Skip to content

Commit 60df340

Browse files
authored
Cleaning up of project email/activity feed semantics (#4542)
This PR is a smallish one to enhance some semantics around the project emails. Ideally making them more intuitive, removing old/redundant code, adding improvements for new code, and adding some logic to send more email notifications for time sensitive events.
1 parent f4056a8 commit 60df340

27 files changed

Lines changed: 203 additions & 121 deletions

hypha/apply/activity/adapters/activity_feed.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ class ActivityAdapter(AdapterBase):
5959
MESSAGES.SEND_FOR_APPROVAL: _("Requested approval"),
6060
MESSAGES.APPROVE_PAF: "handle_paf_assignment",
6161
MESSAGES.APPROVE_PROJECT: _("Approved"),
62-
MESSAGES.REQUEST_PROJECT_CHANGE: _(
63-
'requested changes for acceptance: "{comment}"'
64-
),
62+
MESSAGES.REQUEST_PROJECT_CHANGE: _("requested changes for acceptance"),
6563
MESSAGES.SUBMIT_CONTRACT_DOCUMENTS: _("Submitted Contract Documents"),
6664
MESSAGES.UPLOAD_CONTRACT: _("Uploaded a {contract.state} contract"),
6765
MESSAGES.APPROVE_CONTRACT: _("Approved contract"),

hypha/apply/activity/adapters/emails.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010

1111
from hypha.apply.activity import tasks
1212
from hypha.apply.activity.models import ALL, APPLICANT_PARTNERS, PARTNER
13-
from hypha.apply.projects.models.payment import CHANGES_REQUESTED_BY_STAFF, DECLINED
13+
from hypha.apply.projects.models.payment import (
14+
APPROVED_BY_FINANCE,
15+
CHANGES_REQUESTED_BY_FINANCE,
16+
CHANGES_REQUESTED_BY_STAFF,
17+
DECLINED,
18+
PAID,
19+
PAYMENT_FAILED,
20+
RESUBMITTED,
21+
)
1422
from hypha.apply.projects.templatetags.project_tags import display_project_status
1523
from hypha.apply.users.models import User
1624
from hypha.apply.users.roles import (
@@ -61,6 +69,7 @@ class EmailAdapter(AdapterBase):
6169
MESSAGES.REQUEST_PROJECT_CHANGE: "messages/email/project_request_change.html",
6270
MESSAGES.ASSIGN_PAF_APPROVER: "messages/email/assign_paf_approvers.html",
6371
MESSAGES.APPROVE_PAF: "messages/email/paf_for_approval.html",
72+
MESSAGES.CREATE_INVOICE: "messages/email/invoice_created.html",
6473
MESSAGES.UPDATE_INVOICE: "handle_invoice_updated",
6574
MESSAGES.UPDATE_INVOICE_STATUS: "handle_invoice_status_updated",
6675
MESSAGES.APPROVE_INVOICE: "messages/email/invoice_approved.html",
@@ -194,11 +203,23 @@ def handle_project_transition(self, source, **kwargs):
194203
)
195204

196205
def handle_invoice_status_updated(self, related, **kwargs):
197-
return self.render_message(
198-
"messages/email/invoice_status_updated.html",
199-
has_changes_requested=related.has_changes_requested,
200-
**kwargs,
201-
)
206+
if kwargs.get("recipient") and (
207+
user := User.objects.get(email=kwargs["recipient"])
208+
):
209+
if user.is_applicant:
210+
return self.render_message(
211+
"messages/email/invoice_status_updated_applicant.html",
212+
has_changes_requested=related.has_changes_requested,
213+
**kwargs,
214+
)
215+
elif user.is_org_faculty:
216+
kwargs["source_user"] = kwargs["user"]
217+
kwargs["user"] = user
218+
return self.render_message(
219+
"messages/email/invoice_status_updated_staff.html",
220+
has_changes_requested=related.has_changes_requested,
221+
**kwargs,
222+
)
202223

203224
def handle_invoice_updated(self, **kwargs):
204225
return self.render_message(
@@ -362,9 +383,17 @@ def recipients(self, message_type, source, user, **kwargs):
362383

363384
if message_type == MESSAGES.UPDATE_INVOICE_STATUS:
364385
related = kwargs.get("related", None)
365-
if related:
366-
if related.status in {CHANGES_REQUESTED_BY_STAFF, DECLINED}:
386+
if related and (status := related.status):
387+
if status in {
388+
CHANGES_REQUESTED_BY_STAFF,
389+
DECLINED,
390+
PAID,
391+
APPROVED_BY_FINANCE,
392+
PAYMENT_FAILED,
393+
}:
367394
return [source.user.email]
395+
elif status in {CHANGES_REQUESTED_BY_FINANCE, RESUBMITTED}:
396+
return [source.lead.email]
368397
return []
369398

370399
if message_type == MESSAGES.PROJECT_TRANSITION:
@@ -387,6 +416,12 @@ def recipients(self, message_type, source, user, **kwargs):
387416
return get_compliance_email(target_user_gps=[FINANCE_GROUP_NAME])
388417
return []
389418

419+
if message_type == MESSAGES.CREATE_INVOICE:
420+
if user == source.user:
421+
return [source.lead.email]
422+
else:
423+
return [source.user.email]
424+
390425
if isinstance(source, get_user_model()):
391426
return user.email
392427

hypha/apply/activity/templates/messages/email/applicant_base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% block salutation %}{% blocktrans with name=source.user.get_full_name|default:"applicant" %}Dear {{ name }},{% endblocktrans %}{% endblock %}
55

66
{# fmt:off #}
7-
{% block more_info %}{% trans "Link to your application" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}
7+
{% block more_info %}{% if source.submission %}{% trans "View your project here" %}{% else %}{% trans "View your submission here" %}{% endif %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}
88

99
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{% if source.submission %}{% url 'funds:submissions:comments' pk=source.submission.pk %}{% else %}{% url 'funds:submissions:comments' pk=source.pk %}{% endif %}
1010

hypha/apply/activity/templates/messages/email/contract_uploaded.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
{% if contract.is_signed %}
1919
{% trans "This contract has already been signed and there is no action for you to take." %}
2020
{% else %}
21-
{% blocktrans %}Please review the contract and sign it before reuploading it to your Project page for the {{ ORG_SHORT_NAME }} Team to approve.{% endblocktrans %}
21+
{% blocktrans %}Please review the contract and sign it before reuploading it to your project page for the {{ ORG_SHORT_NAME }} team to approve.{% endblocktrans %}
2222
{% endif %}
2323
{% endblock %}
2424

2525

2626
{% block more_info %}
2727
{% if request.user != source.user %}
28-
{% trans "Link to your application" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}
28+
{% trans "View your project here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}
2929
{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{% url 'funds:submissions:comments' pk=source.submission.pk %}
3030

3131
{% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }}

hypha/apply/activity/templates/messages/email/invoice_approved.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
{% load i18n %}
44
{% block salutation %}{% endblock %}
5-
65
{% block content %}{# fmt:off #}
7-
{% trans "An Invoice is waiting for your approval." %}
6+
{% blocktrans with title=source.title_text_display %}An invoice on project "{{title}}" is waiting for your approval.{% endblocktrans %}
87

9-
{% trans "Title" %}: {{ source.title_text_display }}
10-
{% trans "Link" %}: {{ request.scheme }}://{{ request.get_host }}{{ invoice.get_absolute_url }}
11-
{% trans "Project" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}
8+
{% trans "View the invoice here" %}: {{ request.scheme }}://{{ request.get_host }}{{ invoice.get_absolute_url }}
129

1310
{% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %}
1411
{% endblock %}{# fmt:on #}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends "messages/email/base.html" %}
2+
3+
{% load i18n %}
4+
{% block salutation %}{% endblock %}
5+
{% block content %}{# fmt:off #}
6+
{% blocktrans with title=source.title_text_display %}A new invoice has been submitted for project "{{title}}".{% endblocktrans %}
7+
8+
{% trans "View the invoice here" %}: {{ request.scheme }}://{{ request.get_host }}{{ related.get_absolute_url }}
9+
10+
{% endblock %}{# fmt:on #}

hypha/apply/activity/templates/messages/email/invoice_status_updated.html

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{% extends "messages/email/applicant_base.html" %}
2+
3+
{% load i18n invoice_tools %}
4+
5+
{% block content %}{# fmt:off #}
6+
{% display_invoice_status_for_user source.user invoice as invoice_status %}
7+
{% blocktrans with title=source.title_text_display %}An {{ ORG_SHORT_NAME }} staff member has updated the status for an invoice on your project "{{ title }}".{% endblocktrans %}
8+
9+
{% blocktrans with status=invoice_status %}It's status is now "{{ status }}".{% endblocktrans %}
10+
11+
{% if invoice.comment %}
12+
{% trans "A staff member left a comment that can be read here" %}: {{ request.scheme }}://{{ request.get_host }}{{ comment_url }}
13+
{% endif %}
14+
15+
{% trans "View your invoice here" %}: {{ request.scheme }}://{{ request.get_host }}{{ invoice.get_absolute_url }}
16+
17+
{% endblock %}{# fmt:on #}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{% extends "messages/email/base.html" %}
2+
3+
{% load i18n invoice_tools %}
4+
5+
{% block content %}{# fmt:off #}
6+
{% display_invoice_status_for_user user invoice as invoice_status %}
7+
{% blocktrans with title=source.title_text_display %}An invoice on the project "{{ title }}" had it's status updated by {{ source_user }}.{% endblocktrans %}
8+
9+
{% blocktrans with status=invoice_status %}It's status is now "{{ status }}".{% endblocktrans %}
10+
11+
{% if invoice.comment %}
12+
{% trans "A comment was left that can be read here" %}: {{ request.scheme }}://{{ request.get_host }}{{ comment_url }}
13+
{% endif %}
14+
15+
{% trans "View the invoice here" %}: {{ request.scheme }}://{{ request.get_host }}{{ invoice.get_absolute_url }}
16+
17+
{% endblock %}{# fmt:on #}

hypha/apply/activity/templates/messages/email/invoice_updated.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
{% load i18n invoice_tools %}
44
{% block content %}{# fmt:off #}
5-
{% display_invoice_status_for_user source.user invoice as invoice_status %}
65

7-
{% blocktrans with title=source.title date_from=invoice.date_from date_to=invoice.date_to %}An {{ ORG_SHORT_NAME }} staff member has updated your invoice for {{ title }} for period {{ date_from }} to {{ date_to }}.{% endblocktrans %}
8-
{% blocktrans %}It is now {{ invoice_status }}.{% endblocktrans %}
6+
{% blocktrans with title=source.title_text_display %}An {{ ORG_SHORT_NAME }} staff member has updated an invoice on your project "{{ title }}".{% endblocktrans %}
97

10-
{% trans "Title" %}: {{ source.title_text_display }}
11-
{% trans "Link" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}
8+
{% trans "View the invoice here:" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}
129
{% endblock %}{# fmt:on #}

0 commit comments

Comments
 (0)