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