From 1efc38d9e86c17e9a4676d497e383bb6f27b729a Mon Sep 17 00:00:00 2001 From: Paulina Kujawa <42150286+pkujawa@users.noreply.github.com> Date: Tue, 14 May 2024 19:37:22 +0200 Subject: [PATCH] [Merge] Staging->Develop (#3866) * tweaks (#3856) * fix filtering by rdi * [200749] Add email sender settings (#3865) --------- Co-authored-by: Jan Romaniak Co-authored-by: Domenico Co-authored-by: Jan Romaniak --- .env.example | 7 +++++++ .../core/field_attributes/core_fields_attributes.py | 2 +- .../tests/test_individual_iban_xlsx_update.py | 2 +- .../tests/test_generate_dashboard_report_service.py | 2 +- .../tests/test_check_against_sanction_list_task.py | 2 +- backend/hct_mis_api/apps/utils/mailjet.py | 4 ++-- backend/hct_mis_api/config/fragments/mailjet.py | 2 ++ backend/hct_mis_api/conftest.py | 1 + backend/tests/apps/utils/test_mailjet.py | 10 +++++----- 9 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index 27f13aa2c0..9537ecc450 100644 --- a/.env.example +++ b/.env.example @@ -20,6 +20,13 @@ EMAIL_BACKEND="django.core.mail.backends.console.EmailBackend" EMAIL_HOST=TBD EMAIL_HOST_USER=TBD EMAIL_HOST_PASSWORD=TBD + +MAILJET_API_KEY= +MAILJET_SECRET_KEY= +CATCH_ALL_EMAIL= +DEFAULT_EMAIL_DISPLAY= +DEFAULT_EMAIL= + MAP_BOX_KEY=MAP_BOX_KEY_HERE DJANGO_ALLOWED_HOST=127.0.0.1 # Optional, defaults to localhost HCT_MIS_FRONTEND_HOST=127.0.0.1:8080 # Optional, defaults to DJANGO_ALLOWED_HOST diff --git a/backend/hct_mis_api/apps/core/field_attributes/core_fields_attributes.py b/backend/hct_mis_api/apps/core/field_attributes/core_fields_attributes.py index a962eea72b..7e9bb652cf 100644 --- a/backend/hct_mis_api/apps/core/field_attributes/core_fields_attributes.py +++ b/backend/hct_mis_api/apps/core/field_attributes/core_fields_attributes.py @@ -1602,7 +1602,7 @@ "choices": [], "associated_with": _HOUSEHOLD, "xlsx_field": "registration_data_import", - "scope": [Scope.TARGETING], + "scope": [Scope.TARGETING, Scope.XLSX_PEOPLE], }, { "id": "e4aa9cdf-2c9e-4e22-9928-2b63a6ea4ef0", diff --git a/backend/hct_mis_api/apps/household/tests/test_individual_iban_xlsx_update.py b/backend/hct_mis_api/apps/household/tests/test_individual_iban_xlsx_update.py index c1838c0742..6febb26826 100644 --- a/backend/hct_mis_api/apps/household/tests/test_individual_iban_xlsx_update.py +++ b/backend/hct_mis_api/apps/household/tests/test_individual_iban_xlsx_update.py @@ -265,7 +265,7 @@ def _get_expected_email_body(self, context: dict) -> str: { "Messages": [ { - "From": {"Email": settings.EMAIL_HOST_USER, "Name": settings.DEFAULT_FROM_EMAIL}, + "From": {"Email": settings.DEFAULT_EMAIL, "Name": settings.DEFAULT_EMAIL_DISPLAY}, "Subject": f"[test] Individual IBANs xlsx [{context['upload_file_id']}] update result", "To": [ { diff --git a/backend/hct_mis_api/apps/reporting/tests/test_generate_dashboard_report_service.py b/backend/hct_mis_api/apps/reporting/tests/test_generate_dashboard_report_service.py index a8653ad39e..eb965b3f9f 100644 --- a/backend/hct_mis_api/apps/reporting/tests/test_generate_dashboard_report_service.py +++ b/backend/hct_mis_api/apps/reporting/tests/test_generate_dashboard_report_service.py @@ -90,7 +90,7 @@ def test_email_body_for_generate_report(self, mocked_requests_post: Any) -> None { "Messages": [ { - "From": {"Email": settings.EMAIL_HOST_USER, "Name": settings.DEFAULT_FROM_EMAIL}, + "From": {"Email": settings.DEFAULT_EMAIL, "Name": settings.DEFAULT_EMAIL_DISPLAY}, "Subject": "[test] HOPE report generated", "To": [ { diff --git a/backend/hct_mis_api/apps/sanction_list/tests/test_check_against_sanction_list_task.py b/backend/hct_mis_api/apps/sanction_list/tests/test_check_against_sanction_list_task.py index 5b92315aa9..627dd5e360 100644 --- a/backend/hct_mis_api/apps/sanction_list/tests/test_check_against_sanction_list_task.py +++ b/backend/hct_mis_api/apps/sanction_list/tests/test_check_against_sanction_list_task.py @@ -86,7 +86,7 @@ def __getitem__(self, key: int) -> list: { "Messages": [ { - "From": {"Email": settings.EMAIL_HOST_USER, "Name": settings.DEFAULT_FROM_EMAIL}, + "From": {"Email": settings.DEFAULT_EMAIL, "Name": settings.DEFAULT_EMAIL_DISPLAY}, "Subject": f"[test] {subject}", "To": [{"Email": "test_email@email.com"}], "Cc": [{"Email": settings.SANCTION_LIST_CC_MAIL}], diff --git a/backend/hct_mis_api/apps/utils/mailjet.py b/backend/hct_mis_api/apps/utils/mailjet.py index 8733848631..78ce602381 100644 --- a/backend/hct_mis_api/apps/utils/mailjet.py +++ b/backend/hct_mis_api/apps/utils/mailjet.py @@ -32,8 +32,8 @@ def __init__( self.recipients = settings.CATCH_ALL_EMAIL if settings.CATCH_ALL_EMAIL else recipients self.ccs = ccs or [] self.variables = variables - self.from_email = from_email or settings.EMAIL_HOST_USER - self.from_email_display = from_email_display or settings.DEFAULT_FROM_EMAIL + self.from_email = from_email or settings.DEFAULT_EMAIL + self.from_email_display = from_email_display or settings.DEFAULT_EMAIL_DISPLAY self.attachments = [] def _validate_email_data(self) -> None: diff --git a/backend/hct_mis_api/config/fragments/mailjet.py b/backend/hct_mis_api/config/fragments/mailjet.py index 612e87bc6c..a70c6b2fa3 100644 --- a/backend/hct_mis_api/config/fragments/mailjet.py +++ b/backend/hct_mis_api/config/fragments/mailjet.py @@ -3,3 +3,5 @@ MAILJET_API_KEY = env("MAILJET_API_KEY") MAILJET_SECRET_KEY = env("MAILJET_SECRET_KEY") CATCH_ALL_EMAIL = env.list("CATCH_ALL_EMAIL", default=[]) +DEFAULT_EMAIL_DISPLAY = env("DEFAULT_EMAIL_DISPLAY", default="") +DEFAULT_EMAIL = env("DEFAULT_EMAIL", default="") diff --git a/backend/hct_mis_api/conftest.py b/backend/hct_mis_api/conftest.py index 761e1a1d3c..a6bcf0aff6 100644 --- a/backend/hct_mis_api/conftest.py +++ b/backend/hct_mis_api/conftest.py @@ -33,6 +33,7 @@ def pytest_configure(config: Config) -> None: settings.ELASTICSEARCH_INDEX_PREFIX = "test_" settings.EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" settings.CATCH_ALL_EMAIL = [] + settings.DEFAULT_EMAIL = "testemail@email.com" settings.EXCHANGE_RATE_CACHE_EXPIRY = 0 settings.USE_DUMMY_EXCHANGE_RATES = True diff --git a/backend/tests/apps/utils/test_mailjet.py b/backend/tests/apps/utils/test_mailjet.py index ec7af49ff9..c613fc0acf 100644 --- a/backend/tests/apps/utils/test_mailjet.py +++ b/backend/tests/apps/utils/test_mailjet.py @@ -33,7 +33,7 @@ def test_mailjet_body_with_template(self, mocked_requests_post: Any) -> None: { "Messages": [ { - "From": {"Email": settings.EMAIL_HOST_USER, "Name": settings.DEFAULT_FROM_EMAIL}, + "From": {"Email": settings.DEFAULT_EMAIL, "Name": settings.DEFAULT_EMAIL_DISPLAY}, "Subject": "[test] Subject for email with Template", "To": [ { @@ -81,7 +81,7 @@ def test_mailjet_body_with_template_with_catch_all(self, mocked_requests_post: A { "Messages": [ { - "From": {"Email": settings.EMAIL_HOST_USER, "Name": settings.DEFAULT_FROM_EMAIL}, + "From": {"Email": settings.DEFAULT_EMAIL, "Name": settings.DEFAULT_EMAIL_DISPLAY}, "Subject": "[test] Subject for email with Template for Catch All", "To": [ { @@ -127,7 +127,7 @@ def test_mailjet_body_with_html_and_text_body(self, mocked_requests_post: Any) - { "Messages": [ { - "From": {"Email": settings.EMAIL_HOST_USER, "Name": settings.DEFAULT_FROM_EMAIL}, + "From": {"Email": settings.DEFAULT_EMAIL, "Name": settings.DEFAULT_EMAIL_DISPLAY}, "Subject": "[test] Subject for email with HTML and Text body", "To": [ { @@ -171,7 +171,7 @@ def test_mailjet_body_with_text_body(self, mocked_requests_post: Any) -> None: { "Messages": [ { - "From": {"Email": settings.EMAIL_HOST_USER, "Name": settings.DEFAULT_FROM_EMAIL}, + "From": {"Email": settings.DEFAULT_EMAIL, "Name": settings.DEFAULT_EMAIL_DISPLAY}, "Subject": "[test] Subject for email with Text body", "To": [ { @@ -238,7 +238,7 @@ def test_mailjet_body_with_template_and_attachment(self, mocked_requests_post: A { "Messages": [ { - "From": {"Email": settings.EMAIL_HOST_USER, "Name": settings.DEFAULT_FROM_EMAIL}, + "From": {"Email": settings.DEFAULT_EMAIL, "Name": settings.DEFAULT_EMAIL_DISPLAY}, "Subject": "[test] Subject for email with Template and Attachments", "To": [ {