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
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user