diff --git a/anatomy/migrations/0023_exam_exam_open_access.py b/anatomy/migrations/0023_exam_exam_open_access.py new file mode 100644 index 00000000..5f11a177 --- /dev/null +++ b/anatomy/migrations/0023_exam_exam_open_access.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-10-14 11:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('anatomy', '0022_alter_exam_markers'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='exam_open_access', + field=models.BooleanField(default=False, help_text='Set to true if you want any registered user to be able to take the exam.'), + ), + ] diff --git a/generic/forms.py b/generic/forms.py index 9722af40..a280c8ea 100755 --- a/generic/forms.py +++ b/generic/forms.py @@ -128,6 +128,7 @@ class ExamFormMixin: "open_access", "authors_only", "exam_mode", + "exam_open_access", "include_history", "active", "publish_results", @@ -192,6 +193,7 @@ class ExamFormMixin: "open_access", "authors_only", "exam_mode", + "exam_open_access", "include_history", "restrict_to_dates", "start_date", diff --git a/generic/models.py b/generic/models.py index edbbb17e..91b12377 100644 --- a/generic/models.py +++ b/generic/models.py @@ -696,6 +696,7 @@ class ExamOrCollectionGenericBase(models.Model, AuthorMixin): user_id: int | None = None, allow_authors: bool = True, ): + """Checks if a user (cid or otherwise) is allowed to access (and take) the exam""" print(f"Check cid user: {cid=}, {passcode=}, exam_id={self.pk}") if user is not None and user.is_superuser: return True @@ -705,15 +706,19 @@ class ExamOrCollectionGenericBase(models.Model, AuthorMixin): if self.author.filter(pk=user_id).exists(): return True - if not self.valid_cid_users.exists() and not self.valid_user_users.exists(): - return False - if cid is None and user_id is None: if user is not None: user_id = user.id else: return False + if self.exam_open_access and user_id is not None: + return True + + if not self.valid_cid_users.exists() and not self.valid_user_users.exists(): + return False + + # Start by checking if the logged in user can access if user_id is not None: if self.valid_user_users.filter(pk=user_id).exists(): @@ -852,6 +857,8 @@ class ExamBase(ExamOrCollectionGenericBase): default=False, ) + exam_open_access = models.BooleanField(default=False, help_text="Set to true if you want any registered user to be able to take the exam.") + # randomise_question_order = models.BooleanField( # help_text="If an exam should randomise the order of questions in RTS.", # ) diff --git a/longs/migrations/0030_exam_exam_open_access.py b/longs/migrations/0030_exam_exam_open_access.py new file mode 100644 index 00000000..0711f301 --- /dev/null +++ b/longs/migrations/0030_exam_exam_open_access.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-10-14 11:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('longs', '0029_alter_exam_markers'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='exam_open_access', + field=models.BooleanField(default=False, help_text='Set to true if you want any registered user to be able to take the exam.'), + ), + ] diff --git a/physics/migrations/0016_exam_exam_open_access.py b/physics/migrations/0016_exam_exam_open_access.py new file mode 100644 index 00000000..c4535d4c --- /dev/null +++ b/physics/migrations/0016_exam_exam_open_access.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-10-14 11:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('physics', '0015_alter_exam_markers'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='exam_open_access', + field=models.BooleanField(default=False, help_text='Set to true if you want any registered user to be able to take the exam.'), + ), + ] diff --git a/rapids/migrations/0014_exam_exam_open_access.py b/rapids/migrations/0014_exam_exam_open_access.py new file mode 100644 index 00000000..14cd3555 --- /dev/null +++ b/rapids/migrations/0014_exam_exam_open_access.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-10-14 11:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('rapids', '0013_alter_exam_markers'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='exam_open_access', + field=models.BooleanField(default=False, help_text='Set to true if you want any registered user to be able to take the exam.'), + ), + ] diff --git a/sbas/migrations/0016_exam_exam_open_access.py b/sbas/migrations/0016_exam_exam_open_access.py new file mode 100644 index 00000000..a8c87353 --- /dev/null +++ b/sbas/migrations/0016_exam_exam_open_access.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-10-14 11:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sbas', '0015_alter_exam_markers'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='exam_open_access', + field=models.BooleanField(default=False, help_text='Set to true if you want any registered user to be able to take the exam.'), + ), + ]