-
Notifications
You must be signed in to change notification settings - Fork 7
EAP: Email setup and templates #2607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sudip-khanal
wants to merge
4
commits into
project/eap-workflow
Choose a base branch
from
feat/add-email-setup-and-template
base: project/eap-workflow
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fe2765e
feat(eap): Add email setup and template
sudip-khanal 280f38c
chore(submodule): Update submodule reference
sudip-khanal 6df95e0
fix(eap): align test with renamed task send_new_eap_registration_email
sudip-khanal 8d96244
chore(eap): Add typing for regional coordinator email mapping
sudip-khanal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| [submodule "assets"] | ||
| path = assets | ||
| url = https://github.com/IFRCGo/go-api-artifacts | ||
| url = git@github.com:IFRCGo/go-api-artifacts.git |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| from django.http import HttpResponse | ||
| from django.template import loader | ||
| from rest_framework import permissions | ||
| from rest_framework.views import APIView | ||
|
|
||
|
|
||
| class EAPEmailPreview(APIView): | ||
| permission_classes = [permissions.IsAuthenticated] | ||
|
|
||
| def get(self, request): | ||
| type_param = request.GET.get("type") | ||
|
|
||
| template_map = { | ||
| "registration": "email/eap/registration.html", | ||
| "submission": "email/eap/submission.html", | ||
| "feedback_to_national_society": "email/eap/feedback_to_national_society.html", | ||
| "resubmission_of_revised_eap": "email/eap/re-submission.html", | ||
| "feedback_for_revised_eap": "email/eap/feedback_to_revised_eap.html", | ||
| "technically_validated_eap": "email/eap/technically_validated_eap.html", | ||
| "pending_pfa": "email/eap/pending_pfa.html", | ||
| "approved_eap": "email/eap/approved.html", | ||
| "reminder": "email/eap/reminder.html", | ||
| } | ||
|
|
||
| if type_param not in template_map: | ||
| valid_values = ", ".join(template_map.keys()) | ||
| return HttpResponse( | ||
| f"Invalid 'type' parameter. Please use one of the following values: {valid_values}.", | ||
| ) | ||
|
|
||
| context_map = { | ||
| "registration": { | ||
| "eap_type_display": "FULL EAP", | ||
| "country_name": "Test Country", | ||
| "national_society": "Test National Society", | ||
| "supporting_partners": [ | ||
| {"society_name": "Partner 1"}, | ||
| {"society_name": "Partner 2"}, | ||
| ], | ||
| "disaster_type": "Flood", | ||
| "ns_contact_name": "Test registration name", | ||
| "ns_contact_email": "[email protected]", | ||
| "ns_contact_phone": "1234567890", | ||
| }, | ||
| "submission": { | ||
| "eap_type_display": "SIMPLIFIED EAP", | ||
| "country_name": "Test Country", | ||
| "national_society": "Test National Society", | ||
| "people_targated": 100, | ||
| "supporting_partners": [ | ||
| {"society_name": "Partner NS 1"}, | ||
| {"society_name": "Partner NS 2"}, | ||
| ], | ||
| "disaster_type": "Flood", | ||
| "total_budget": "250,000 CHF", | ||
| "ns_contact_name": "Test Ns Contact name", | ||
| "ns_contact_email": "[email protected]", | ||
| "ns_contact_phone": "+977-9800000000", | ||
| }, | ||
| "feedback_to_national_society": { | ||
| "eap_type_display": "FULL EAP", | ||
| "country_name": "Test Country", | ||
| "national_society": "Test National Society", | ||
| }, | ||
| "resubmission_of_revised_eap": { | ||
| "eap_type_display": "SIMPLIFIED EAP", | ||
| "country_name": "Test Country", | ||
| "national_society": "Test National Society", | ||
| "supporting_partners": [ | ||
| {"society_name": "Partner NS 1"}, | ||
| {"society_name": "Partner NS 2"}, | ||
| ], | ||
| "version": 2 or 3, | ||
| "people_targated": 100, | ||
| "disaster_type": "Flood", | ||
| "total_budget": "250,000 CHF", | ||
| "ns_contact_name": "Test Ns Contact name", | ||
| "ns_contact_email": "[email protected]", | ||
| "ns_contact_phone": "+977-9800000000", | ||
| }, | ||
| "feedback_for_revised_eap": { | ||
| "eap_type_display": "FULL EAP", | ||
| "country_name": "Test Country", | ||
| "national_society": "Test National Society", | ||
| "version": 2, | ||
| }, | ||
| "technically_validated_eap": { | ||
| "eap_type_display": "FULL EAP", | ||
| "country_name": "Test Country", | ||
| "national_society": "Test National Society", | ||
| "disaster_type": "Flood", | ||
| }, | ||
| "pending_pfa": { | ||
| "eap_type_display": "FULL EAP", | ||
| "country_name": "Test Country", | ||
| "national_society": "Test National Society", | ||
| "disaster_type": "Flood", | ||
| }, | ||
| "approved_eap": { | ||
| "eap_type_display": "FULL EAP", | ||
| "country_name": "Test Country", | ||
| "national_society": "Test National Society", | ||
| "disaster_type": "Flood", | ||
| }, | ||
| "reminder": { | ||
| "eap_type_display": "FULL EAP", | ||
| "country_name": "Test Country", | ||
| "national_society": "Test National Society", | ||
| "disaster_type": "Flood", | ||
| }, | ||
| } | ||
|
|
||
| context = context_map.get(type_param) | ||
| if context is None: | ||
| return HttpResponse("No context found for the email preview.") | ||
| template_file = template_map[type_param] | ||
| template = loader.get_template(template_file) | ||
| return HttpResponse(template.render(context, request)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import logging | ||
|
|
||
| from celery import shared_task | ||
| from django.conf import settings | ||
| from django.contrib.auth import get_user_model | ||
| from django.template.loader import render_to_string | ||
|
|
||
| from eap.models import EAPRegistration | ||
| from eap.utils import ( | ||
| get_coordinator_emails_by_region, | ||
| get_eap_registration_email_context, | ||
| ) | ||
| from notifications.notification import send_notification | ||
|
|
||
| User = get_user_model() | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @shared_task | ||
| def send_new_eap_registration_email(eap_registration_id: int): | ||
|
|
||
| instance = EAPRegistration.objects.filter(id=eap_registration_id).first() | ||
| if not instance: | ||
| return None | ||
|
|
||
| regional_coordinator_emails: list[str] = get_coordinator_emails_by_region(instance.country.region) | ||
|
|
||
| recipients = [ | ||
| settings.EMAIL_EAP_DREF_ANTICIPATORY_PILLAR, | ||
| instance.ifrc_contact_email, | ||
| ] | ||
| cc_recipients = list( | ||
| set( | ||
| [ | ||
| instance.national_society_contact_email, | ||
| *settings.EMAIL_EAP_DREF_AA_GLOBAL_TEAM, | ||
| *regional_coordinator_emails, | ||
| ] | ||
| ) | ||
| ) | ||
| email_context = get_eap_registration_email_context(instance) | ||
| email_subject = ( | ||
| f"[{instance.get_eap_type_display() if instance.get_eap_type_display() else 'EAP'} IN DEVELOPMENT] " | ||
| f"{instance.country} {instance.disaster_type}" | ||
| ) | ||
| email_body = render_to_string("email/eap/registration.html", email_context) | ||
| email_type = "New EAP Registration" | ||
|
|
||
| send_notification( | ||
| subject=email_subject, | ||
| recipients=recipients, | ||
| html=email_body, | ||
| mailtype=email_type, | ||
| cc_recipients=cc_recipients, | ||
| ) | ||
|
|
||
| return email_context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,14 @@ | |
| EMAIL_USER=(str, None), | ||
| EMAIL_PASS=(str, None), | ||
| DEBUG_EMAIL=(bool, False), # This was 0/1 before | ||
| # EAP-EMAILS | ||
| EMAIL_EAP_DREF_ANTICIPATORY_PILLAR=(str, None), | ||
| EMAIL_EAP_DREF_AA_GLOBAL_TEAM=(list, None), | ||
| EMAIL_EAP_AFRICA_COORDINATORS=(list, None), | ||
| EMAIL_EAP_AMERICAS_COORDINATORS=(list, None), | ||
| EMAIL_EAP_ASIA_PACIFIC_COORDINATORS=(list, None), | ||
| EMAIL_EAP_EUROPE_COORDINATORS=(list, None), | ||
| EMAIL_EAP_MENA_COORDINATORS=(list, None), | ||
| # TEST_EMAILS=(list, ['[email protected]']), # maybe later | ||
| # Translation | ||
| # Translator Available: | ||
|
|
@@ -198,6 +206,7 @@ def parse_domain(*env_keys: str) -> str: | |
| ALLOWED_HOSTS = [ | ||
| "localhost", | ||
| "0.0.0.0", | ||
| "127.0.0.1", | ||
| urlparse(GO_API_URL).hostname, | ||
| *env("DJANGO_ADDITIONAL_ALLOWED_HOSTS"), | ||
| ] | ||
|
|
@@ -581,6 +590,15 @@ def parse_domain(*env_keys: str) -> str: | |
| DEBUG_EMAIL = env("DEBUG_EMAIL") | ||
| # TEST_EMAILS = env('TEST_EMAILS') # maybe later | ||
|
|
||
| # EAP-Email | ||
| EMAIL_EAP_DREF_ANTICIPATORY_PILLAR = env("EMAIL_EAP_DREF_ANTICIPATORY_PILLAR") | ||
| EMAIL_EAP_DREF_AA_GLOBAL_TEAM = env("EMAIL_EAP_DREF_AA_GLOBAL_TEAM") | ||
| EMAIL_EAP_AFRICA_COORDINATORS = env("EMAIL_EAP_AFRICA_COORDINATORS") | ||
| EMAIL_EAP_AMERICAS_COORDINATORS = env("EMAIL_EAP_AMERICAS_COORDINATORS") | ||
| EMAIL_EAP_ASIA_PACIFIC_COORDINATORS = env("EMAIL_EAP_ASIA_PACIFIC_COORDINATORS") | ||
| EMAIL_EAP_EUROPE_COORDINATORS = env("EMAIL_EAP_EUROPE_COORDINATORS") | ||
| EMAIL_EAP_MENA_COORDINATORS = env("EMAIL_EAP_MENA_COORDINATORS") | ||
|
|
||
| DATA_UPLOAD_MAX_MEMORY_SIZE = 104857600 # default 2621440, 2.5MB -> 100MB | ||
| # default 1000, was not enough for Mozambique Cyclone Idai data | ||
| # second 2000, was not enouch for Global COVID Emergency | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need

disaster_typefor this:and national society contacts for regards: