Update permissions system for chats
This commit is contained in:
18
main.py
18
main.py
@@ -45,7 +45,7 @@ except Exception as e:
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# Chat Details Endpoint:
|
# Chat Details Endpoint:
|
||||||
# Gets details about a chat using the chatId
|
# Get or change details about a chat using the chatId
|
||||||
# Arguments: token (required), details (required), model, name
|
# Arguments: token (required), details (required), model, name
|
||||||
@app.route('/api/chat/<_id>/details', methods = ['GET', 'POST'])
|
@app.route('/api/chat/<_id>/details', methods = ['GET', 'POST'])
|
||||||
def getChatHistory(_id):
|
def getChatHistory(_id):
|
||||||
@@ -70,6 +70,8 @@ def getChatHistory(_id):
|
|||||||
returnedChat = chatCollection.find_one({'_id': ObjectId(_id)})
|
returnedChat = chatCollection.find_one({'_id': ObjectId(_id)})
|
||||||
# Convert chatId into string
|
# Convert chatId into string
|
||||||
returnedChat['_id'] = str(returnedChat['_id'])
|
returnedChat['_id'] = str(returnedChat['_id'])
|
||||||
|
try:
|
||||||
|
returnedChat["permissions"][userId].index("view")
|
||||||
print("Chat " + _id + " has been found with token " + token)
|
print("Chat " + _id + " has been found with token " + token)
|
||||||
# Check for detail type and return correct value from db
|
# Check for detail type and return correct value from db
|
||||||
if (details == "history"):
|
if (details == "history"):
|
||||||
@@ -80,7 +82,11 @@ def getChatHistory(_id):
|
|||||||
return jsonify(returnedChat["model"])
|
return jsonify(returnedChat["model"])
|
||||||
elif (details == "name"):
|
elif (details == "name"):
|
||||||
return jsonify(returnedChat["name"])
|
return jsonify(returnedChat["name"])
|
||||||
|
except:
|
||||||
|
return jsonify("Invalid Permissions")
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
|
returnedChat["permissions"][userId].index("edit")
|
||||||
# Check for the detail type and add data to db
|
# Check for the detail type and add data to db
|
||||||
if (details == "model"):
|
if (details == "model"):
|
||||||
model = request.json['model']
|
model = request.json['model']
|
||||||
@@ -89,6 +95,8 @@ def getChatHistory(_id):
|
|||||||
name = request.json['name']
|
name = request.json['name']
|
||||||
chatCollection.update_one({'_id': ObjectId(_id)}, { "$set": { "name": name } })
|
chatCollection.update_one({'_id': ObjectId(_id)}, { "$set": { "name": name } })
|
||||||
return jsonify("Success")
|
return jsonify("Success")
|
||||||
|
except:
|
||||||
|
return jsonify("Invalid Permissions")
|
||||||
else:
|
else:
|
||||||
return jsonify("User token is invalid")
|
return jsonify("User token is invalid")
|
||||||
else:
|
else:
|
||||||
@@ -99,8 +107,11 @@ def getChatHistory(_id):
|
|||||||
# Arguments: token (required), name (required), model (required)
|
# Arguments: token (required), name (required), model (required)
|
||||||
@app.route('/api/chat/create', methods = ['POST'])
|
@app.route('/api/chat/create', methods = ['POST'])
|
||||||
def createChat():
|
def createChat():
|
||||||
|
# Get user auth token
|
||||||
token = request.json['token']
|
token = request.json['token']
|
||||||
user = usersCollection.find_one({'tokens.token': token}, {"_id":1,"tokens":{"$elemMatch": {"token":token}}, "permissions":1})
|
# Find the correct user token in user db
|
||||||
|
user = usersCollection.find_one({'tokens.token': token}, {"_id":1,"tokens":{"$elemMatch": {"token":token}}})
|
||||||
|
# If the user exists, continue, otherwise return fail
|
||||||
if (user):
|
if (user):
|
||||||
user['_id'] = str(user['_id'])
|
user['_id'] = str(user['_id'])
|
||||||
if (user['tokens'][0]['expiry'] > int(datetime.now().timestamp())):
|
if (user['tokens'][0]['expiry'] > int(datetime.now().timestamp())):
|
||||||
@@ -119,7 +130,8 @@ def createChat():
|
|||||||
userId:[
|
userId:[
|
||||||
"owner",
|
"owner",
|
||||||
"view",
|
"view",
|
||||||
"message"
|
"message",
|
||||||
|
"edit"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"messages": [
|
"messages": [
|
||||||
|
|||||||
Reference in New Issue
Block a user