From ef577c11f73b5c23fcebdff565714f78a9c16210 Mon Sep 17 00:00:00 2001 From: Hugo H Date: Tue, 2 Sep 2025 17:30:14 +0100 Subject: [PATCH] Added function to check permissions on specific chat. The checkChatPermission function checks if a use is allowed to perform an action in a chat --- main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.py b/main.py index c516086..43c64a5 100644 --- a/main.py +++ b/main.py @@ -65,6 +65,20 @@ def checkUserPermission(token, permission): return False, "Token is expired" else: return False, "Token doesn't exist" + +def checkChatPermission(token, chatId, permission): + a, userId = checkUserPermission(token, True) + if (a == True): + # Get the chat from the chatId + returnedChat = chatCollection.find_one({'_id': ObjectId(chatId)}) + # Convert chatId into string + returnedChat['_id'] = str(returnedChat['_id']) + if permission in returnedChat['permissions']: + return True, userId + else: + return False, "Incorrect permissions" + else: + return False, "Invalid Token" # Chat Details Endpoint: # Get or change details about a chat using the chatId