Skip to content

Commit 93ce6be

Browse files
authored
21361 - Add BCROS acct number to all correspondence, emails, and notifications (#3593)
1 parent 885ef24 commit 93ce6be

20 files changed

+93
-51
lines changed

auth-api/src/auth_api/services/products.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def resubmit_product_subscription(org_id, subscription_data: dict[str, Any], ski
149149

150150
Product._send_product_subscription_confirmation(
151151
ProductNotificationInfo(
152-
product_model=product_model, product_sub_model=existing_sub, is_confirmation=True
152+
product_model=product_model, product_sub_model=existing_sub, is_confirmation=True, org_id=org_id
153153
),
154154
org.id,
155155
)
@@ -257,7 +257,7 @@ def create_product_subscription(
257257
)
258258
Product._send_product_subscription_confirmation(
259259
ProductNotificationInfo(
260-
product_model=product_model, product_sub_model=product_subscription, is_confirmation=True
260+
product_model=product_model, product_sub_model=product_subscription, is_confirmation=True, org_id=org.id
261261
),
262262
org.id,
263263
)
@@ -576,6 +576,7 @@ def approve_reject_parent_subscription(
576576
product_model=product_model,
577577
product_sub_model=product_subscription,
578578
is_reapproved=is_reapproved,
579+
org_id=org_id
579580
)
580581
)
581582
else:

auth-api/src/auth_api/utils/notifications.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,19 @@ def get_product_notification_data(product_notification_info: ProductNotification
115115
is_confirmation = product_notification_info.is_confirmation
116116
subscription_status_code = product_notification_info.product_sub_model.status_code
117117
remarks = product_notification_info.remarks
118-
118+
org_id = product_notification_info.org_id
119119
if product_model.code not in DETAILED_MHR_NOTIFICATIONS:
120-
org_id = product_notification_info.org_id
121120
org_name = product_notification_info.org_name
122121
return get_default_product_notification_data(product_model, recipient_emails, org_id, org_name)
123122

124123
if is_confirmation:
125-
return get_mhr_qs_confirmation_data(product_model, recipient_emails)
124+
return get_mhr_qs_confirmation_data(product_model, recipient_emails, org_id)
126125

127126
if is_reapproved or subscription_status_code == ProductSubscriptionStatus.ACTIVE.value:
128-
return get_mhr_qs_approval_data(product_model, recipient_emails, is_reapproved)
127+
return get_mhr_qs_approval_data(product_model, recipient_emails, org_id, is_reapproved)
129128

130129
if subscription_status_code == ProductSubscriptionStatus.REJECTED.value:
131-
return get_mhr_qs_rejected_data(product_model, recipient_emails, remarks)
130+
return get_mhr_qs_rejected_data(product_model, recipient_emails, org_id, remarks)
132131

133132
return None
134133

@@ -144,7 +143,7 @@ def get_default_product_notification_data(product_model: ProductCodeModel, recip
144143
return data
145144

146145

147-
def get_mhr_qs_approval_data(product_model: ProductCodeModel, recipient_emails: str, is_reapproved: bool = False):
146+
def get_mhr_qs_approval_data(product_model: ProductCodeModel, recipient_emails: str, org_id: int, is_reapproved: bool = False):
148147
"""Get the mhr qualified supplier product approval notification data."""
149148
data = {
150149
"subjectDescriptor": ProductSubjectDescriptor.MHR_QUALIFIED_SUPPLIER.value,
@@ -153,11 +152,12 @@ def get_mhr_qs_approval_data(product_model: ProductCodeModel, recipient_emails:
153152
"isReapproved": is_reapproved,
154153
"productName": product_model.description,
155154
"emailAddresses": recipient_emails,
155+
"accountId": org_id
156156
}
157157
return data
158158

159159

160-
def get_mhr_qs_rejected_data(product_model: ProductCodeModel, recipient_emails: str, reject_reason: str = None):
160+
def get_mhr_qs_rejected_data(product_model: ProductCodeModel, recipient_emails: str, org_id: int, reject_reason: str = None):
161161
"""Get the mhr qualified supplier product rejected notification data."""
162162
data = {
163163
"subjectDescriptor": ProductSubjectDescriptor.MHR_QUALIFIED_SUPPLIER.value,
@@ -168,11 +168,12 @@ def get_mhr_qs_rejected_data(product_model: ProductCodeModel, recipient_emails:
168168
"emailAddresses": recipient_emails,
169169
"remarks": reject_reason,
170170
"contactType": get_notification_contact_type(product_model.code),
171+
"accountId": org_id
171172
}
172173
return data
173174

174175

175-
def get_mhr_qs_confirmation_data(product_model: ProductCodeModel, recipient_emails: str):
176+
def get_mhr_qs_confirmation_data(product_model: ProductCodeModel, recipient_emails: str, org_id: int):
176177
"""Get the mhr qualified supplier product confirmation notification data."""
177178
data = {
178179
"subjectDescriptor": ProductSubjectDescriptor.MHR_QUALIFIED_SUPPLIER.value,
@@ -183,6 +184,7 @@ def get_mhr_qs_confirmation_data(product_model: ProductCodeModel, recipient_emai
183184
"contactType": get_notification_contact_type(product_model.code),
184185
"hasAgreementAttachment": True,
185186
"attachmentType": NotificationAttachmentType.MHR_QS.value,
187+
"accountId": org_id
186188
}
187189
return data
188190

auth-api/tests/unit/services/test_product_notifications.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ def test_detailed_approved_notification(mock_mailer, session, auth_mock, keycloa
254254
"isReapproved": False,
255255
"productName": product_code_model.description,
256256
"emailAddresses": "test@test.com",
257+
"accountId": dictionary["id"],
257258
}
258259
mock_mailer.assert_called_with(
259260
QueueMessageTypes.PRODUCT_APPROVED_NOTIFICATION_DETAILED.value, data=expected_data
@@ -345,6 +346,7 @@ def test_detailed_rejected_notification(
345346
"emailAddresses": "test@test.com",
346347
"contactType": contact_type,
347348
"remarks": task_dict["remarks"][0],
349+
"accountId": dictionary["id"],
348350
}
349351
mock_mailer.assert_called_with(
350352
QueueMessageTypes.PRODUCT_REJECTED_NOTIFICATION_DETAILED.value, data=expected_data
@@ -479,6 +481,7 @@ def test_confirmation_notification(
479481
"contactType": contact_type,
480482
"hasAgreementAttachment": True,
481483
"attachmentType": NotificationAttachmentType.MHR_QS.value,
484+
"accountId": dictionary["id"],
482485
}
483486

484487
mock_mailer.assert_called_with(QueueMessageTypes.PRODUCT_CONFIRMATION_NOTIFICATION.value, data=expected_data)
@@ -606,6 +609,7 @@ def test_resubmission_notification(
606609
"contactType": contact_type,
607610
"hasAgreementAttachment": True,
608611
"attachmentType": NotificationAttachmentType.MHR_QS.value,
612+
"accountId": dictionary["id"],
609613
}
610614

611615
# Assert that confirmation email is re-sent on re-submission
@@ -639,6 +643,7 @@ def test_resubmission_notification(
639643
"isReapproved": True,
640644
"productName": product_code_model.description,
641645
"emailAddresses": "test@test.com",
646+
"accountId": dictionary["id"],
642647
}
643648
mock_mailer.assert_called_with(
644649
QueueMessageTypes.PRODUCT_APPROVED_NOTIFICATION_DETAILED.value, data=expected_data

queue_services/account-mailer/src/account_mailer/email_processors/account_unlock.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from jinja2 import Template
1818

1919
from account_mailer.email_processors import generate_template
20+
from account_mailer.email_processors.utils import get_account_info
2021
from account_mailer.pdf_utils import get_pdf_from_report_api
2122

2223

@@ -42,10 +43,16 @@ def process(data: dict, token: str) -> dict:
4243
}
4344

4445

45-
def _get_account_unlock_email(email_msg):
46-
filled_template = generate_template(current_app.config.get("TEMPLATE_PATH"), email_msg.get("template_name"))
46+
def _get_account_unlock_email(data):
47+
org_id = data.get("accountId")
48+
_, account_name_with_branch = get_account_info(org_id)
49+
filled_template = generate_template(current_app.config.get("TEMPLATE_PATH"), data.get("template_name"))
4750
jnja_template = Template(filled_template, autoescape=True)
48-
html_out = jnja_template.render(account_name=email_msg.get("account_name"), logo_url=email_msg.get("logo_url"))
51+
html_out = jnja_template.render(
52+
logo_url=data.get("logo_url"),
53+
account_name_with_branch=account_name_with_branch,
54+
account_number=org_id,
55+
)
4956
return html_out
5057

5158

queue_services/account-mailer/src/account_mailer/email_processors/common_mailer.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,20 @@
1313
# limitations under the License.
1414
"""A Template for the account suspended email."""
1515

16-
# Local application imports
17-
from auth_api.models import Org as OrgModel
18-
1916
# Third-party imports
2017
from flask import current_app
2118
from jinja2 import Template
2219

2320
from account_mailer.auth_utils import get_dashboard_url, get_login_url, get_payment_statements_url
2421
from account_mailer.email_processors import generate_template
22+
from account_mailer.email_processors.utils import get_account_info
2523

2624

2725
def process(org_id, recipients, template_name, subject, logo_url, **kwargs) -> dict:
2826
"""Build the email for Account notification."""
29-
current_app.logger.debug("account notification: %s", org_id)
30-
31-
account_name: str = None
32-
account_name_with_branch: str = None
33-
if org_id:
34-
org: OrgModel = OrgModel.find_by_id(org_id)
35-
account_name = org.name
36-
account_name_with_branch = org.name
37-
if org.branch_name:
38-
account_name_with_branch = f"{org.name} - {org.branch_name}"
27+
current_app.logger.debug("account notification: %s", org_id)
28+
29+
account_name, account_name_with_branch = get_account_info(org_id)
3930

4031
# fill in template
4132
filled_template = generate_template(current_app.config.get("TEMPLATE_PATH"), template_name)

queue_services/account-mailer/src/account_mailer/email_processors/pad_confirmation.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
from jinja2 import Template
2323

2424
from account_mailer.email_processors import generate_template
25+
from account_mailer.email_processors.utils import get_account_info
2526
from account_mailer.pdf_utils import get_pdf_from_report_api, get_pdf_from_storage
2627

2728

28-
def process(email_msg: dict, token: str) -> dict:
29+
def process(email_msg: dict, org_id: str, token: str) -> dict:
2930
"""Build the email for PAD Confirmation notification."""
3031
current_app.logger.debug("email_msg notification: %s", email_msg)
31-
# fill in template
32-
32+
_, account_name_with_branch = get_account_info(org_id)
3333
username = email_msg.get("padTosAcceptedBy")
3434
pad_tos_file_name = current_app.config["PAD_TOS_FILE"]
3535
admin_emails, admin_name = _get_admin_emails(username)
3636
pdf_attachment = _get_pad_confirmation_report_pdf(email_msg, token)
3737
tos_attachment = _get_pdf(pad_tos_file_name)
38-
html_body = _get_pad_confirmation_email_body(email_msg, admin_name)
38+
html_body = _get_pad_confirmation_email_body(email_msg, admin_name, account_name_with_branch, org_id)
3939
return {
4040
"recipients": admin_emails,
4141
"content": {
@@ -73,11 +73,17 @@ def _get_admin_emails(username):
7373
return admin_emails, admin_name
7474

7575

76-
def _get_pad_confirmation_email_body(email_msg, admin_name):
76+
def _get_pad_confirmation_email_body(email_msg, admin_name, account_name_with_branch, account_number):
7777
filled_template = generate_template(current_app.config.get("TEMPLATE_PATH"), "pad_confirmation_email")
7878
# render template with vars from email msg
7979
jnja_template = Template(filled_template, autoescape=True)
80-
html_out = jnja_template.render(request=email_msg, admin_name=admin_name, logo_url=email_msg.get("logo_url"))
80+
html_out = jnja_template.render(
81+
request=email_msg,
82+
admin_name=admin_name,
83+
logo_url=email_msg.get("logo_url"),
84+
account_name_with_branch=account_name_with_branch,
85+
account_number=account_number,
86+
)
8187
return html_out
8288

8389

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright © 2019 Province of British Columbia
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Utility functions for email processors."""
15+
16+
from auth_api.models import Org as OrgModel
17+
18+
19+
def get_account_info(org_id: int | None) -> tuple[str | None, str | None]:
20+
"""Get account name and account name with branch for an org."""
21+
if not org_id:
22+
return None, None
23+
org = OrgModel.find_by_id(org_id)
24+
account_name = org.name
25+
account_name_with_branch = org.name
26+
if org.branch_name:
27+
account_name_with_branch = f"{org.name} - {org.branch_name}"
28+
return account_name, account_name_with_branch

queue_services/account-mailer/src/account_mailer/email_templates/creditcard_refund_request_email.html

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
Account: {{ account_name_with_branch }} (Account Number: {{ account_number }})
2+
13
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.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
Account: {{ account_name_with_branch }} (Account Number: {{ account_number }})
2+
13
We have received payment in the amount of ${{ paid_amount }} and your products are now available.

0 commit comments

Comments
 (0)