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:
14
main.py
14
main.py
@@ -66,6 +66,20 @@ def checkUserPermission(token, permission):
|
||||
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
|
||||
# Arguments: token (required), details (required), model, name
|
||||
|
||||
Reference in New Issue
Block a user