From 9ef702c8e322195e0ae819c196ccf59f93d099cc Mon Sep 17 00:00:00 2001 From: Seb Palmer Date: Thu, 31 Oct 2024 20:35:27 +0000 Subject: [PATCH 1/2] fix: students levels are not shared with anybody when the student is dismissed --- portal/tests/test_views.py | 18 ++++++++++++++++++ portal/views/teacher/teach.py | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/portal/tests/test_views.py b/portal/tests/test_views.py index 9455121ac..172924f19 100644 --- a/portal/tests/test_views.py +++ b/portal/tests/test_views.py @@ -252,11 +252,24 @@ def test_release_verified_student(self): assert response.status_code == 302 student = Student.objects.get(pk=self.student.pk) + assert student.user.is_verified c.logout() c.login(username=self.email, password=self.password) + teacher = Teacher.objects.factory("the", "teacher", "theteacher@foo.com", "password") + level = Level.objects.create() + + level.owner = student.new_user.userprofile + level.shared_with.add(teacher.new_user) + level.save() + + students_levels = Level.objects.filter(owner=student.new_user.userprofile).all() + + for level in students_levels.all(): + assert level.shared_with.exists() + release_url = reverse( "teacher_dismiss_students", args=[self.class_access_code] ) @@ -279,6 +292,11 @@ def test_release_verified_student(self): student = Student.objects.get(pk=self.student.pk) assert not student.user.is_verified + students_levels = Level.objects.filter(owner=student.new_user.userprofile).all() + + for level in students_levels.all(): + assert not level.shared_with.exists() + class TestLoginViews(TestCase): @classmethod diff --git a/portal/views/teacher/teach.py b/portal/views/teacher/teach.py index 9edd9971e..c34d034b1 100644 --- a/portal/views/teacher/teach.py +++ b/portal/views/teacher/teach.py @@ -39,6 +39,8 @@ from reportlab.lib.utils import ImageReader from reportlab.pdfgen import canvas +from game.models import Level + from portal.forms.teach import ( BaseTeacherDismissStudentsFormSet, BaseTeacherMoveStudentsDisambiguationFormSet, @@ -56,6 +58,7 @@ from portal.helpers.ratelimit import clear_ratelimit_cache_for_user from portal.views.registration import handle_reset_password_tracking + STUDENT_PASSWORD_LENGTH = 6 REMINDER_CARDS_PDF_ROWS = 8 REMINDER_CARDS_PDF_COLUMNS = 1 @@ -616,6 +619,11 @@ def process_dismiss_student_form(request, formset, klass, access_code): new_user__first_name__iexact=data["orig_name"], ) + students_levels = Level.objects.filter(owner=student.new_user.userprofile).all() + for level in students_levels.all(): + for other in level.shared_with.all(): + level.shared_with.remove(other) + student.class_field = None student.new_user.first_name = data["name"] student.new_user.username = data["email"] From ab21f335104ccfe5feebbb774404021588015cd4 Mon Sep 17 00:00:00 2001 From: Seb Palmer Date: Fri, 1 Nov 2024 08:10:34 +0000 Subject: [PATCH 2/2] fix: set shared_with to nobody --- portal/views/teacher/teach.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/portal/views/teacher/teach.py b/portal/views/teacher/teach.py index c34d034b1..a62835ecc 100644 --- a/portal/views/teacher/teach.py +++ b/portal/views/teacher/teach.py @@ -620,9 +620,9 @@ def process_dismiss_student_form(request, formset, klass, access_code): ) students_levels = Level.objects.filter(owner=student.new_user.userprofile).all() - for level in students_levels.all(): - for other in level.shared_with.all(): - level.shared_with.remove(other) + for level in students_levels: + level.shared_with.set([]) + level.save() student.class_field = None student.new_user.first_name = data["name"]