Skip to content

Commit

Permalink
feat: update drone-flightplan to v0.3.2 and notify project creator on…
Browse files Browse the repository at this point in the history
… unflyable task state (#357)

* feat: notify project creator when a task is marked as unflyable

* feat: upgrade drone-flightplan to >=0.3.2 and add email notification for unflyable task

* fix: added author email to send the email notification
  • Loading branch information
Pradip-p authored Nov 27, 2024
1 parent 32f9d91 commit 196d2b2
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 17 deletions.
133 changes: 133 additions & 0 deletions src/backend/app/email_templates/mapping/task_marked_unflyable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ email_subject }}</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.email-container {
max-width: 600px;
background-color: #ffffff;
border-radius: 10px;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
overflow: hidden;
margin: 20px;
}

.header {
background-color: #d73f3f;
color: #ffffff;
text-align: center;
padding: 25px;
border-radius: 10px 10px 0 0;
}

.header h1 {
margin: 0;
font-size: 26px;
}

.content {
padding: 25px;
}

.content p {
font-size: 16px;
line-height: 1.5;
color: #333333;
}

.task {
margin: 20px 0;
background-color: #f9f9f9;
padding: 20px;
border: 1px solid #eeeeee;
border-radius: 8px;
}

.task h2 {
margin: 0 0 10px;
font-size: 20px;
color: #d73f3f;
}

.task p {
margin: 5px 0;
color: #555555;
}

.task-details {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}

.task-details p {
margin: 0;
font-size: 16px;
color: #555555;
}

.footer {
background-color: #f4f4f4;
text-align: center;
padding: 20px;
color: #666666;
font-size: 14px;
border-radius: 0 0 10px 10px;
}
body {
margin: auto;
width: 65%;
}
</style>
</head>
<body>
<div class="email-container">
<div class="header">
<h1>{{ email_subject }}</h1>
</div>
<div class="content">
<p>Dear {{ name }},</p>
<p>
We regret to inform you that the task associated with your project "{{
project_name }}" has been marked as <strong>unflyable</strong> by the
drone operator, {{ drone_operator_name }}.
</p>
<p>Please find below the details of the task:</p>
<div class="task">
<h2>Task Details</h2>
<div class="task-details">
<p><strong>Project:</strong> {{ project_name }}</p>
<p><strong>Task ID:</strong> {{ project_task_index }}</p>
<p><strong>Description:</strong> {{ description }}</p>
</div>
<a
href="{{FRONTEND_URL}}/projects/{{project_id}}/tasks/{{task_id}}"
class="task-button"
>Visit Drone Tasking Manager</a
>
</div>
<p>
Note: Please review the project on your platform to determine the next
steps.
</p>
</div>
<div class="footer">
<p>Thank you for your support,</p>
<p>The HOTOSM Team</p>
</div>
</div>
</body>
</html>
40 changes: 38 additions & 2 deletions src/backend/app/tasks/task_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ async def handle_event(
)

requested_user_id = await user_schemas.DbUser.get_requested_user_id(
db, project_id, task_id
db, project_id, task_id, State.REQUEST_FOR_MAPPING
)
drone_operator = await user_schemas.DbUser.get_user_by_id(
db, requested_user_id
Expand Down Expand Up @@ -395,7 +395,7 @@ async def handle_event(
)

requested_user_id = await user_schemas.DbUser.get_requested_user_id(
db, project_id, task_id
db, project_id, task_id, State.REQUEST_FOR_MAPPING
)
drone_operator = await user_schemas.DbUser.get_user_by_id(
db, requested_user_id
Expand Down Expand Up @@ -479,6 +479,42 @@ async def handle_event(
detail.updated_at,
)
case EventType.COMMENT:
author = await user_schemas.DbUser.get_user_by_id(db, project["author_id"])

requested_user_id = await user_schemas.DbUser.get_requested_user_id(
db, project_id, task_id, State.LOCKED_FOR_MAPPING
)
project_task_index = next(
(
task["project_task_index"]
for task in project["tasks"]
if task["id"] == task_id and task["user_id"] == requested_user_id
),
None,
)
drone_operator = await user_schemas.DbUser.get_user_by_id(db, user_data.id)
html_content = render_email_template(
folder_name="mapping",
template_name="task_marked_unflyable.html",
context={
"email_subject": "Task Marked as Unflyable: Action Required",
"task_status": "unflyable",
"name": user_data.name,
"drone_operator_name": drone_operator["name"],
"task_id": task_id,
"project_task_index": project_task_index,
"project_name": project["name"],
"description": project["description"],
},
)

background_tasks.add_task(
send_notification_email,
author["email_address"],
"Task Marked as Unflyable",
html_content,
)

return await update_task_state(
db,
project_id,
Expand Down
8 changes: 5 additions & 3 deletions src/backend/app/users/user_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,21 +321,23 @@ async def get_user_by_email(db: Connection, email: str) -> dict[str, Any]:

@staticmethod
async def get_requested_user_id(
db: Connection, project_id: uuid.UUID, task_id: uuid.UUID
db: Connection, project_id: uuid.UUID, task_id: uuid.UUID, current_state: State
):
async with db.cursor(row_factory=dict_row) as cur:
await cur.execute(
"""
SELECT user_id
FROM task_events
WHERE project_id = %(project_id)s AND task_id = %(task_id)s and state = %(request_for_map_state)s
WHERE project_id = %(project_id)s
AND task_id = %(task_id)s
AND state = %(current_state)s
ORDER BY created_at DESC
LIMIT 1
""",
{
"project_id": str(project_id),
"task_id": str(task_id),
"request_for_map_state": State.REQUEST_FOR_MAPPING.name,
"current_state": current_state.name,
},
)

Expand Down
22 changes: 11 additions & 11 deletions src/backend/pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ dependencies = [
"psycopg2>=2.9.9",
"pyodm>=1.5.11",
"asgiref>=3.8.1",
"drone-flightplan>=0.3.1",
"bcrypt>=4.2.1",
"drone-flightplan>=0.3.2",
]
requires-python = ">=3.11"
license = {text = "GPL-3.0-only"}
Expand Down

0 comments on commit 196d2b2

Please sign in to comment.