-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
17528 - Qualified supplier confirmation email (#2538)
* 17528 - Qualified Supplier Email - Confirmation * PDF attachment fix
- Loading branch information
Showing
9 changed files
with
240 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -30,7 +30,8 @@ | |
from auth_api.services.user import User as UserService | ||
from auth_api.utils.enums import ( | ||
LoginSource, NotificationTypes, TaskAction, TaskRelationshipStatus, TaskRelationshipType, TaskStatus) | ||
from auth_api.utils.notifications import ProductAccessDescriptor, ProductCategoryDescriptor, ProductSubjectDescriptor | ||
from auth_api.utils.notifications import ( | ||
NotificationAttachmentType, ProductAccessDescriptor, ProductCategoryDescriptor, ProductSubjectDescriptor) | ||
from tests.utilities.factory_scenarios import TestJwtClaims, TestOrgInfo, TestOrgProductsInfo, TestUserInfo | ||
from tests.utilities.factory_utils import factory_user_model_with_contact, patch_token_info | ||
|
||
|
@@ -347,7 +348,7 @@ def test_detailed_rejected_notification(mock_mailer, session, auth_mock, keycloa | |
]) | ||
@patch.object(auth_api.services.products, 'publish_to_mailer') | ||
def test_hold_notification(mock_mailer, session, auth_mock, keycloak_mock, monkeypatch, org_product_info): | ||
"""Assert product approved notification with details is created.""" | ||
"""Assert product notification is not created for on hold state.""" | ||
user_with_token = TestUserInfo.user_bceid_tester | ||
user_with_token['keycloak_guid'] = TestJwtClaims.public_bceid_user['sub'] | ||
user_with_token['idp_userid'] = TestJwtClaims.public_bceid_user['idp_userid'] | ||
|
@@ -400,7 +401,7 @@ def test_hold_notification(mock_mailer, session, auth_mock, keycloak_mock, monke | |
assert task.relationship_id == org_prod_sub.id | ||
assert task.action == TaskAction.QUALIFIED_SUPPLIER_REVIEW.value | ||
|
||
# Approve task and check for publish to mailer | ||
# Hold task and check publish to mailer is not called | ||
task_info = { | ||
'relationshipStatus': TaskRelationshipStatus.PENDING_STAFF_REVIEW.value, | ||
'status': TaskStatus.HOLD.value | ||
|
@@ -409,3 +410,91 @@ def test_hold_notification(mock_mailer, session, auth_mock, keycloak_mock, monke | |
with patch.object(UserService, 'get_admin_emails_for_org', return_value='[email protected]'): | ||
TaskService.update_task(TaskService(task), task_info=task_info) | ||
mock_mailer.assert_not_called | ||
|
||
|
||
@pytest.mark.parametrize('org_product_info, contact_type', [ | ||
(TestOrgProductsInfo.mhr_qs_lawyer_and_notaries, 'BCOL'), | ||
(TestOrgProductsInfo.mhr_qs_home_manufacturers, 'BCREG'), | ||
(TestOrgProductsInfo.mhr_qs_home_dealers, 'BCREG') | ||
]) | ||
@patch.object(auth_api.services.products, 'publish_to_mailer') | ||
def test_confirmation_notification(mock_mailer, session, auth_mock, keycloak_mock, | ||
monkeypatch, org_product_info, contact_type): | ||
"""Assert product confirmation notification is properly created.""" | ||
user_with_token = TestUserInfo.user_bceid_tester | ||
user_with_token['keycloak_guid'] = TestJwtClaims.public_bceid_user['sub'] | ||
user_with_token['idp_userid'] = TestJwtClaims.public_bceid_user['idp_userid'] | ||
user = factory_user_model_with_contact(user_with_token) | ||
|
||
patch_token_info(TestJwtClaims.public_bceid_user, monkeypatch) | ||
|
||
org = OrgService.create_org(TestOrgInfo.org_premium, user_id=user.id) | ||
assert org | ||
dictionary = org.as_dict() | ||
assert dictionary['name'] == TestOrgInfo.org_premium['name'] | ||
|
||
product_code = org_product_info['subscriptions'][0]['productCode'] | ||
product_code_model = ProductCodeModel.find_by_code(product_code) | ||
|
||
if product_code_model.parent_code: | ||
# Create parent product subscription | ||
ProductService.create_product_subscription(org_id=dictionary['id'], | ||
subscription_data={'subscriptions': [ | ||
{'productCode': product_code_model.parent_code}]}, | ||
skip_auth=True) | ||
|
||
with patch.object(UserService, 'get_admin_emails_for_org', return_value='[email protected]'): | ||
# Subscribe to product | ||
ProductService.create_product_subscription(org_id=dictionary['id'], | ||
subscription_data=org_product_info, | ||
skip_auth=True) | ||
|
||
expected_data = { | ||
'subjectDescriptor': ProductSubjectDescriptor.MHR_QUALIFIED_SUPPLIER.value, | ||
'productAccessDescriptor': ProductAccessDescriptor.MHR_QUALIFIED_SUPPLIER.value, | ||
'categoryDescriptor': ProductCategoryDescriptor.MHR.value, | ||
'productName': product_code_model.description, | ||
'emailAddresses': '[email protected]', | ||
'contactType': contact_type, | ||
'hasAgreementAttachment': True, | ||
'attachmentType': NotificationAttachmentType.MHR_QS.value | ||
} | ||
|
||
mock_mailer.assert_called_with(NotificationTypes.DETAILED_CONFIRMATION_PRODUCT.value, | ||
data=expected_data) | ||
|
||
|
||
@pytest.mark.parametrize('org_product_info', [ | ||
TestOrgProductsInfo.org_products_vs | ||
]) | ||
@patch.object(auth_api.services.products, 'publish_to_mailer') | ||
def test_no_confirmation_notification(mock_mailer, session, auth_mock, keycloak_mock, monkeypatch, org_product_info): | ||
"""Assert product confirmation notification not created.""" | ||
user_with_token = TestUserInfo.user_bceid_tester | ||
user_with_token['keycloak_guid'] = TestJwtClaims.public_bceid_user['sub'] | ||
user_with_token['idp_userid'] = TestJwtClaims.public_bceid_user['idp_userid'] | ||
user = factory_user_model_with_contact(user_with_token) | ||
|
||
patch_token_info(TestJwtClaims.public_bceid_user, monkeypatch) | ||
|
||
org = OrgService.create_org(TestOrgInfo.org_premium, user_id=user.id) | ||
assert org | ||
dictionary = org.as_dict() | ||
assert dictionary['name'] == TestOrgInfo.org_premium['name'] | ||
|
||
product_code = org_product_info['subscriptions'][0]['productCode'] | ||
product_code_model = ProductCodeModel.find_by_code(product_code) | ||
|
||
if product_code_model.parent_code: | ||
# Create parent product subscription | ||
ProductService.create_product_subscription(org_id=dictionary['id'], | ||
subscription_data={'subscriptions': [ | ||
{'productCode': product_code_model.parent_code}]}, | ||
skip_auth=True) | ||
|
||
with patch.object(UserService, 'get_admin_emails_for_org', return_value='[email protected]'): | ||
# Subscribe to product | ||
ProductService.create_product_subscription(org_id=dictionary['id'], | ||
subscription_data=org_product_info, | ||
skip_auth=True) | ||
mock_mailer.assert_not_called() |
This file contains 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
61 changes: 61 additions & 0 deletions
61
queue_services/account-mailer/src/account_mailer/email_processors/product_confirmation.py
This file contains 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,61 @@ | ||
# Copyright © 2023 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. | ||
"""A processor for the product confirmation email.""" | ||
|
||
import base64 | ||
|
||
from flask import current_app | ||
|
||
from account_mailer.enums import AttachmentTypes | ||
from account_mailer.services import minio_service | ||
|
||
|
||
def process_attachment(email_dict: dict, attachment_type: str) -> dict: | ||
"""Process any attachments for a product confirmation notification.""" | ||
if attachment_type is None: | ||
return email_dict | ||
|
||
attachment_name = _get_attachment_name(attachment_type) | ||
|
||
if attachment_name is None: | ||
return email_dict | ||
|
||
pdf_attachment = _get_pdf(attachment_name) | ||
email_dict['content']['attachments'] = [ | ||
{ | ||
'fileName': attachment_name, | ||
'fileBytes': pdf_attachment.decode('utf-8'), | ||
'fileUrl': '', | ||
'attachOrder': '1' | ||
} | ||
] | ||
|
||
return email_dict | ||
|
||
|
||
def _get_attachment_name(attachment_type: str) -> str: | ||
if attachment_type == AttachmentTypes.QUALIFIED_SUPPLIER.value: | ||
return current_app.config['MHR_QS_AGREEMENT_FILE'] | ||
|
||
return None | ||
|
||
|
||
def _get_pdf(file_name: str): | ||
read_pdf = None | ||
mino_object = minio_service.MinioService.get_minio_file(current_app.config['MINIO_BUCKET'], | ||
file_name) | ||
if mino_object: | ||
read_pdf = base64.b64encode(mino_object.data) | ||
|
||
return read_pdf |
15 changes: 15 additions & 0 deletions
15
.../account-mailer/src/account_mailer/email_templates/product_confirmation_notification.html
This file contains 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,15 @@ | ||
# 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. | ||
|
||
{% if has_agreement_attachment %} | ||
Please find a copy of the {{ product_access_descriptor }} Agreement attached for your records. | ||
{% endif %} | ||
|
||
You will be notified by email once your application has been reviewed. | ||
|
||
{% if contact_type == 'BCOL' %} | ||
Please contact BC OnLine at 1-800-663-6102 or email [email protected] to discuss further actions. | ||
{% else %} | ||
Please contact BC Registries at 1-877-526-1526 or email [email protected] to discuss further actions. | ||
{% endif %} |
This file contains 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.