From 11db42bad1e77748b9af4901bbe5e2df0e2c303b Mon Sep 17 00:00:00 2001 From: Pradip-p Date: Thu, 25 Jul 2024 11:23:04 +0545 Subject: [PATCH 1/4] feat: Filter pending tasks by state in function --- src/backend/app/projects/project_crud.py | 2 +- src/backend/app/tasks/task_crud.py | 15 +++++++++++++++ src/backend/app/tasks/task_routes.py | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index 1582c27a..484cb908 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -52,7 +52,7 @@ async def create_project_with_project_info( "status": ProjectStatus.DRAFT.name, "visibility": project_metadata.visibility.name, "outline": str(project_metadata.outline), - "no_fly_zones": str(project_metadata.no_fly_zones), + "no_fly_zones": str(project_metadata.no_fly_zones) if project_metadata.no_fly_zones is not None else None, "dem_url": project_metadata.dem_url, "output_orthophoto_url": project_metadata.output_orthophoto_url, "output_pointcloud_url": project_metadata.output_pointcloud_url, diff --git a/src/backend/app/tasks/task_crud.py b/src/backend/app/tasks/task_crud.py index f63cdfb3..cf5f3c94 100644 --- a/src/backend/app/tasks/task_crud.py +++ b/src/backend/app/tasks/task_crud.py @@ -163,3 +163,18 @@ async def get_requested_user_id( if result is None: raise ValueError("No user requested for mapping") return result["user_id"] + + + +async def get_project_task_by_id(db: Database, project_id: uuid.UUID): + """Get all tasks associated with a specific project by project_id.""" + raw_sql = """ + SELECT t.id AS task_id, te.event_id, te.user_id, te.comment, te.state, te.created_at + FROM tasks t + LEFT JOIN task_events te ON t.id = te.task_id + WHERE t.project_id = :project_id + ORDER BY t.project_task_index; + """ + db_tasks = await db.fetch_all(raw_sql, {"project_id": project_id}) + + return db_tasks \ No newline at end of file diff --git a/src/backend/app/tasks/task_routes.py b/src/backend/app/tasks/task_routes.py index 168289cf..804ee485 100644 --- a/src/backend/app/tasks/task_routes.py +++ b/src/backend/app/tasks/task_routes.py @@ -1,5 +1,5 @@ import uuid -from fastapi import APIRouter, BackgroundTasks, Depends +from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException from app.config import settings from app.models.enums import EventType, State from app.tasks import task_schemas, task_crud @@ -140,3 +140,19 @@ async def new_event( ) return True + + + +@router.get("/requested_tasks/{project_id}/pending") +async def get_pending_tasks( + project_id: uuid.UUID, + user_data: AuthUser = Depends(login_required), + db: Database = Depends(database.encode_db), +): + """Get a list of pending tasks for a specific project and user.""" + # Ensure that the user is authorized to view tasks for the project + pending_tasks = await task_crud.get_project_task_by_id(db, project_id) + if pending_tasks is None: + raise HTTPException(status_code=404, detail="Project not found") + # Fetch the pending tasks for the project + return pending_tasks From 466496afcf74f0441f3052f070c706d6dafe15a3 Mon Sep 17 00:00:00 2001 From: Pradip-p Date: Thu, 25 Jul 2024 15:22:42 +0545 Subject: [PATCH 2/4] feat: add email notification for mapping request approval & mapping request rejection --- .../app/email_templates/mapping_approved.html | 140 ++++++++++++++++++ .../app/email_templates/mapping_requests.html | 6 +- src/backend/app/projects/project_crud.py | 4 +- src/backend/app/tasks/task_crud.py | 11 +- src/backend/app/tasks/task_routes.py | 63 +++++++- 5 files changed, 210 insertions(+), 14 deletions(-) create mode 100644 src/backend/app/email_templates/mapping_approved.html diff --git a/src/backend/app/email_templates/mapping_approved.html b/src/backend/app/email_templates/mapping_approved.html new file mode 100644 index 00000000..c7bf1b35 --- /dev/null +++ b/src/backend/app/email_templates/mapping_approved.html @@ -0,0 +1,140 @@ + + + + + + {{ email_subject }} + + + + + + diff --git a/src/backend/app/email_templates/mapping_requests.html b/src/backend/app/email_templates/mapping_requests.html index d4feec04..6c9de9b9 100644 --- a/src/backend/app/email_templates/mapping_requests.html +++ b/src/backend/app/email_templates/mapping_requests.html @@ -125,11 +125,11 @@

Drone Tasking Manager Invite

Mapping Task Details

+

Drone Operator: {{drone_operator_name}}

+

Task ID: {{task_id}}

Project:{{project_name}}

- Description: Drone Tasking Manager Project - Description -

+ Description: {{description}}

Start Mapping Date: Thu, 25 Jul 2024 15:27:11 +0545 Subject: [PATCH 3/4] feat: changes filename --- ...apping_approved.html => mapping_approved_or_rejected.html} | 0 src/backend/app/tasks/task_routes.py | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/backend/app/email_templates/{mapping_approved.html => mapping_approved_or_rejected.html} (100%) diff --git a/src/backend/app/email_templates/mapping_approved.html b/src/backend/app/email_templates/mapping_approved_or_rejected.html similarity index 100% rename from src/backend/app/email_templates/mapping_approved.html rename to src/backend/app/email_templates/mapping_approved_or_rejected.html diff --git a/src/backend/app/tasks/task_routes.py b/src/backend/app/tasks/task_routes.py index 39958df8..931f58ef 100644 --- a/src/backend/app/tasks/task_routes.py +++ b/src/backend/app/tasks/task_routes.py @@ -84,7 +84,7 @@ async def new_event( ) drone_operator = await get_user_by_id(db, requested_user_id) html_content = render_email_template( - template_name="mapping_approved.html", + template_name="mapping_approved_or_rejected.html", context={ "email_subject": "Mapping Request Approved", "email_body": "We are pleased to inform you that your mapping request has been approved. Your contribution is invaluable to our efforts in improving humanitarian responses worldwide.", @@ -127,7 +127,7 @@ async def new_event( ) drone_operator = await get_user_by_id(db, requested_user_id) html_content = render_email_template( - template_name="mapping_approved.html", + template_name="mapping_approved_or_rejected.html", context={ "email_subject": "Mapping Request Rejected", "email_body": "We are sorry to inform you that your mapping request has been rejected.", From d5004f53f5b7c12b815595983c54cdd2ba4fddae Mon Sep 17 00:00:00 2001 From: Pradip-p Date: Thu, 25 Jul 2024 17:03:39 +0545 Subject: [PATCH 4/4] fix: added task rejected email --- src/backend/app/tasks/task_routes.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/app/tasks/task_routes.py b/src/backend/app/tasks/task_routes.py index 931f58ef..0520f428 100644 --- a/src/backend/app/tasks/task_routes.py +++ b/src/backend/app/tasks/task_routes.py @@ -140,6 +140,13 @@ async def new_event( }, ) + background_tasks.add_task( + send_notification_email, + drone_operator.email_address, + "Task is Rejected", + html_content, + ) + return await task_crud.update_task_state( db, project_id,