From d6a57f25016ac4d8170b1d72577e9da911162379 Mon Sep 17 00:00:00 2001 From: test test Date: Wed, 16 Jun 2021 17:06:12 +0200 Subject: [PATCH] Add fields to restrict user to register to webclass depending of if they are platform_only or not --- teleforma/views/core.py | 8 +++++-- .../migrations/0002_webclass_platform_only.py | 2 +- .../migrations/0003_auto_20210616_1650.py | 23 +++++++++++++++++++ .../migrations/0004_auto_20210616_1654.py | 23 +++++++++++++++++++ teleforma/webclass/models.py | 3 ++- teleforma/webclass/views.py | 4 +++- 6 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 teleforma/webclass/migrations/0003_auto_20210616_1650.py create mode 100644 teleforma/webclass/migrations/0004_auto_20210616_1654.py diff --git a/teleforma/views/core.py b/teleforma/views/core.py index 66309f1f..b2879397 100644 --- a/teleforma/views/core.py +++ b/teleforma/views/core.py @@ -359,7 +359,9 @@ class CourseListView(CourseAccessMixin, ListView): for webclass in Webclass.published.filter(period=self.period, iej=student.iej, course__in=student_courses): # if webclass.course not in student_courses: # continue - if webclass.platform_only and not student.platform_only: + if student.platform_only and not webclass.allow_elearning: + continue + if not student.platform_only and not webclass.allow_presentiel: continue slot = webclass.get_slot(user) if slot and slot.status in ('almost', 'ingoing'): @@ -458,7 +460,9 @@ class CourseView(CourseAccessMixin, DetailView): except IndexError: pass if webclass: - if webclass.platform_only and not student.platform_only: + if student.platform_only and not webclass.allow_elearning: + webclass = None + elif not student.platform_only and not webclass.allow_presentiel: webclass = None else: webclass_slot = webclass.get_slot(self.request.user) diff --git a/teleforma/webclass/migrations/0002_webclass_platform_only.py b/teleforma/webclass/migrations/0002_webclass_platform_only.py index 407be8da..0d4aaaeb 100644 --- a/teleforma/webclass/migrations/0002_webclass_platform_only.py +++ b/teleforma/webclass/migrations/0002_webclass_platform_only.py @@ -13,6 +13,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='webclass', name='platform_only', - field=models.BooleanField(default=False, verbose_name='platform only'), + field=models.BooleanField(default=True, verbose_name='platform only'), ), ] diff --git a/teleforma/webclass/migrations/0003_auto_20210616_1650.py b/teleforma/webclass/migrations/0003_auto_20210616_1650.py new file mode 100644 index 00000000..f261bc6f --- /dev/null +++ b/teleforma/webclass/migrations/0003_auto_20210616_1650.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.3 on 2021-06-16 16:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webclass', '0002_webclass_platform_only'), + ] + + operations = [ + migrations.AddField( + model_name='webclass', + name='presentiel', + field=models.BooleanField(default=True, verbose_name='Autoriser présentiel'), + ), + migrations.AlterField( + model_name='webclass', + name='platform_only', + field=models.BooleanField(default=True, verbose_name='Autoriser e-learning'), + ), + ] diff --git a/teleforma/webclass/migrations/0004_auto_20210616_1654.py b/teleforma/webclass/migrations/0004_auto_20210616_1654.py new file mode 100644 index 00000000..74978d77 --- /dev/null +++ b/teleforma/webclass/migrations/0004_auto_20210616_1654.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.3 on 2021-06-16 16:54 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('webclass', '0003_auto_20210616_1650'), + ] + + operations = [ + migrations.RenameField( + model_name='webclass', + old_name='platform_only', + new_name='allow_elearning', + ), + migrations.RenameField( + model_name='webclass', + old_name='presentiel', + new_name='allow_presentiel', + ), + ] diff --git a/teleforma/webclass/models.py b/teleforma/webclass/models.py index f3b92709..a4f3ba40 100644 --- a/teleforma/webclass/models.py +++ b/teleforma/webclass/models.py @@ -139,7 +139,8 @@ class Webclass(models.Model): 'teleforma.Course', related_name='webclass', verbose_name=_('course'), on_delete=models.CASCADE) iej = models.ManyToManyField( 'teleforma.IEJ', related_name='webclass', verbose_name=_('iej'), blank=True) - platform_only = models.BooleanField(_('platform only'), default=False) + allow_elearning = models.BooleanField('Autoriser e-learning', default=True) + allow_presentiel = models.BooleanField('Autoriser présentiel', default=True) bbb_server = models.ForeignKey( 'BBBServer', related_name='webclass', verbose_name='Serveur BBB', on_delete=models.CASCADE) duration = DurationField('Durée de la conférence', default="00:30:00") diff --git a/teleforma/webclass/views.py b/teleforma/webclass/views.py index 8e008652..5d39a926 100644 --- a/teleforma/webclass/views.py +++ b/teleforma/webclass/views.py @@ -55,7 +55,9 @@ class WebclassAppointment(View): # Student is in the right IEJ ? if not student.iej in webclass.iej.all(): return HttpResponse('Unauthorized', status=401) - if webclass.platform_only and not student.platform_only: + if student.platform_only and not webclass.allow_elearning: + return HttpResponse('Unauthorized', status=401) + if not student.platform_only and not webclass.allow_presentiel: return HttpResponse('Unauthorized', status=401) return -- 2.39.5