Skip to content

Commit

Permalink
Add project name and Id in notifications (hotosm#5271)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aadesh-Baral authored Jul 28, 2022
1 parent 7a258ac commit 4150bda
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class EnvironmentConfig:
MAIL_DEBUG = True if LOG_LEVEL == "DEBUG" else False

# If disabled project update emails will not be sent.
SEND_PROJECT_EMAIL_UPDATES = os.getenv("TM_SEND_PROJECT_EMAIL_UPDATES", True)
SEND_PROJECT_EMAIL_UPDATES = int(os.getenv("TM_SEND_PROJECT_EMAIL_UPDATES", True))

# Languages offered by the Tasking Manager
# Please note that there must be exactly the same number of Codes as languages.
Expand Down
22 changes: 13 additions & 9 deletions backend/services/messaging/message_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ def send_message_after_validation(
validation_message.task_id = task_id
validation_message.from_user_id = validated_by
validation_message.to_user_id = mapped_by
validation_message.subject = f"{task_link} mapped by you in project {project_name} has been {status_text}"
validation_message.subject = (
f"{task_link} mapped by you in Project "
+ f"{project_name} #{project_id} has been {status_text}"
)
validation_message.message = text_template
messages.append(
dict(message=validation_message, user=user, project_name=project_name)
Expand Down Expand Up @@ -241,7 +244,10 @@ def send_message_after_comment(
message.task_id = task_id
message.from_user_id = comment_from
message.to_user_id = user.id
message.subject = f"You were mentioned in a comment in {task_link} of project {project_name}"
message.subject = (
f"You were mentioned in a comment in {task_link} "
+ f"of Project {project_name} #{project_id}"
)
message.message = comment
messages.append(
dict(message=message, user=user, project_name=project_name)
Expand Down Expand Up @@ -284,7 +290,7 @@ def send_message_after_comment(
message.from_user_id = comment_from
message.task_id = task_id
message.to_user_id = user.id
message.subject = f"{user_link} left a comment in {task_link} of project {project_name}"
message.subject = f"{user_link} left a comment in {task_link} of Project {project_name} #{project_id}"
message.message = comment
messages.append(
dict(message=message, user=user, project_name=project_name)
Expand All @@ -309,11 +315,9 @@ def send_project_transfer_message(

message = Message()
message.message_type = MessageType.PROJECT_ACTIVITY_NOTIFICATION.value
message.subject = (
f"Project {project_name} was transferred to {transferred_to}"
)
message.subject = f"Project {project_name} #{project_id} was transferred to {transferred_to}"
message.message = (
f"Project {project_name} associated with your "
f"Project {project_name} #{project_id} associated with your"
+ f"organisation {project.organisation.name} was transferred to {transferred_to} by {transferred_by}."
)
values = {
Expand Down Expand Up @@ -474,7 +478,7 @@ def send_message_after_chat(
message.project_id = project_id
message.from_user_id = chat_from
message.to_user_id = user.id
message.subject = f"You were mentioned in project {link} chat"
message.subject = f"You were mentioned in Project {link} chat"
message.message = chat
messages.append(
dict(message=message, user=user, project_name=project_name)
Expand Down Expand Up @@ -768,7 +772,7 @@ def get_project_link(
else:
section = ""

return f'<a href="{base_url}/projects/{project_id}{section}">{project_name}</a>'
return f'<a href="{base_url}/projects/{project_id}{section}">{project_name} #{project_id}</a>'

@staticmethod
def get_user_profile_link(user_name: str, base_url=None) -> str:
Expand Down
10 changes: 5 additions & 5 deletions backend/services/messaging/templates/message_alert_en.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
{% block content %}
<div style="padding: 0 2.357rem; margin: 4rem 0;">
{% if values['MESSAGE_TYPE'] == 3 %}
<p style="font-size: 14px; font-weight: 600"><a style="color: #d73f3f" href="{{values['FROM_USER_LINK']}}">@{{values['FROM_USERNAME']}}</a> mentioned you in a comment on <a style="color: #d73f3f" href="{{values['PROJECT_LINK']}}">Project {{values['PROJECT_ID']}}</a>:</p>
<p style="font-size: 14px; font-weight: 600"><a style="color: #d73f3f" href="{{values['FROM_USER_LINK']}}">@{{values['FROM_USERNAME']}}</a> mentioned you in a comment on <a style="color: #d73f3f" href="{{values['PROJECT_LINK']}}">Project {{values['PROJECT_NAME']}} #{{values['PROJECT_ID']}}</a>:</p>
{% endif %}
{% if values['MESSAGE_TYPE'] == 4 %}
<p style="font-size: 14px; font-weight: 600">Task validated on <a style="color: #d73f3f" href="{{values['PROJECT_LINK']}}">Project {{values['PROJECT_ID']}}</a>:</p>
<p style="font-size: 14px; font-weight: 600">Task validated on <a style="color: #d73f3f" href="{{values['PROJECT_LINK']}}">Project {{values['PROJECT_NAME']}} #{{values['PROJECT_ID']}}</a>:</p>
{% endif %}
{% if values['MESSAGE_TYPE'] == 5 %}
<p style="font-size: 14px; font-weight: 600">Task on <a style="color: #d73f3f" href="{{values['PROJECT_LINK']}}">Project {{values['PROJECT_ID']}}</a> needs more mapping:</p>
<p style="font-size: 14px; font-weight: 600">Task on <a style="color: #d73f3f" href="{{values['PROJECT_LINK']}}">Project {{values['PROJECT_NAME']}} #{{values['PROJECT_ID']}}</a> needs more mapping:</p>
{% endif %}
{% if values['MESSAGE_TYPE'] == 8 %}
<p style="font-size: 14px; font-weight: 600"><a style="color: #d73f3f" href="{{values['FROM_USER_LINK']}}">@{{values['FROM_USERNAME']}}</a> left a comment on <a style="color: #d73f3f" href="{{values['TASK_LINK']}}">Task {{values['TASK_ID']}}</a> in <a style="color: #d73f3f" href="{{values['PROJECT_LINK']}}">Project {{values['PROJECT_ID']}}</a>:</p>
<p style="font-size: 14px; font-weight: 600"><a style="color: #d73f3f" href="{{values['FROM_USER_LINK']}}">@{{values['FROM_USERNAME']}}</a> left a comment on <a style="color: #d73f3f" href="{{values['TASK_LINK']}}">Task {{values['TASK_ID']}}</a> in <a style="color: #d73f3f" href="{{values['PROJECT_LINK']}}">Project {{values['PROJECT_NAME']}} #{{values['PROJECT_ID']}}</a>:</p>
{% endif %}
{% if values['MESSAGE_TYPE'] == 9 %}
<p style="font-size: 14px; font-weight: 600"><a style="color: #d73f3f" href="{{values['FROM_USER_LINK']}}">@{{values['FROM_USERNAME']}}</a> left a comment on <a style="color: #d73f3f" href="{{values['PROJECT_LINK']}}">Project {{values['PROJECT_ID']}}</a>:</p>
<p style="font-size: 14px; font-weight: 600"><a style="color: #d73f3f" href="{{values['FROM_USER_LINK']}}">@{{values['FROM_USERNAME']}}</a> left a comment on <a style="color: #d73f3f" href="{{values['PROJECT_LINK']}}">Project {{values['PROJECT_NAME']}} #{{values['PROJECT_ID']}}</a>:</p>
{% endif %}
<p>
{{ values['CONTENT']|safe }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_message_service_generates_correct_chat_link(self):

self.assertEqual(
link,
'<a href="http://test.com/projects/1#questionsAndComments">TEST_PROJECT</a>',
'<a href="http://test.com/projects/1#questionsAndComments">TEST_PROJECT #1</a>',
)
link = MessageService.get_project_link(
1,
Expand All @@ -41,5 +41,5 @@ def test_message_service_generates_correct_chat_link(self):

self.assertEqual(
link,
'<a href="http://test.com/projects/1">TEST_PROJECT</a>',
'<a href="http://test.com/projects/1">TEST_PROJECT #1</a>',
)

0 comments on commit 4150bda

Please sign in to comment.