Skip to content

Commit

Permalink
fix: background notification for organisation approval
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj-Gupta4 committed Dec 19, 2024
1 parent b07265a commit bf6f357
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/backend/app/auth/auth_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ async def login_required(
request,
settings.cookie_name, # FMTM cookie
)
print("manage")
return await _authenticate_user(extracted_token)


Expand Down
7 changes: 4 additions & 3 deletions src/backend/app/helpers/helper_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}).")
Expand All @@ -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}).")
14 changes: 8 additions & 6 deletions src/backend/app/organisations/organisation_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Depends,
File,
HTTPException,
Request,
Response,
UploadFile,
)
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit bf6f357

Please sign in to comment.