diff --git a/auth-api/src/auth_api/services/products.py b/auth-api/src/auth_api/services/products.py index 8f84954ff..98e37d426 100644 --- a/auth-api/src/auth_api/services/products.py +++ b/auth-api/src/auth_api/services/products.py @@ -149,7 +149,7 @@ def resubmit_product_subscription(org_id, subscription_data: dict[str, Any], ski Product._send_product_subscription_confirmation( ProductNotificationInfo( - product_model=product_model, product_sub_model=existing_sub, is_confirmation=True + product_model=product_model, product_sub_model=existing_sub, is_confirmation=True, org_id=org_id ), org.id, ) @@ -257,7 +257,7 @@ def create_product_subscription( ) Product._send_product_subscription_confirmation( ProductNotificationInfo( - product_model=product_model, product_sub_model=product_subscription, is_confirmation=True + product_model=product_model, product_sub_model=product_subscription, is_confirmation=True, org_id=org.id ), org.id, ) @@ -573,6 +573,7 @@ def approve_reject_parent_subscription( product_model=product_model, product_sub_model=product_subscription, is_reapproved=is_reapproved, + org_id=org_id ) ) else: diff --git a/auth-api/src/auth_api/utils/notifications.py b/auth-api/src/auth_api/utils/notifications.py index 02dc8fa40..b46143d75 100644 --- a/auth-api/src/auth_api/utils/notifications.py +++ b/auth-api/src/auth_api/utils/notifications.py @@ -115,20 +115,19 @@ def get_product_notification_data(product_notification_info: ProductNotification is_confirmation = product_notification_info.is_confirmation subscription_status_code = product_notification_info.product_sub_model.status_code remarks = product_notification_info.remarks - + org_id = product_notification_info.org_id if product_model.code not in DETAILED_MHR_NOTIFICATIONS: - org_id = product_notification_info.org_id org_name = product_notification_info.org_name return get_default_product_notification_data(product_model, recipient_emails, org_id, org_name) if is_confirmation: - return get_mhr_qs_confirmation_data(product_model, recipient_emails) + return get_mhr_qs_confirmation_data(product_model, recipient_emails, org_id) if is_reapproved or subscription_status_code == ProductSubscriptionStatus.ACTIVE.value: - return get_mhr_qs_approval_data(product_model, recipient_emails, is_reapproved) + return get_mhr_qs_approval_data(product_model, recipient_emails, org_id, is_reapproved) if subscription_status_code == ProductSubscriptionStatus.REJECTED.value: - return get_mhr_qs_rejected_data(product_model, recipient_emails, remarks) + return get_mhr_qs_rejected_data(product_model, recipient_emails, org_id, remarks) return None @@ -144,7 +143,7 @@ def get_default_product_notification_data(product_model: ProductCodeModel, recip return data -def get_mhr_qs_approval_data(product_model: ProductCodeModel, recipient_emails: str, is_reapproved: bool = False): +def get_mhr_qs_approval_data(product_model: ProductCodeModel, recipient_emails: str, org_id: int, is_reapproved: bool = False): """Get the mhr qualified supplier product approval notification data.""" data = { "subjectDescriptor": ProductSubjectDescriptor.MHR_QUALIFIED_SUPPLIER.value, @@ -153,11 +152,12 @@ def get_mhr_qs_approval_data(product_model: ProductCodeModel, recipient_emails: "isReapproved": is_reapproved, "productName": product_model.description, "emailAddresses": recipient_emails, + "accountId": org_id } return data -def get_mhr_qs_rejected_data(product_model: ProductCodeModel, recipient_emails: str, reject_reason: str = None): +def get_mhr_qs_rejected_data(product_model: ProductCodeModel, recipient_emails: str, org_id: int, reject_reason: str = None): """Get the mhr qualified supplier product rejected notification data.""" data = { "subjectDescriptor": ProductSubjectDescriptor.MHR_QUALIFIED_SUPPLIER.value, @@ -168,11 +168,12 @@ def get_mhr_qs_rejected_data(product_model: ProductCodeModel, recipient_emails: "emailAddresses": recipient_emails, "remarks": reject_reason, "contactType": get_notification_contact_type(product_model.code), + "accountId": org_id } return data -def get_mhr_qs_confirmation_data(product_model: ProductCodeModel, recipient_emails: str): +def get_mhr_qs_confirmation_data(product_model: ProductCodeModel, recipient_emails: str, org_id: int): """Get the mhr qualified supplier product confirmation notification data.""" data = { "subjectDescriptor": ProductSubjectDescriptor.MHR_QUALIFIED_SUPPLIER.value, @@ -183,6 +184,7 @@ def get_mhr_qs_confirmation_data(product_model: ProductCodeModel, recipient_emai "contactType": get_notification_contact_type(product_model.code), "hasAgreementAttachment": True, "attachmentType": NotificationAttachmentType.MHR_QS.value, + "accountId": org_id } return data diff --git a/auth-api/tests/unit/services/test_product_notifications.py b/auth-api/tests/unit/services/test_product_notifications.py index 721d17f32..b37c6cade 100644 --- a/auth-api/tests/unit/services/test_product_notifications.py +++ b/auth-api/tests/unit/services/test_product_notifications.py @@ -254,6 +254,7 @@ def test_detailed_approved_notification(mock_mailer, session, auth_mock, keycloa "isReapproved": False, "productName": product_code_model.description, "emailAddresses": "test@test.com", + "accountId": dictionary["id"], } mock_mailer.assert_called_with( QueueMessageTypes.PRODUCT_APPROVED_NOTIFICATION_DETAILED.value, data=expected_data @@ -345,6 +346,7 @@ def test_detailed_rejected_notification( "emailAddresses": "test@test.com", "contactType": contact_type, "remarks": task_dict["remarks"][0], + "accountId": dictionary["id"], } mock_mailer.assert_called_with( QueueMessageTypes.PRODUCT_REJECTED_NOTIFICATION_DETAILED.value, data=expected_data @@ -479,6 +481,7 @@ def test_confirmation_notification( "contactType": contact_type, "hasAgreementAttachment": True, "attachmentType": NotificationAttachmentType.MHR_QS.value, + "accountId": dictionary["id"], } mock_mailer.assert_called_with(QueueMessageTypes.PRODUCT_CONFIRMATION_NOTIFICATION.value, data=expected_data) @@ -606,6 +609,7 @@ def test_resubmission_notification( "contactType": contact_type, "hasAgreementAttachment": True, "attachmentType": NotificationAttachmentType.MHR_QS.value, + "accountId": dictionary["id"], } # Assert that confirmation email is re-sent on re-submission @@ -639,6 +643,7 @@ def test_resubmission_notification( "isReapproved": True, "productName": product_code_model.description, "emailAddresses": "test@test.com", + "accountId": dictionary["id"], } mock_mailer.assert_called_with( QueueMessageTypes.PRODUCT_APPROVED_NOTIFICATION_DETAILED.value, data=expected_data diff --git a/queue_services/account-mailer/src/account_mailer/email_processors/account_unlock.py b/queue_services/account-mailer/src/account_mailer/email_processors/account_unlock.py index 15661ad0b..e22d98220 100644 --- a/queue_services/account-mailer/src/account_mailer/email_processors/account_unlock.py +++ b/queue_services/account-mailer/src/account_mailer/email_processors/account_unlock.py @@ -17,6 +17,7 @@ from jinja2 import Template from account_mailer.email_processors import generate_template +from account_mailer.email_processors.utils import get_account_info from account_mailer.pdf_utils import get_pdf_from_report_api @@ -42,10 +43,16 @@ def process(data: dict, token: str) -> dict: } -def _get_account_unlock_email(email_msg): - filled_template = generate_template(current_app.config.get("TEMPLATE_PATH"), email_msg.get("template_name")) +def _get_account_unlock_email(data): + org_id = data.get("accountId") + _, account_name_with_branch = get_account_info(org_id) + filled_template = generate_template(current_app.config.get("TEMPLATE_PATH"), data.get("template_name")) jnja_template = Template(filled_template, autoescape=True) - html_out = jnja_template.render(account_name=email_msg.get("account_name"), logo_url=email_msg.get("logo_url")) + html_out = jnja_template.render( + logo_url=data.get("logo_url"), + account_name_with_branch=account_name_with_branch, + account_number=org_id, + ) return html_out diff --git a/queue_services/account-mailer/src/account_mailer/email_processors/common_mailer.py b/queue_services/account-mailer/src/account_mailer/email_processors/common_mailer.py index d84b2a044..2676e8d5c 100644 --- a/queue_services/account-mailer/src/account_mailer/email_processors/common_mailer.py +++ b/queue_services/account-mailer/src/account_mailer/email_processors/common_mailer.py @@ -13,29 +13,20 @@ # limitations under the License. """A Template for the account suspended email.""" -# Local application imports -from auth_api.models import Org as OrgModel - # Third-party imports from flask import current_app from jinja2 import Template from account_mailer.auth_utils import get_dashboard_url, get_login_url, get_payment_statements_url from account_mailer.email_processors import generate_template +from account_mailer.email_processors.utils import get_account_info def process(org_id, recipients, template_name, subject, logo_url, **kwargs) -> dict: """Build the email for Account notification.""" - current_app.logger.debug("account notification: %s", org_id) - - account_name: str = None - account_name_with_branch: str = None - if org_id: - org: OrgModel = OrgModel.find_by_id(org_id) - account_name = org.name - account_name_with_branch = org.name - if org.branch_name: - account_name_with_branch = f"{org.name} - {org.branch_name}" + current_app.logger.debug("account notification: %s", org_id) + + account_name, account_name_with_branch = get_account_info(org_id) # fill in template filled_template = generate_template(current_app.config.get("TEMPLATE_PATH"), template_name) diff --git a/queue_services/account-mailer/src/account_mailer/email_processors/pad_confirmation.py b/queue_services/account-mailer/src/account_mailer/email_processors/pad_confirmation.py index 80e4427f3..79a2d6c1a 100644 --- a/queue_services/account-mailer/src/account_mailer/email_processors/pad_confirmation.py +++ b/queue_services/account-mailer/src/account_mailer/email_processors/pad_confirmation.py @@ -22,20 +22,20 @@ from jinja2 import Template from account_mailer.email_processors import generate_template +from account_mailer.email_processors.utils import get_account_info from account_mailer.pdf_utils import get_pdf_from_report_api, get_pdf_from_storage -def process(email_msg: dict, token: str) -> dict: +def process(email_msg: dict, org_id: str, token: str) -> dict: """Build the email for PAD Confirmation notification.""" current_app.logger.debug("email_msg notification: %s", email_msg) - # fill in template - + _, account_name_with_branch = get_account_info(org_id) username = email_msg.get("padTosAcceptedBy") pad_tos_file_name = current_app.config["PAD_TOS_FILE"] admin_emails, admin_name = _get_admin_emails(username) pdf_attachment = _get_pad_confirmation_report_pdf(email_msg, token) tos_attachment = _get_pdf(pad_tos_file_name) - html_body = _get_pad_confirmation_email_body(email_msg, admin_name) + html_body = _get_pad_confirmation_email_body(email_msg, admin_name, account_name_with_branch, org_id) return { "recipients": admin_emails, "content": { @@ -73,11 +73,17 @@ def _get_admin_emails(username): return admin_emails, admin_name -def _get_pad_confirmation_email_body(email_msg, admin_name): +def _get_pad_confirmation_email_body(email_msg, admin_name, account_name_with_branch, account_number): filled_template = generate_template(current_app.config.get("TEMPLATE_PATH"), "pad_confirmation_email") # render template with vars from email msg jnja_template = Template(filled_template, autoescape=True) - html_out = jnja_template.render(request=email_msg, admin_name=admin_name, logo_url=email_msg.get("logo_url")) + html_out = jnja_template.render( + request=email_msg, + admin_name=admin_name, + logo_url=email_msg.get("logo_url"), + account_name_with_branch=account_name_with_branch, + account_number=account_number, + ) return html_out diff --git a/queue_services/account-mailer/src/account_mailer/email_processors/utils.py b/queue_services/account-mailer/src/account_mailer/email_processors/utils.py new file mode 100644 index 000000000..45917ec5e --- /dev/null +++ b/queue_services/account-mailer/src/account_mailer/email_processors/utils.py @@ -0,0 +1,28 @@ +# Copyright © 2019 Province of British Columbia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Utility functions for email processors.""" + +from auth_api.models import Org as OrgModel + + +def get_account_info(org_id: int | None) -> tuple[str | None, str | None]: + """Get account name and account name with branch for an org.""" + if not org_id: + return None, None + org = OrgModel.find_by_id(org_id) + account_name = org.name + account_name_with_branch = org.name + if org.branch_name: + account_name_with_branch = f"{org.name} - {org.branch_name}" + return account_name, account_name_with_branch diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/creditcard_refund_request_email.html b/queue_services/account-mailer/src/account_mailer/email_templates/creditcard_refund_request_email.html deleted file mode 100644 index e0f8b1523..000000000 --- a/queue_services/account-mailer/src/account_mailer/email_templates/creditcard_refund_request_email.html +++ /dev/null @@ -1,13 +0,0 @@ -Please complete a refund for the following transaction: - -Order Number: {{ refund_data.orderNumber }} -Transaction Date & Time: {{ refund_data.transactionDateTime }} -Transaction Amount: {{ refund_data.transactionAmount }} -Transaction ID: {{ refund_data.transactionId }} - -These documents are also available on the [Business Dashboard]({{ entity_dashboard_url }}). - - -Toll Free: 1-877-526-1526 -Victoria Office: 250-387-7848 -Email: [BCRegistries@gov.bc.ca](BCRegistries@gov.bc.ca) diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_over_payment.html b/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_over_payment.html index 8eada2ab1..17185ff63 100644 --- a/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_over_payment.html +++ b/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_over_payment.html @@ -1 +1,3 @@ +Account: {{ account_name_with_branch }} (Account Number: {{ account_number }}) + We have received payment in the amount of ${{ paid_amount }}. Payment received over the outstanding balance has been applied as a credit to your account and will be applied to future purchases. \ No newline at end of file diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_payment.html b/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_payment.html index 7380df9a9..614d27a30 100644 --- a/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_payment.html +++ b/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_payment.html @@ -1 +1,3 @@ +Account: {{ account_name_with_branch }} (Account Number: {{ account_number }}) + We have received payment in the amount of ${{ paid_amount }} and your products are now available. \ No newline at end of file diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_under_payment.html b/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_under_payment.html index f961fc387..a0efbb111 100644 --- a/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_under_payment.html +++ b/queue_services/account-mailer/src/account_mailer/email_templates/online_banking_under_payment.html @@ -1 +1,3 @@ +Account: {{ account_name_with_branch }} (Account Number: {{ account_number }}) + We have received payment in the amount of ${{ paid_amount }}. Please pay the outstanding balance to access your products. \ No newline at end of file diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/pad_confirmation_email.html b/queue_services/account-mailer/src/account_mailer/email_templates/pad_confirmation_email.html index 96ff43967..60c0ca908 100644 --- a/queue_services/account-mailer/src/account_mailer/email_templates/pad_confirmation_email.html +++ b/queue_services/account-mailer/src/account_mailer/email_templates/pad_confirmation_email.html @@ -1,3 +1,5 @@ +Account: {{ account_name_with_branch }} (Account Number: {{ account_number }}) + Please find attached your **Confirmation Letter of Pre-Authorized Debit (PAD) Sign-up** and a copy of your **Business Pre-Authorized Debit Terms and Conditions Agreement** with BC Registries and Online Services. If you have questions, please contact the BC Online Partnership Office. Contact details are included in your confirmation letter. diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/pad_setup_failed.html b/queue_services/account-mailer/src/account_mailer/email_templates/pad_setup_failed.html index a91f78279..e77ded3c6 100644 --- a/queue_services/account-mailer/src/account_mailer/email_templates/pad_setup_failed.html +++ b/queue_services/account-mailer/src/account_mailer/email_templates/pad_setup_failed.html @@ -1,3 +1,5 @@ +Account: {{ account_name_with_branch }} (Account Number: {{ account_number }}) + When you setup pre-authorized debit, the bank information you entered was invalid. To unlock your account, please review and update your bank information. diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/product_approved_notification_detailed.html b/queue_services/account-mailer/src/account_mailer/email_templates/product_approved_notification_detailed.html index 70bca4ded..cc3712529 100644 --- a/queue_services/account-mailer/src/account_mailer/email_templates/product_approved_notification_detailed.html +++ b/queue_services/account-mailer/src/account_mailer/email_templates/product_approved_notification_detailed.html @@ -1,3 +1,5 @@ +Account: {{ account_name_with_branch }} (Account Number: {{ account_number }}) + # You've been approved for {{ product_access_descriptor }} access to {{ category_descriptor }}. {% if is_reapproved %} diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/product_confirmation_notification.html b/queue_services/account-mailer/src/account_mailer/email_templates/product_confirmation_notification.html index b216f71d9..e6684277f 100644 --- a/queue_services/account-mailer/src/account_mailer/email_templates/product_confirmation_notification.html +++ b/queue_services/account-mailer/src/account_mailer/email_templates/product_confirmation_notification.html @@ -1,3 +1,5 @@ +Account: {{ account_name_with_branch }} (Account Number: {{ account_number }}) + # Your application for {{ product_access_descriptor }} access to {{ category_descriptor }} has been received. BC Registries staff have received your application to have **{{ product_name }}** access to {{ category_descriptor }}, and your request is under review. diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/resubmit_bceid_admin.html b/queue_services/account-mailer/src/account_mailer/email_templates/resubmit_bceid_admin.html index 512a6370d..702813534 100644 --- a/queue_services/account-mailer/src/account_mailer/email_templates/resubmit_bceid_admin.html +++ b/queue_services/account-mailer/src/account_mailer/email_templates/resubmit_bceid_admin.html @@ -1,3 +1,5 @@ +Account: {{ account_name_with_branch }} (Account Number: {{ account_number }}) + # Your Team Member Request is On hold. Thank you for your interest with BC Registries and Online Services. Our office was attempting to approve your application sent on {{ applicationDate }} but, had to place your account creation request on hold for the following reason(s): diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/resubmit_bceid_org.html b/queue_services/account-mailer/src/account_mailer/email_templates/resubmit_bceid_org.html index 2380399ce..c1f578094 100644 --- a/queue_services/account-mailer/src/account_mailer/email_templates/resubmit_bceid_org.html +++ b/queue_services/account-mailer/src/account_mailer/email_templates/resubmit_bceid_org.html @@ -1,3 +1,5 @@ +Account: {{ account_name_with_branch }} (Account Number: {{ account_number }}) + # Your Account Creation Request is On hold. Thank you for your interest with BC Registries and Online Services. Our office was attempting to approve your application sent on {{ applicationDate }} but, had to place your account creation request on hold for the following reason(s): diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/staff_review_account_email.html b/queue_services/account-mailer/src/account_mailer/email_templates/staff_review_account_email.html deleted file mode 100644 index 89cebf9b3..000000000 --- a/queue_services/account-mailer/src/account_mailer/email_templates/staff_review_account_email.html +++ /dev/null @@ -1,3 +0,0 @@ -# **{{ user_first_name }} {{ user_last_name }}** has submitted a request that requires your approval. You will need to log in using your IDIR to approve this request. - -[Review Account]({{ context_url }}) diff --git a/queue_services/account-mailer/src/account_mailer/enums.py b/queue_services/account-mailer/src/account_mailer/enums.py index d8ce3bc6b..43e72efea 100644 --- a/queue_services/account-mailer/src/account_mailer/enums.py +++ b/queue_services/account-mailer/src/account_mailer/enums.py @@ -151,7 +151,6 @@ class TemplateType(Enum): NON_BCSC_ORG_REJECTED_NOTIFICATION_TEMPLATE_NAME = "nonbcsc_org_rejected_notification_email" OTP_AUTHENTICATOR_RESET_NOTIFICATION_TEMPLATE_NAME = "otp_authenticator_reset_notification_email" ROLE_CHANGED_NOTIFICATION_TEMPLATE_NAME = "role_changed_notification_email" - STAFF_REVIEW_ACCOUNT_TEMPLATE_NAME = "staff_review_account_email" GOVM_APPROVED_NOTIFICATION_TEMPLATE_NAME = "govm_approved_notification" GOVM_REJECTED_NOTIFICATION_TEMPLATE_NAME = "govm_rejected_notification" PROD_PACKAGE_APPROVED_NOTIFICATION_TEMPLATE_NAME = "prod_package_approved_notification" diff --git a/queue_services/account-mailer/src/account_mailer/resources/worker.py b/queue_services/account-mailer/src/account_mailer/resources/worker.py index dc3322332..5d3f64f87 100644 --- a/queue_services/account-mailer/src/account_mailer/resources/worker.py +++ b/queue_services/account-mailer/src/account_mailer/resources/worker.py @@ -107,7 +107,8 @@ def handle_pad_account_create(message_type, email_msg): return email_msg["registry_logo_url"] = google_store.GoogleStoreService.get_static_resource_url("bc_registry_logo_pdf.svg") token = RestService.get_service_account_token() - email_dict = pad_confirmation.process(email_msg, token) + org_id = email_msg.get("accountId") + email_dict = pad_confirmation.process(email_msg, org_id, token) process_email(email_dict, token) @@ -397,7 +398,7 @@ def handle_product_actions(message_type, email_msg): attachment_type = email_msg.get("attachmentType", None) email_dict = common_mailer.process( **{ - "org_id": email_msg.get("orgId", None), + "org_id": email_msg.get("accountId"), "recipients": email_msg.get("emailAddresses"), "template_name": TemplateType[f"{QueueMessageTypes(message_type).name}_TEMPLATE_NAME"].value, "subject": subject_type.format(subject_descriptor=subject_descriptor),