diff --git a/backend/api/migrations/0001_initial.py b/backend/api/migrations/0001_initial.py index 6b842090..1254180c 100644 --- a/backend/api/migrations/0001_initial.py +++ b/backend/api/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.0.2 on 2024-02-28 21:55 +# Generated by Django 5.0.2 on 2024-03-05 14:25 import datetime import django.db.models.deletion @@ -7,300 +7,115 @@ class Migration(migrations.Migration): + initial = True dependencies = [ - ("authentication", "0001_initial"), + ('authentication', '0001_initial'), ] operations = [ migrations.CreateModel( - name="Admin", - fields=[ - ( - "user_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to=settings.AUTH_USER_MODEL, - ), - ), - ], - options={ - "abstract": False, - }, - bases=("authentication.user",), - ), - migrations.CreateModel( - name="FileExtension", + name='FileExtension', fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("extension", models.CharField(max_length=10, unique=True)), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('extension', models.CharField(max_length=10, unique=True)), ], ), migrations.CreateModel( - name="Course", + name='Course', fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=100)), - ("academic_startyear", models.IntegerField()), - ("description", models.TextField(blank=True, null=True)), - ( - "parent_course", - models.OneToOneField( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="child_course", - to="api.course", - ), - ), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('academic_startyear', models.IntegerField()), + ('description', models.TextField(blank=True, null=True)), + ('parent_course', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='child_course', to='api.course')), ], ), migrations.CreateModel( - name="Assistant", + name='Assistant', fields=[ - ( - "user_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to=settings.AUTH_USER_MODEL, - ), - ), - ( - "courses", - models.ManyToManyField( - blank=True, related_name="assistants", to="api.course" - ), - ), + ('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), + ('courses', models.ManyToManyField(blank=True, related_name='assistants', to='api.course')), ], options={ - "abstract": False, + 'abstract': False, }, - bases=("authentication.user",), + bases=('authentication.user',), ), migrations.CreateModel( - name="Checks", + name='Checks', fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("dockerfile", models.FileField(blank=True, null=True, upload_to="")), - ( - "allowed_file_extensions", - models.ManyToManyField( - blank=True, - related_name="checks_allowed", - to="api.fileextension", - ), - ), - ( - "forbidden_file_extensions", - models.ManyToManyField( - blank=True, - related_name="checks_forbidden", - to="api.fileextension", - ), - ), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('dockerfile', models.FileField(blank=True, null=True, upload_to='')), + ('allowed_file_extensions', models.ManyToManyField(blank=True, related_name='checks_allowed', to='api.fileextension')), + ('forbidden_file_extensions', models.ManyToManyField(blank=True, related_name='checks_forbidden', to='api.fileextension')), ], ), migrations.CreateModel( - name="Project", + name='Project', fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=100)), - ("description", models.TextField(blank=True, null=True)), - ("visible", models.BooleanField(default=True)), - ("archived", models.BooleanField(default=False)), - ( - "start_date", - models.DateTimeField(blank=True, default=datetime.datetime.now), - ), - ("deadline", models.DateTimeField()), - ( - "checks", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="api.checks", - ), - ), - ( - "course", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="projects", - to="api.course", - ), - ), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('description', models.TextField(blank=True, null=True)), + ('visible', models.BooleanField(default=True)), + ('archived', models.BooleanField(default=False)), + ('start_date', models.DateTimeField(blank=True, default=datetime.datetime.now)), + ('deadline', models.DateTimeField()), + ('checks', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='api.checks')), + ('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='projects', to='api.course')), ], ), migrations.CreateModel( - name="Student", + name='Student', fields=[ - ( - "user_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to=settings.AUTH_USER_MODEL, - ), - ), - ("student_id", models.CharField(max_length=8, null=True, unique=True)), - ( - "courses", - models.ManyToManyField( - blank=True, related_name="students", to="api.course" - ), - ), + ('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), + ('student_id', models.CharField(max_length=8, null=True, unique=True)), + ('courses', models.ManyToManyField(blank=True, related_name='students', to='api.course')), ], options={ - "abstract": False, + 'abstract': False, }, - bases=("authentication.user",), + bases=('authentication.user',), ), migrations.CreateModel( - name="Group", + name='Group', fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("score", models.FloatField(blank=True, null=True)), - ( - "project", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="groups", - to="api.project", - ), - ), - ( - "students", - models.ManyToManyField(related_name="groups", to="api.student"), - ), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('score', models.FloatField(blank=True, null=True)), + ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='groups', to='api.project')), + ('students', models.ManyToManyField(related_name='groups', to='api.student')), ], ), migrations.CreateModel( - name="Submission", + name='Submission', fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("submission_number", models.PositiveIntegerField()), - ("submission_time", models.DateTimeField(auto_now_add=True)), - ( - "group", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="submissions", - to="api.group", - ), - ), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('submission_number', models.PositiveIntegerField()), + ('submission_time', models.DateTimeField(auto_now_add=True)), + ('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='submissions', to='api.group')), ], options={ - "unique_together": {("group", "submission_number")}, + 'unique_together': {('group', 'submission_number')}, }, ), migrations.CreateModel( - name="SubmissionFile", + name='SubmissionFile', fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("file", models.FileField(upload_to="")), - ( - "submission", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - related_name="files", - to="api.submission", - ), - ), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('file', models.FileField(upload_to='')), + ('submission', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='files', to='api.submission')), ], ), migrations.CreateModel( - name="Teacher", + name='Teacher', fields=[ - ( - "user_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to=settings.AUTH_USER_MODEL, - ), - ), - ( - "courses", - models.ManyToManyField( - blank=True, related_name="teachers", to="api.course" - ), - ), + ('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), + ('courses', models.ManyToManyField(blank=True, related_name='teachers', to='api.course')), ], options={ - "abstract": False, + 'abstract': False, }, - bases=("authentication.user",), + bases=('authentication.user',), ), ] diff --git a/backend/api/migrations/0002_delete_admin.py b/backend/api/migrations/0002_delete_admin.py deleted file mode 100644 index 036781ac..00000000 --- a/backend/api/migrations/0002_delete_admin.py +++ /dev/null @@ -1,16 +0,0 @@ -# Generated by Django 5.0.2 on 2024-03-04 18:06 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0001_initial'), - ] - - operations = [ - migrations.DeleteModel( - name='Admin', - ), - ] diff --git a/backend/authentication/migrations/0001_initial.py b/backend/authentication/migrations/0001_initial.py index 8895c9c4..3265f487 100644 --- a/backend/authentication/migrations/0001_initial.py +++ b/backend/authentication/migrations/0001_initial.py @@ -1,59 +1,38 @@ -# Generated by Django 5.0.2 on 2024-02-28 21:55 +# Generated by Django 5.0.2 on 2024-03-05 14:25 -from django.conf import settings from django.db import migrations, models class Migration(migrations.Migration): + initial = True - dependencies = [] + dependencies = [ + ] operations = [ migrations.CreateModel( - name="User", + name='Faculty', fields=[ - ( - "last_login", - models.DateTimeField( - blank=True, null=True, verbose_name="last login" - ), - ), - ( - "id", - models.CharField(max_length=12, primary_key=True, serialize=False), - ), - ("username", models.CharField(max_length=12, unique=True)), - ("email", models.EmailField(max_length=254, unique=True)), - ("first_name", models.CharField(max_length=50)), - ("last_name", models.CharField(max_length=50)), - ("last_enrolled", models.IntegerField(default=1, null=True)), - ("create_time", models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=50, primary_key=True, serialize=False)), ], - options={ - "abstract": False, - }, ), migrations.CreateModel( - name="Faculty", + name='User', fields=[ - ( - "name", - models.CharField(max_length=50, primary_key=True, serialize=False), - ), - ( - "user", - models.ManyToManyField( - blank=True, related_name="users", to=settings.AUTH_USER_MODEL - ), - ), + ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), + ('id', models.CharField(max_length=12, primary_key=True, serialize=False)), + ('username', models.CharField(max_length=12, unique=True)), + ('is_staff', models.BooleanField(default=False)), + ('email', models.EmailField(max_length=254, unique=True)), + ('first_name', models.CharField(max_length=50)), + ('last_name', models.CharField(max_length=50)), + ('last_enrolled', models.IntegerField(default=1, null=True)), + ('create_time', models.DateTimeField(auto_now_add=True)), + ('faculties', models.ManyToManyField(blank=True, related_name='users', to='authentication.faculty')), ], - ), - migrations.AddField( - model_name="user", - name="faculty", - field=models.ManyToManyField( - blank=True, related_name="faculties", to="authentication.faculty" - ), + options={ + 'abstract': False, + }, ), ] diff --git a/backend/authentication/migrations/0002_remove_faculty_user_remove_user_faculty_and_more.py b/backend/authentication/migrations/0002_remove_faculty_user_remove_user_faculty_and_more.py deleted file mode 100644 index 6323b90c..00000000 --- a/backend/authentication/migrations/0002_remove_faculty_user_remove_user_faculty_and_more.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 5.0.2 on 2024-02-29 13:20 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("authentication", "0001_initial"), - ] - - operations = [ - migrations.RemoveField( - model_name="faculty", - name="user", - ), - migrations.RemoveField( - model_name="user", - name="faculty", - ), - migrations.AddField( - model_name="user", - name="faculties", - field=models.ManyToManyField( - blank=True, related_name="users", to="authentication.faculty" - ), - ), - ] diff --git a/backend/authentication/migrations/0003_alter_user_create_time.py b/backend/authentication/migrations/0003_alter_user_create_time.py deleted file mode 100644 index f65d50cf..00000000 --- a/backend/authentication/migrations/0003_alter_user_create_time.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 5.0.2 on 2024-03-04 15:13 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("authentication", "0002_remove_faculty_user_remove_user_faculty_and_more"), - ] - - operations = [ - migrations.AlterField( - model_name="user", - name="create_time", - field=models.DateTimeField(auto_now_add=True), - ), - ] diff --git a/backend/authentication/migrations/0003_user_is_staff_alter_user_create_time.py b/backend/authentication/migrations/0003_user_is_staff_alter_user_create_time.py deleted file mode 100644 index 6e1a9080..00000000 --- a/backend/authentication/migrations/0003_user_is_staff_alter_user_create_time.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 5.0.2 on 2024-03-04 18:06 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('authentication', '0002_remove_faculty_user_remove_user_faculty_and_more'), - ] - - operations = [ - migrations.AddField( - model_name='user', - name='is_staff', - field=models.BooleanField(default=False), - ), - migrations.AlterField( - model_name='user', - name='create_time', - field=models.DateTimeField(auto_now_add=True), - ), - ] diff --git a/backend/authentication/models.py b/backend/authentication/models.py index a2dea074..8a8787f4 100644 --- a/backend/authentication/models.py +++ b/backend/authentication/models.py @@ -27,7 +27,7 @@ class User(AbstractBaseUser): faculties = models.ManyToManyField("Faculty", related_name="users", blank=True) - last_enrolled = IntegerField(default=datetime.MINYEAR, null=True) + last_enrolled = IntegerField(default=MINYEAR, null=True) create_time = DateTimeField(auto_now_add=True) diff --git a/backend/authentication/tests/test_authentication_views.py b/backend/authentication/tests/test_authentication_views.py index 068e1d93..960e689d 100644 --- a/backend/authentication/tests/test_authentication_views.py +++ b/backend/authentication/tests/test_authentication_views.py @@ -9,7 +9,7 @@ class TestWhomAmIView(APITestCase): def setUp(self): """Create a user and generate a token for that user""" - user_data = User.objects.create(**{ + self.user = User.objects.create(**{ "id": "1234", "username": "ddickwd", "email": "dummy@dummy.com", @@ -66,7 +66,7 @@ def test_logout_view_authenticated_logout_url(self): access_token = AccessToken().for_user(self.user) self.token = f"Bearer {access_token}" self.client.credentials(HTTP_AUTHORIZATION=self.token) - response = self.client.post(reverse("cas-logout")) + response = self.client.get(reverse("cas-logout")) self.assertEqual(response.status_code, 302) url = "{server_url}/logout?service={service_url}".format( server_url=settings.CAS_ENDPOINT, service_url=settings.API_ENDPOINT @@ -75,7 +75,7 @@ def test_logout_view_authenticated_logout_url(self): def test_logout_view_not_authenticated_logout_url(self): """LogoutView should return a 401 error when trying to access it while not authenticated.""" - response = self.client.post(reverse("cas-logout")) + response = self.client.get(reverse("cas-logout")) self.assertEqual(response.status_code, 401)