From 933d9f98ec8d350ee9471118da6667acb1b77266 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Sat, 5 Aug 2023 22:18:14 +0500 Subject: [PATCH 1/2] when queue is updated to private, make it null in all competitions belonging to other users --- src/apps/api/views/queues.py | 22 +++++++++++++++++++++- src/static/riot/queues/management.tag | 5 ++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/apps/api/views/queues.py b/src/apps/api/views/queues.py index 4a5870c64..db96188c6 100644 --- a/src/apps/api/views/queues.py +++ b/src/apps/api/views/queues.py @@ -46,7 +46,27 @@ def update(self, request, *args, **kwargs): queue = self.get_object() if request.user != queue.owner and not request.user.is_superuser: raise PermissionDenied("Cannot update a queue that is not yours") - return super().update(request, *args, **kwargs) + + # Get the original value of is_public before updating + before_update_queue_is_public = queue.is_public + + # Get the competitions that are using this queue + competitions = queue.competitions.all() + + # Update the queue + updated_queue_response = super().update(request, *args, **kwargs) + + # If the queue `is_public`` field is updated to False, then update competitions + if 'is_public' in request.data and not request.data['is_public'] and before_update_queue_is_public: + + # Set the queue field in all competitions to NULL + # which do not belong to the user + for competition in competitions: + if competition.created_by != request.user: + competition.queue = None + competition.save() + + return updated_queue_response def destroy(self, request, *args, **kwargs): instance = self.get_object() diff --git a/src/static/riot/queues/management.tag b/src/static/riot/queues/management.tag index 062693bc2..fafb43ede 100644 --- a/src/static/riot/queues/management.tag +++ b/src/static/riot/queues/management.tag @@ -69,9 +69,8 @@ - + +