From 429fd4f155b8d9ac596e6ef41123b4cfcdfef1ea Mon Sep 17 00:00:00 2001 From: epicadk Date: Wed, 17 Feb 2021 23:46:44 +0530 Subject: [PATCH 1/2] Bump flask jwt extended version to 4.0.2 #1002 Signed-off-by: epicadk --- app/api/jwt_extension.py | 2 +- app/api/resources/admin.py | 6 +++--- app/api/resources/mentorship_relation.py | 18 +++++++++--------- app/api/resources/task.py | 8 ++++---- app/api/resources/task_comment.py | 8 ++++---- app/api/resources/user.py | 21 ++++++++++----------- requirements.txt | 2 +- 7 files changed, 32 insertions(+), 33 deletions(-) diff --git a/app/api/jwt_extension.py b/app/api/jwt_extension.py index a76d76233..a2dd9beff 100644 --- a/app/api/jwt_extension.py +++ b/app/api/jwt_extension.py @@ -10,7 +10,7 @@ @jwt.expired_token_loader -def my_expired_token_callback(): +def my_expired_token_callback(jwt_header, jwt_payload): return messages.TOKEN_HAS_EXPIRED, HTTPStatus.UNAUTHORIZED diff --git a/app/api/resources/admin.py b/app/api/resources/admin.py index b406d1d5d..ff8aa8726 100644 --- a/app/api/resources/admin.py +++ b/app/api/resources/admin.py @@ -23,7 +23,7 @@ @admin_ns.response(HTTPStatus.NOT_FOUND.value, f"{messages.USER_DOES_NOT_EXIST}") class AssignNewUserAdmin(Resource): @classmethod - @jwt_required + @jwt_required() @admin_ns.expect( auth_header_parser, assign_and_revoke_user_admin_request_body, validate=True ) @@ -55,7 +55,7 @@ def post(cls): @admin_ns.response(HTTPStatus.NOT_FOUND.value, f"{messages.USER_DOES_NOT_EXIST}") class RevokeUserAdmin(Resource): @classmethod - @jwt_required + @jwt_required() @admin_ns.expect( auth_header_parser, assign_and_revoke_user_admin_request_body, validate=True ) @@ -79,7 +79,7 @@ def post(cls): @admin_ns.route("admins") class ListAdmins(Resource): @classmethod - @jwt_required + @jwt_required() @admin_ns.doc("get_list_of_admins") @admin_ns.response(HTTPStatus.OK.value, "Success.", public_admin_user_api_model) @admin_ns.doc( diff --git a/app/api/resources/mentorship_relation.py b/app/api/resources/mentorship_relation.py index 3b9a84267..4118f6c09 100644 --- a/app/api/resources/mentorship_relation.py +++ b/app/api/resources/mentorship_relation.py @@ -25,7 +25,7 @@ @mentorship_relation_ns.route("mentorship_relation/send_request") class SendRequest(Resource): @classmethod - @jwt_required + @jwt_required() @mentorship_relation_ns.doc("send_request") @mentorship_relation_ns.expect(auth_header_parser, send_mentorship_request_body) @mentorship_relation_ns.response( @@ -122,7 +122,7 @@ def is_valid_data(data): @mentorship_relation_ns.route("mentorship_relations") class GetAllMyMentorshipRelation(Resource): @classmethod - @jwt_required + @jwt_required() @mentorship_relation_ns.doc("get_all_user_mentorship_relations") @mentorship_relation_ns.expect(auth_header_parser) @mentorship_relation_ns.param( @@ -174,7 +174,7 @@ def get(cls): @mentorship_relation_ns.route("mentorship_relation//accept") class AcceptMentorshipRelation(Resource): @classmethod - @jwt_required + @jwt_required() @mentorship_relation_ns.doc("accept_mentorship_relation") @mentorship_relation_ns.expect(auth_header_parser) @mentorship_relation_ns.response( @@ -223,7 +223,7 @@ def put(cls, request_id): @mentorship_relation_ns.route("mentorship_relation//reject") class RejectMentorshipRelation(Resource): @classmethod - @jwt_required + @jwt_required() @mentorship_relation_ns.doc("reject_mentorship_relation") @mentorship_relation_ns.expect(auth_header_parser) @mentorship_relation_ns.response( @@ -267,7 +267,7 @@ def put(cls, request_id): @mentorship_relation_ns.route("mentorship_relation//cancel") class CancelMentorshipRelation(Resource): @classmethod - @jwt_required + @jwt_required() @mentorship_relation_ns.doc("cancel_mentorship_relation") @mentorship_relation_ns.expect(auth_header_parser) @mentorship_relation_ns.response( @@ -310,7 +310,7 @@ def put(cls, request_id): @mentorship_relation_ns.route("mentorship_relation/") class DeleteMentorshipRelation(Resource): @classmethod - @jwt_required + @jwt_required() @mentorship_relation_ns.doc("delete_mentorship_relation") @mentorship_relation_ns.expect(auth_header_parser) @mentorship_relation_ns.response( @@ -353,7 +353,7 @@ def delete(cls, request_id): @mentorship_relation_ns.route("mentorship_relations/past") class ListPastMentorshipRelations(Resource): @classmethod - @jwt_required + @jwt_required() @mentorship_relation_ns.doc("get_past_mentorship_relations") @mentorship_relation_ns.expect(auth_header_parser) @mentorship_relation_ns.response( @@ -392,7 +392,7 @@ def get(cls): @mentorship_relation_ns.route("mentorship_relations/current") class ListCurrentMentorshipRelation(Resource): @classmethod - @jwt_required + @jwt_required() @mentorship_relation_ns.doc("get_current_mentorship_relation") @mentorship_relation_ns.expect(auth_header_parser) @mentorship_relation_ns.response( @@ -432,7 +432,7 @@ def get(cls): @mentorship_relation_ns.route("mentorship_relations/pending") class ListPendingMentorshipRequests(Resource): @classmethod - @jwt_required + @jwt_required() @mentorship_relation_ns.doc("get_pending_mentorship_relations") @mentorship_relation_ns.expect(auth_header_parser) @mentorship_relation_ns.response( diff --git a/app/api/resources/task.py b/app/api/resources/task.py index cc4e7e189..b38f42267 100644 --- a/app/api/resources/task.py +++ b/app/api/resources/task.py @@ -19,7 +19,7 @@ @task_ns.route("mentorship_relation//task") class CreateTask(Resource): @classmethod - @jwt_required + @jwt_required() @task_ns.doc("create_task_in_mentorship_relation") @task_ns.expect(auth_header_parser, create_task_request_body) @task_ns.response(HTTPStatus.CREATED, f"{messages.TASK_WAS_CREATED_SUCCESSFULLY}") @@ -75,7 +75,7 @@ def is_valid_data(data): @task_ns.route("mentorship_relation//task/") class DeleteTask(Resource): @classmethod - @jwt_required + @jwt_required() @task_ns.doc("delete_task_in_mentorship_relation") @task_ns.expect(auth_header_parser) @task_ns.response(HTTPStatus.OK, f"{messages.TASK_WAS_DELETED_SUCCESSFULLY}") @@ -119,7 +119,7 @@ def delete(cls, request_id, task_id): @task_ns.route("mentorship_relation//tasks") class ListTasks(Resource): @classmethod - @jwt_required + @jwt_required() @task_ns.doc("list_tasks_in_mentorship_relation") @task_ns.expect(auth_header_parser) @task_ns.response( @@ -167,7 +167,7 @@ def get(cls, request_id): @task_ns.route("mentorship_relation//task//complete") class UpdateTask(Resource): @classmethod - @jwt_required + @jwt_required() @task_ns.doc("update_task_in_mentorship_relation") @task_ns.expect(auth_header_parser) @task_ns.response(HTTPStatus.OK, f"{messages.TASK_WAS_ACHIEVED_SUCCESSFULLY}") diff --git a/app/api/resources/task_comment.py b/app/api/resources/task_comment.py index 6cca3415a..59a6e8749 100644 --- a/app/api/resources/task_comment.py +++ b/app/api/resources/task_comment.py @@ -21,7 +21,7 @@ ) class CreateTaskComment(Resource): @classmethod - @jwt_required + @jwt_required() @task_comment_ns.expect(auth_header_parser, task_comment_model) @task_comment_ns.doc( responses={ @@ -61,7 +61,7 @@ def post(cls, relation_id, task_id): ) class TaskComment(Resource): @classmethod - @jwt_required + @jwt_required() @task_comment_ns.expect(auth_header_parser, task_comment_model) @task_comment_ns.doc( responses={ @@ -99,7 +99,7 @@ def put(cls, relation_id, task_id, comment_id): ) @classmethod - @jwt_required + @jwt_required() @task_comment_ns.expect(auth_header_parser) @task_comment_ns.doc( responses={ @@ -132,7 +132,7 @@ def delete(cls, relation_id, task_id, comment_id): ) class TaskComments(Resource): @classmethod - @jwt_required + @jwt_required() @task_comment_ns.expect(auth_header_parser) @task_comment_ns.response( HTTPStatus.OK, diff --git a/app/api/resources/user.py b/app/api/resources/user.py index 72cbae554..c69af3111 100644 --- a/app/api/resources/user.py +++ b/app/api/resources/user.py @@ -3,7 +3,6 @@ from flask import request from flask_jwt_extended import ( jwt_required, - jwt_refresh_token_required, create_access_token, create_refresh_token, get_jwt_identity, @@ -36,7 +35,7 @@ # TODO: @users_ns.response(404, 'User does not exist.') class UserList(Resource): @classmethod - @jwt_required + @jwt_required() @users_ns.doc( "list_users", params={ @@ -80,7 +79,7 @@ def get(cls): @users_ns.param("user_id", "The user identifier") class OtherUser(Resource): @classmethod - @jwt_required + @jwt_required() @users_ns.doc("get_user") @users_ns.expect(auth_header_parser) @users_ns.response(HTTPStatus.OK.value, "Success.", public_user_api_model) @@ -121,7 +120,7 @@ def get(cls, user_id): @users_ns.response(HTTPStatus.NOT_FOUND.value, "%s" % messages.USER_DOES_NOT_EXIST) class MyUserProfile(Resource): @classmethod - @jwt_required + @jwt_required() @users_ns.doc("get_user") @users_ns.expect(auth_header_parser, validate=True) @users_ns.marshal_with( @@ -138,7 +137,7 @@ def get(cls): return DAO.get_user(user_id) @classmethod - @jwt_required + @jwt_required() @users_ns.doc("update_user_profile") @users_ns.expect(auth_header_parser, update_user_request_body_model) @users_ns.response(HTTPStatus.OK.value, "%s" % messages.USER_SUCCESSFULLY_UPDATED) @@ -174,7 +173,7 @@ def put(cls): return DAO.update_user_profile(user_id, data) @classmethod - @jwt_required + @jwt_required() @users_ns.doc("delete_user") @users_ns.expect(auth_header_parser, validate=True) @users_ns.response(HTTPStatus.OK.value, "%s" % messages.USER_SUCCESSFULLY_DELETED) @@ -209,7 +208,7 @@ def delete(cls): @users_ns.route("user/change_password") class ChangeUserPassword(Resource): @classmethod - @jwt_required + @jwt_required() @users_ns.doc("update_user_password") @users_ns.expect( auth_header_parser, change_password_request_data_model, validate=True @@ -242,7 +241,7 @@ def put(cls): @users_ns.route("users/verified") class VerifiedUser(Resource): @classmethod - @jwt_required + @jwt_required() @users_ns.doc( "get_verified_users", params={ @@ -410,7 +409,7 @@ def post(cls): @users_ns.route("refresh") class RefreshUser(Resource): @classmethod - @jwt_refresh_token_required + @jwt_required(refresh=True) @users_ns.doc("refresh") @users_ns.response( HTTPStatus.OK.value, "Successful refresh", refresh_response_body_model @@ -536,7 +535,7 @@ def post(cls): @users_ns.response(HTTPStatus.NOT_FOUND.value, "%s" % messages.USER_NOT_FOUND) class UserHomeStatistics(Resource): @classmethod - @jwt_required + @jwt_required() @users_ns.expect(auth_header_parser) def get(cls): """Get Statistics regarding the current user @@ -561,7 +560,7 @@ def get(cls): @users_ns.response(HTTPStatus.NOT_FOUND.value, "User not found") class UserDashboard(Resource): @classmethod - @jwt_required + @jwt_required() @users_ns.expect(auth_header_parser) def get(cls): """Get current User's dashboard diff --git a/requirements.txt b/requirements.txt index e994c9c3b..c74dd6744 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ APScheduler==3.6.3 coverage==5.3 Flask==1.0.2 -Flask-JWT-Extended==3.25.0 +Flask-JWT-Extended==4.0.2 Flask-Mail==0.9.1 Flask-Migrate==2.5.3 flask-restx==0.2.0 From f7bc61a57cd88b83e491aad0e71f177b894f91c3 Mon Sep 17 00:00:00 2001 From: Aditya Kurkure <56596662+epicadk@users.noreply.github.com> Date: Mon, 26 Jul 2021 11:36:03 +0530 Subject: [PATCH 2/2] Update user.py --- app/api/resources/user.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/api/resources/user.py b/app/api/resources/user.py index 48967fad4..caba09a57 100644 --- a/app/api/resources/user.py +++ b/app/api/resources/user.py @@ -5,7 +5,6 @@ create_access_token, create_refresh_token, get_jwt_identity, - jwt_refresh_token_required, jwt_required, ) from flask_restx import Namespace, Resource, marshal