Skip to content

Commit

Permalink
20087 - Mailer changes for suspension (#2851)
Browse files Browse the repository at this point in the history
* Mailer changes for suspension

* lint fix

* alphabetical

* repoint at correct branch

* point at branch
  • Loading branch information
seeker25 authored Jun 6, 2024
1 parent 46fdf55 commit 9936065
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 16 deletions.
3 changes: 2 additions & 1 deletion auth-api/src/auth_api/utils/account_mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
from simple_cloudevent import SimpleCloudEvent

from auth_api.services.gcp_queue import GcpQueue, queue
from auth_api.utils.enums import QueueSources


def publish_to_mailer(notification_type, data=None, source='sbc-auth-auth-api'):
def publish_to_mailer(notification_type, data=None, source=QueueSources.AUTH_API.value):
"""Publish to Account Mailer."""
cloud_event = SimpleCloudEvent(
id=str(uuid.uuid4()),
Expand Down
7 changes: 7 additions & 0 deletions auth-api/src/auth_api/utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,10 @@ class NRActionCodes(Enum):
RENEW = 'REN' # restore with new name request
RESTORATION = 'REST' # FUTURE: unused? delete?
RESUBMIT = 'RESUBMIT' # FUTURE: unused? delete?


class QueueSources(Enum):
"""Queue sources for PAY."""

AUTH_API = 'auth-api'
AUTH_QUEUE = 'auth-queue'
2 changes: 1 addition & 1 deletion queue_services/account-mailer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ tornado==6.4
urllib3==2.2.1
zipp==3.19.0
-e git+https://github.com/bcgov/sbc-common-components.git#egg=sbc-common-components&subdirectory=python
-e git+https://github.com/seeker25/sbc-auth.git@refactor_queues#egg=auth-api&subdirectory=auth-api
-e git+https://github.com/seeker25/sbc-auth.git@20087#egg=auth-api&subdirectory=auth-api
-e git+https://github.com/seeker25/sbc-connect-common.git@small_tweaks#egg=gcp-queue&subdirectory=python/gcp-queue
git+https://github.com/daxiom/simple-cloudevent.py.git
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@ def process(org_id, recipients, template_name, subject, logo_url, **kwargs) -> d
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}'

# fill in template
filled_template = generate_template(current_app.config.get('TEMPLATE_PATH'), template_name)
# render template with vars from email msg
jnja_template = Template(filled_template, autoescape=True)
jinja_kwargs = {
'account_name': account_name,
'account_name_with_branch': account_name_with_branch,
'account_number': org_id,
'url': get_login_url(),
'logo_url': logo_url,
'dashboard_url': get_dashboard_url(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Your BC Registries and Online Services account has been suspended.
# Account suspended for {{ account_number }} - {{ account_name_with_branch }}

The following account has been suspended due to a failed payment.

{{ account_name }}
Your account has been suspended due to a failed or overdue payment(s).

Log in to BC Registries and Online Services to reactivate your account.

[Log in]({{ url }})
[Log in]({{ url }})

**Business Registry**
BC Registries and Online Services
Toll Free: [1-877-526-1526](1-877-526-1526)
Victoria Office: [250-387-7848](250-387-7848)
Email: [[email protected]]([email protected])

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Account Unlocked

Your account **{{ account_name }}** has been unlocked. Team members can now log in and access this account.
Your account **{{ account_name_with_branch }}** has been unlocked. Team members can now log in and access this account.

Your receipt is attached to this email:

**Business Registry**
BC Registries and Online Services
Toll Free: [1-877-370-1033](1-877-370-1033)
Victoria Office: [250-370-1033](250-370-1033)
Toll Free: [1-877-526-1526](1-877-526-1526)
Victoria Office: [250-387-7848](250-387-7848)
Email: [[email protected]]([email protected])
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def handle_eft_available_notification(message_type, email_msg):
def handle_nsf_lock_unlock_account(message_type, email_msg):
"""Handle the NSF lock/unlock account message."""
if message_type == QueueMessageTypes.NSF_LOCK_ACCOUNT.value:
current_app.logger.debug('lock account message recieved:')
current_app.logger.debug('Lock account message received')
template_name = TemplateType.NSF_LOCK_ACCOUNT_TEMPLATE_NAME.value
org_id = email_msg.get('accountId')
admin_coordinator_emails = get_member_emails(org_id, (ADMIN, COORDINATOR))
Expand All @@ -136,7 +136,7 @@ def handle_nsf_lock_unlock_account(message_type, email_msg):
subject, logo_url=logo_url)
process_email(email_dict)
elif message_type == QueueMessageTypes.NSF_UNLOCK_ACCOUNT.value:
current_app.logger.debug('unlock account message received')
current_app.logger.debug('Unlock account message received')
template_name = TemplateType.NSF_UNLOCK_ACCOUNT_TEMPLATE_NAME.value
org_id = email_msg.get('accountId')
admin_coordinator_emails = get_member_emails(org_id, (ADMIN, COORDINATOR))
Expand Down
2 changes: 1 addition & 1 deletion queue_services/auth-queue/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ tornado==6.4
urllib3==2.2.1
zipp==3.19.0
-e git+https://github.com/bcgov/sbc-common-components.git#egg=sbc-common-components&subdirectory=python
-e git+https://github.com/seeker25/sbc-auth.git@refactor_queues#egg=auth-api&subdirectory=auth-api
-e git+https://github.com/seeker25/sbc-auth.git@20087#egg=auth-api&subdirectory=auth-api
-e git+https://github.com/seeker25/sbc-connect-common.git@small_tweaks#egg=gcp-queue&subdirectory=python/gcp-queue
git+https://github.com/daxiom/simple-cloudevent.py.git
6 changes: 3 additions & 3 deletions queue_services/auth-queue/src/auth_queue/resources/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from auth_api.services.gcp_queue.gcp_auth import ensure_authorized_queue_user
from auth_api.services.rest_service import RestService
from auth_api.utils.account_mailer import publish_to_mailer
from auth_api.utils.enums import AccessType, ActivityAction, CorpType, OrgStatus
from auth_api.utils.enums import AccessType, ActivityAction, CorpType, OrgStatus, QueueSources
from dateutil import parser
from flask import Blueprint, current_app, request
from sbc_common_components.utils.enums import QueueMessageTypes
Expand Down Expand Up @@ -115,11 +115,11 @@ def process_pay_lock_unlock_event(event_message: SimpleCloudEvent):
org.status_code = OrgStatus.NSF_SUSPENDED.value
org.suspended_on = datetime.now()
org.suspension_reason_code = queue_data.get('suspensionReasonCode', None)
publish_to_mailer(QueueMessageTypes.NSF_LOCK_ACCOUNT.value, data)
publish_to_mailer(QueueMessageTypes.NSF_LOCK_ACCOUNT.value, data, QueueSources.AUTH_QUEUE.value)
elif message_type == QueueMessageTypes.NSF_UNLOCK_ACCOUNT.value:
org.status_code = OrgStatus.ACTIVE.value
org.suspension_reason_code = None
publish_to_mailer(QueueMessageTypes.NSF_UNLOCK_ACCOUNT.value, data)
publish_to_mailer(QueueMessageTypes.NSF_UNLOCK_ACCOUNT.value, data, QueueSources.AUTH_QUEUE.value)

org.flush()
db.session.commit()
Expand Down

0 comments on commit 9936065

Please sign in to comment.