From bf6f357d91128a11ea8958ea52bf853cb2c88fda Mon Sep 17 00:00:00 2001 From: Anuj-Gupta4 Date: Thu, 19 Dec 2024 15:23:51 +0545 Subject: [PATCH] fix: background notification for organisation approval --- src/backend/app/auth/auth_deps.py | 1 - src/backend/app/helpers/helper_routes.py | 7 ++++--- .../app/organisations/organisation_routes.py | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/backend/app/auth/auth_deps.py b/src/backend/app/auth/auth_deps.py index bc3276e9f..4bea8abde 100644 --- a/src/backend/app/auth/auth_deps.py +++ b/src/backend/app/auth/auth_deps.py @@ -273,7 +273,6 @@ async def login_required( request, settings.cookie_name, # FMTM cookie ) - print("manage") return await _authenticate_user(extracted_token) diff --git a/src/backend/app/helpers/helper_routes.py b/src/backend/app/helpers/helper_routes.py index f9ca538e9..27c793428 100644 --- a/src/backend/app/helpers/helper_routes.py +++ b/src/backend/app/helpers/helper_routes.py @@ -342,10 +342,10 @@ async def send_test_osm_message( async def send_approval_message( + request: Request, creator_id: int, organisation_name: str, - osm_auth: Annotated[Auth, Depends(init_osm_auth)], - request: Request, + osm_auth: Auth, ): """Send message to the organisation creator after approval.""" log.info(f"Sending approval message to organisation creator ({creator_id}).") @@ -355,10 +355,11 @@ async def send_approval_message( Your organisation **{organisation_name}** has been approved. - You can now manage your organisation and add team members. + You can now manage your organisation freely. Thank you for being a part of our platform! """) send_osm_message( osm_token, creator_id, "Your organisation has been approved!", message_content ) + log.info(f"Approval message sent to organisation creator ({creator_id}).") diff --git a/src/backend/app/organisations/organisation_routes.py b/src/backend/app/organisations/organisation_routes.py index 0b57cfb00..c0a1a8ec1 100644 --- a/src/backend/app/organisations/organisation_routes.py +++ b/src/backend/app/organisations/organisation_routes.py @@ -25,6 +25,7 @@ Depends, File, HTTPException, + Request, Response, UploadFile, ) @@ -33,6 +34,7 @@ from app.auth.auth_deps import login_required from app.auth.auth_schemas import AuthUser, OrgUserDict +from app.auth.providers.osm import init_osm_auth from app.auth.roles import org_admin, super_admin from app.db.database import db_conn from app.db.enums import HTTPStatus @@ -130,10 +132,12 @@ async def delete_unapproved_org( @router.post("/approve", response_model=OrganisationOut) async def approve_organisation( + request: Request, org_id: int, background_tasks: BackgroundTasks, db: Annotated[Connection, Depends(db_conn)], current_user: Annotated[AuthUser, Depends(super_admin)], + osm_auth=Depends(init_osm_auth), ): """Approve the organisation request made by the user. @@ -154,14 +158,12 @@ async def approve_organisation( ) log.info(f"Approved organisation ({org_id}).") - log.info( - f"Starting background task to notify user ({approved_org.created_by})." - ) background_tasks.add_task( send_approval_message, - approved_org.created_by, - approved_org.name, - current_user, + request=request, + creator_id=approved_org.created_by, + organisation_name=approved_org.name, + osm_auth=osm_auth, ) return approved_org