Added function to check permissions on specific chat.

The checkChatPermission function checks if a use is allowed to perform an action in a chat
This commit is contained in:
2025-09-02 17:30:14 +01:00
parent 89f9b6d270
commit ef577c11f7

14
main.py
View File

@@ -65,6 +65,20 @@ def checkUserPermission(token, permission):
return False, "Token is expired" return False, "Token is expired"
else: else:
return False, "Token doesn't exist" 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: # Chat Details Endpoint:
# Get or change details about a chat using the chatId # Get or change details about a chat using the chatId