Skip to content
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2454bf0
added basic logic to send email through different actions.
roman-stolar Feb 24, 2025
210fc6f
added email templated + added send email logic
roman-stolar Feb 24, 2025
1c8f7d4
filled templates
roman-stolar Feb 25, 2025
a12a5b1
fix
roman-stolar Feb 25, 2025
6196cd7
applied all data to email templates
roman-stolar Feb 25, 2025
14c91e8
Merge branch 'main' into OSDEV-1721-customer-comms-slc-workflow
roman-stolar Feb 25, 2025
803e516
fix linter errors
roman-stolar Feb 25, 2025
5ce4ff3
fix linter
roman-stolar Feb 26, 2025
2f04dbe
Update template and data for "Email 1: OS ID exists / additional cont…
roman-stolar Feb 26, 2025
374324b
fix
roman-stolar Feb 26, 2025
1892c18
Update template and data for "Email 2: OS ID exists / additional cont…
roman-stolar Feb 26, 2025
4677b58
Update template and data for "Email 4: OS ID does not exist / new fac…
roman-stolar Feb 26, 2025
085f504
fix linter
roman-stolar Feb 26, 2025
b6972a1
Update template and data for "Email 3: OS ID exists / additional cont…
roman-stolar Feb 26, 2025
b6a7be6
Merge branch 'main' into OSDEV-1721-customer-comms-slc-workflow
roman-stolar Feb 26, 2025
9941435
update field name
roman-stolar Feb 26, 2025
91c64a3
fix linter
roman-stolar Feb 26, 2025
1bb0b62
updated body .txt with links
roman-stolar Feb 27, 2025
aaad513
updated sender
roman-stolar Feb 27, 2025
aed339e
fixes
roman-stolar Feb 27, 2025
a6052a6
updated release notes
roman-stolar Feb 27, 2025
49d74e5
fix linter
roman-stolar Feb 27, 2025
3c6e477
small improvements
roman-stolar Feb 27, 2025
55cae64
fix
roman-stolar Feb 27, 2025
4d5cf0a
fix Vlad comments
roman-stolar Feb 27, 2025
f72d19e
fix code rabbit comment
roman-stolar Feb 27, 2025
6180343
fix linter
roman-stolar Feb 27, 2025
793d86a
Merge branch 'main' into OSDEV-1721-customer-comms-slc-workflow
roman-stolar Feb 27, 2025
d37ccc5
added logic to send email only for SLC request
roman-stolar Feb 27, 2025
fd53a8d
fetch is_claimed data from FacilityClaim
roman-stolar Feb 28, 2025
31cdafe
fix
roman-stolar Feb 28, 2025
1e6c3e3
Updated unit tests to cover new email templates sending
roman-stolar Feb 28, 2025
b051f5d
fix fail test
roman-stolar Feb 28, 2025
ae06821
fix tests
roman-stolar Feb 28, 2025
03a6b4f
Merge branch 'main' into OSDEV-1721-customer-comms-slc-workflow
roman-stolar Mar 3, 2025
c92cf4d
fix linter
roman-stolar Mar 3, 2025
33b46c3
fixes
roman-stolar Mar 3, 2025
db0c46c
fixed test
roman-stolar Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/release/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html

### What's new
* [OSDEV-1764](https://opensupplyhub.atlassian.net/browse/OSDEV-1764) - Added a new claiming email for the Moderation queue/SLC workflow, which is sent once a data moderator creates a new location based on the moderation event the customer submitted through the SLC workflow.
* [OSDEV-1721](https://opensupplyhub.atlassian.net/browse/OSDEV-1721) - Added new email templates for Moderation/SLC workflow:
* Email #1 SLC additional contribution to existing production location - Pending moderation.
* Email #2 SLC contribution - Moderation complete. APPROVED.
* Email #3 SLC contribution - Moderation complete. REJECTED.
* Email #4 SLC new production location contribution - Pending moderation.

### Release instructions:
* Ensure that the following commands are included in the `post_deployment` command:
Expand Down
160 changes: 156 additions & 4 deletions src/django/api/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
from django.core.mail import send_mail
from django.conf import settings
from django.template.loader import get_template

from api.models.facility.facility_list import FacilityList
from api.models.moderation_event import ModerationEvent
from api.models import (
FacilityList,
FacilityClaim,
ModerationEvent,
Facility
)
from countries.lib.countries import COUNTRY_NAMES
from api.models.facility.facility import Facility
from api.constants import FacilityClaimStatuses


def make_oshub_url(request: Request):
Expand Down Expand Up @@ -42,6 +45,23 @@ def make_claim_url(request: Request, location: Facility):
return '{}/claim'.format(make_facility_url(request, location))


def make_pl_search_url(request):
return (
"{}/contribute/single-location".format(
make_oshub_url(request)
)
)


def make_pl_claim_url(request, facility):
return (
"{}/facilities/{}/claim".format(
make_oshub_url(request),
facility.id,
)
)


def send_claim_facility_confirmation_email(request, facility_claim):
subj_template = get_template('mail/claim_facility_submitted_subject.txt')
text_template = get_template('mail/claim_facility_submitted_body.txt')
Expand Down Expand Up @@ -445,3 +465,135 @@ def send_production_location_creation_email(
[moderation_event.contributor.admin.email],
html_message=html_template.render(creation_dict)
)


def send_slc_additional_info_confirmation_email(moderation_event):
subj_template = get_template(
'mail/slc_additional_info_confirmation_subject.txt'
)
text_template = get_template(
'mail/slc_additional_info_confirmation_body.txt'
)
html_template = get_template(
'mail/slc_additional_info_confirmation_body.html'
)

additional_info_dictionary = {
'pl_name': moderation_event.cleaned_data.get("name", ''),
'pl_address': moderation_event.cleaned_data.get("address", ''),
'pl_country': (
moderation_event.cleaned_data.get("country_code", '')
),
}

send_mail(
subj_template.render().rstrip(),
text_template.render(additional_info_dictionary),
settings.DATA_FROM_EMAIL,
[moderation_event.contributor.admin.email],
html_message=html_template.render(additional_info_dictionary)
)


def send_slc_new_location_confirmation_email(moderation_event):
subj_template = get_template(
'mail/slc_new_location_confirmation_subject.txt'
)
text_template = get_template(
'mail/slc_new_location_confirmation_body.txt'
)
html_template = get_template(
'mail/slc_new_location_confirmation_body.html'
)

send_mail(
subj_template.render().rstrip(),
text_template.render(),
settings.DATA_FROM_EMAIL,
[moderation_event.contributor.admin.email],
html_message=html_template.render()
)


def send_slc_contribution_approval_email(
request,
moderation_event,
facility_list_item
):
subj_template = get_template(
'mail/slc_contribution_approval_subject.txt'
)
text_template = get_template(
'mail/slc_contribution_approval_body.txt'
)
html_template = get_template(
'mail/slc_contribution_approval_body.html'
)

is_claimed = FacilityClaim.objects.filter(
facility=facility_list_item.facility,
status__in=[
FacilityClaimStatuses.APPROVED,
FacilityClaimStatuses.PENDING
]
).exists()

approval_dictionary = {
'is_claimed': is_claimed,
'pl_claim_url': make_pl_claim_url(
request,
facility_list_item.facility
),
'os_id': facility_list_item.facility.id,
'location_url': make_facility_url(
request,
facility_list_item.facility
),
}

send_mail(
subj_template.render().rstrip(),
text_template.render(approval_dictionary),
settings.DATA_FROM_EMAIL,
[moderation_event.contributor.admin.email],
html_message=html_template.render(approval_dictionary)
)


def send_slc_contribution_rejected_email(request, moderation_event):
subj_template = get_template(
'mail/slc_contribution_rejected_subject.txt'
)
text_template = get_template(
'mail/slc_contribution_rejected_body.txt'
)
html_template = get_template(
'mail/slc_contribution_rejected_body.html'
)

rejected_dictionary = {
'action_reason_text_cleaned': getattr(
moderation_event,
"action_reason_text_cleaned",
None
),
'action_reason_text_raw': getattr(
moderation_event,
"action_reason_text_raw",
None
),
'pl_search_url': make_pl_search_url(request),
'pl_name': moderation_event.cleaned_data.get("name", ''),
'pl_address': moderation_event.cleaned_data.get("address", ''),
'pl_country': (
moderation_event.cleaned_data.get("country_code", '')
),
}

send_mail(
subj_template.render().rstrip(),
text_template.render(rejected_dictionary),
settings.DATA_FROM_EMAIL,
[moderation_event.contributor.admin.email],
html_message=html_template.render(rejected_dictionary)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Thank You for Your Submission – It Is Now Being Reviewed
</title>
</head>
<body>
<p>Hello,</p>
<p>
Thank you for submitting your production location information to <a href="https://info.opensupplyhub.org/">Open Supply Hub</a> (OS Hub)!
</p>
<p>
Our team is now reviewing your submission to ensure it can be assigned an <a href="https://info.opensupplyhub.org/resources/a-free-universal-id-matching-algorithm">OS ID</a>. This
process may take up to 15 business days.
</p>
<p>
Once the review is complete, you will receive an email confirming your OS ID. If we need any
additional information, we will contact you at this email address.
</p>
<p>
<b>Here are the details of your submission:</b>
</p>
<ul>
<li>Production Location Name: {{ pl_name }}</li>
<li>Production Location Address: {{ pl_address }}</li>
<li>Production Location Country: {{ pl_country }}</li>
</ul>
<p>
<b>If you have also requested to <a href="https://info.opensupplyhub.org/resources/claim-a-facility">claim this location</a>:</b> After your OS ID is confirmed, we will
review the documents you submitted to claim the location and either approve or deny the claim.
You will also receive an email when this stage is complete.
</p>
<p>
Thank you for sharing your information! Your data helps open doors to safe and sustainable
supply chains.
</p>
<p>Best Regards,</p>
{% include "mail/signature_block.html" %}
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% block content %}
Hello,

Thank you for submitting your production location information to Open Supply Hub (https://info.opensupplyhub.org/) (OS Hub)!

Our team is now reviewing your submission to ensure it can be assigned an OS ID.
This process may take up to 15 business days.

Once the review is complete, you will receive an email confirming your OS ID (https://info.opensupplyhub.org/resources/a-free-universal-id-matching-algorithm).
If we need any additional information, we will contact you at this email address.

Here are the details of your submission:
- Production Location Name: {{ pl_name }}
- Production Location Address: {{ pl_address }}
- Production Location Country: {{ pl_country }}

If you have also requested to claim this location (https://info.opensupplyhub.org/resources/claim-a-facility): After your OS ID is confirmed, we will
review the documents you submitted to claim the location and either approve or deny the claim.
You will also receive an email when this stage is complete.

Thank you for sharing your information! Your data helps open doors to safe and sustainable
supply chains.

Best Regards,

{% include "mail/signature_block.txt" %}
{% endblock content %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thank You for Your Submission – It Is Now Being Reviewed
58 changes: 58 additions & 0 deletions src/django/api/templates/mail/slc_contribution_approval_body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Great News: your OS ID is ready!
</title>
</head>
<body>
<p>
Hello,
</p>
<p>
Thank you for submitting your production location information to <a href="https://info.opensupplyhub.org/">Open Supply Hub</a> (OS Hub)!
</p>
<p>
You can now:
</p>
<ol>
<li>
<p>
<b>Save your OS ID and the public link</b> to your production location profile and share it
with clients and stakeholders:
</p>
<ul>
<li>OS ID: {{ os_id }}</li>
<li>Public link: {{ location_url }}</li>
</ul>
</li>
{% if not is_claimed %}
<li>
<p>
<b>Claim your production location</b> to take control of
your data and make it visible to more global partners. It’s free and only takes a few
steps! <b><a href="{{ pl_claim_url }}">Claim my production location now</a></b>.
</p>
</li>
{% endif %}
<li>
<p>
<b>Learn more about the OS ID</b> and how to use it to advance your business
in this <a href="https://info.opensupplyhub.org/facilities">Guide for Facilities</a>.
</p>
</li>
</ol>
{% if is_claimed %}
<p>
<b>We will now review the documents you submitted to <a href="https://info.opensupplyhub.org/resources/claim-a-facility">claim the location</a>
and either approve or deny the claim.</b> Review of claims typically takes 7 - 10 business days.
You will receive another email when this stage is complete.
</p>
{% endif %}
<p>
Thank you for sharing your information! Your data helps open doors to safe and sustainable
supply chains.
</p>
{% include "mail/signature_block.html" %}
</body>
</html>
32 changes: 32 additions & 0 deletions src/django/api/templates/mail/slc_contribution_approval_body.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% block content %}
Hello,

Thank you for submitting your production location information to Open Supply Hub (https://info.opensupplyhub.org/) (OS Hub)!

You can now:
1. Save your OS ID and the public link to your production location profile and share it
with clients and stakeholders:
- OS ID: {{ os_id }}
- Public link: {{ location_url }}
{% if not is_claimed %}
2. Claim your production location to take control of
your data and make it visible to more global partners. It’s free and only takes a few
steps! Claim my production location now ({{ pl_claim_url }}).
3. Learn more about the OS ID and how to use it to advance your business in this Guide for Facilities (https://info.opensupplyhub.org/facilities).
{% else %}
2. Learn more about the OS ID and how to use it to advance your business in this Guide for Facilities (https://info.opensupplyhub.org/facilities).
{% endif %}

{% if is_claimed %}
We will now review the documents you submitted to claim the location (https://info.opensupplyhub.org/resources/claim-a-facility)
and either approve or deny the claim. Review of claims typically takes 7 - 10 business days.
You will receive another email when this stage is complete.
{% endif %}

Thank you for sharing your information! Your data helps open doors to safe and sustainable
supply chains.

Best Regards,

{% include "mail/signature_block.txt" %}
{% endblock content %}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Great News: your OS ID is ready!
Loading
Loading