Skip to content

Commit

Permalink
fix: students levels are not shared with anybody when the student is …
Browse files Browse the repository at this point in the history
…dismissed
  • Loading branch information
Seb Palmer committed Oct 31, 2024
1 parent ec52caa commit 9ef702c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions portal/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", "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]
)
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions portal/views/teacher/teach.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 9ef702c

Please sign in to comment.