From 4b1da0fd926aaa033b4ba726801ec73f48c6f147 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 27 Nov 2022 22:37:56 +0000 Subject: [PATCH] Prevent registering the instructor for classes --- apiserver/apiserver/api/views.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index df2e108..8ed8b4b 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -430,6 +430,11 @@ class TrainingViewSet(Base, Retrieve, Create, Update): member = get_object_or_404(models.Member, id=data['member_id']) user = member.user + if user == session.instructor: + msg = 'Self-register trickery detected:\n' + str(data.dict()) + utils.alert_tanner(msg) + raise exceptions.ValidationError(dict(non_field_errors='Can\'t register the instructor. Don\'t try to trick the portal.')) + training1 = models.Training.objects.filter(user=user, session=session) if training1.exists(): raise exceptions.ValidationError(dict(non_field_errors='Already registered.'))