From 4051d98f8fc2461131786054114efc32620c071e Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Mon, 4 Sep 2023 20:28:55 -0400 Subject: [PATCH] Appease the linter --- app/classes/web/routes/api/users/user/api.py | 76 +++++++++++--------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/app/classes/web/routes/api/users/user/api.py b/app/classes/web/routes/api/users/user/api.py index 814ce296..1c7635f2 100644 --- a/app/classes/web/routes/api/users/user/api.py +++ b/app/classes/web/routes/api/users/user/api.py @@ -17,8 +17,14 @@ class ApiUsersUserKeyHandler(BaseApiHandler): key = self.controller.users.get_user_api_key(key_id) # does this user id exist? if key is None: - self.redirect("/panel/error?error=Invalid Key ID") - return + return self.finish_json( + 400, + { + "status": "error", + "error": "INVALID DATA", + "error_data": "INVALID KEY", + }, + ) if ( str(key.user_id) != str(auth_data[4]["user_id"]) @@ -48,37 +54,37 @@ class ApiUsersUserKeyHandler(BaseApiHandler): 200, {"status": "ok", "data": data_key}, ) - else: - if ( - str(user_id) != str(auth_data[4]["user_id"]) - and not auth_data[4]["superuser"] - ): - return self.finish_json( - 400, - { - "status": "error", - "error": "NOT AUTHORIZED", - "error_data": "TRIED TO EDIT KEY WIHTOUT AUTH", - }, - ) - keys = [] - for key in self.controller.users.get_user_api_keys(str(user_id)): - keys.append( - { - "id": key.token_id, - "name": key.name, - "server_permissions": key.server_permissions, - "crafty_permissions": key.crafty_permissions, - "superuser": key.superuser, - } - ) - self.finish_json( - 200, + + if ( + str(user_id) != str(auth_data[4]["user_id"]) + and not auth_data[4]["superuser"] + ): + return self.finish_json( + 400, { - "status": "ok", - "data": keys, + "status": "error", + "error": "NOT AUTHORIZED", + "error_data": "TRIED TO EDIT KEY WIHTOUT AUTH", }, ) + keys = [] + for key in self.controller.users.get_user_api_keys(str(user_id)): + keys.append( + { + "id": key.token_id, + "name": key.name, + "server_permissions": key.server_permissions, + "crafty_permissions": key.crafty_permissions, + "superuser": key.superuser, + } + ) + self.finish_json( + 200, + { + "status": "ok", + "data": keys, + }, + ) def patch(self, user_id: str): user_key_schema = { @@ -187,8 +193,14 @@ class ApiUsersUserKeyHandler(BaseApiHandler): key = self.controller.users.get_user_api_key(key_id) # does this user id exist? if key is None: - self.redirect("/panel/error?error=Invalid Key ID") - return + return self.finish_json( + 400, + { + "status": "error", + "error": "INVALID DATA", + "error_data": "INVALID KEY", + }, + ) # does this user id exist? target_key = self.controller.users.get_user_api_key(key_id)