From 3c1b7d748b1de5ddb52115f92f23ded2698fc1f5 Mon Sep 17 00:00:00 2001 From: Seyed Alireza Hashemi Date: Thu, 21 Nov 2024 12:36:04 +0330 Subject: [PATCH] feat: check the fsm participant limit (on entering fsm) --- apps/fsm/views/fsm_view.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/fsm/views/fsm_view.py b/apps/fsm/views/fsm_view.py index 56cf43cc..619283cf 100644 --- a/apps/fsm/views/fsm_view.py +++ b/apps/fsm/views/fsm_view.py @@ -74,6 +74,18 @@ def get_serializer_context(self): def enter_fsm(self, request, pk=None): fsm = self.get_object() user = request.user + is_mentor = user in fsm.mentors.all() + + # Check if the fsm has a participant limit + if fsm.participant_limit > 0 and not is_mentor: + if user.is_anonymous: + raise PermissionDenied( + "You must be logged in to submit this form.") + else: + count = get_players(user, fsm).count() + if count >= fsm.participant_limit: + raise PermissionDenied( + "You have exceeded the submission limit for this form.") if fsm.is_public: if isinstance(user, AnonymousUser):