Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable_won_emails #1662

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ MRAS_SVC_API_KEY=

# Local development only
DISABLE_NAMEREQUEST_SOLR_UPDATES=1

# launchdarkly
NAMEX_LD_SDK_ID=sdk-075200eb-4ff7-4e0e-872a-848585d3d460
2 changes: 1 addition & 1 deletion api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ db: ## Update the local database
.DEFAULT_GOAL := help

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
24 changes: 2 additions & 22 deletions api/namex/resources/name_requests/report_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ def _get_template_data(nr_model):
nr_report_json['applicants']['countryName'] = \
pycountry.countries.search_fuzzy(nr_report_json['applicants']['countryTypeCd'])[0].name
actions_obj = ReportResource._get_next_action_text(nr_model['entity_type_cd'])
structured_log(request, "DEBUG", f"NR_notification - NameX API: {actions_obj}")
current_app.logger.debug(f"NR_notification - NameX API: {actions_obj}")
structured_log(request, "DEBUG", f"NR_notification - NameX API: {nr_report_json['request_action_cd']}")
current_app.logger.debug(f"NR_notification - NameX API: {nr_report_json['request_action_cd']}")
structured_log(request, "DEBUG", f"NR_notification - NameX API: {nr_model['entity_type_cd']}")
current_app.logger.debug(f"NR_notification - NameX API: {nr_model['entity_type_cd']}")
if actions_obj:
action_text = actions_obj.get(nr_report_json['request_action_cd'])
if not action_text:
Expand Down Expand Up @@ -283,7 +277,7 @@ def _is_modernized(legal_type):

@staticmethod
def _is_colin(legal_type):
colin_list = ['XCR', 'XUL', 'RLC']
colin_list = ['CR', 'UL', 'CC', 'XCR', 'XUL', 'RLC']
return legal_type in colin_list

@staticmethod
Expand All @@ -292,24 +286,13 @@ def _is_society(legal_type):
return legal_type in society_list

@staticmethod
def _is_potential_colin(legal_type):
potential_colin_list = ['CR', 'UL', 'CC']
return legal_type in potential_colin_list

@staticmethod
def _get_instruction_group(legal_type, request_action, corpNum):
if request_action == RequestAction.CHG.value or RequestAction.CNV.value:
# For the 'Name Change' or 'Alteration', return 'modernized' if the company is in LEAR, and 'colin' if not
return 'modernized' if ReportResource._is_lear_entity(corpNum) else 'colin'
def _get_instruction_group(legal_type):
if ReportResource._is_modernized(legal_type):
return 'modernized'
if ReportResource._is_colin(legal_type):
return 'colin'
if ReportResource._is_society(legal_type):
return 'so'
# return "new" for BC/CC/ULC IAs, "colin" for for BC/CC/ULC others
if ReportResource._is_potential_colin(legal_type):
return 'new' if request_action == RequestAction.NEW.value else 'colin'
return ''

@staticmethod
Expand Down Expand Up @@ -388,12 +371,10 @@ def _get_next_action_text(entity_type_cd: str):
next_action_text = {
# BC Types
'CR': {
'NEW': 'Check your email for instructions on how to complete your application using this name request.',
'DEFAULT': f'Use this name request to complete your application by visiting <a href="{url}">'
f'{url}</a>'
},
'UL': {
'NEW': 'Check your email for instructions on how to complete your application using this name request.',
'DEFAULT': f'Use this name request to complete your application by visiting <a href="{url}">'
f'{url}</a>'
},
Expand Down Expand Up @@ -436,7 +417,6 @@ def _get_next_action_text(entity_type_cd: str):
'DEFAULT': f'Use this name request to complete your application by visiting <a href="{url}">{url}</a>'
},
'CC': {
'NEW': 'Check your email for instructions on how to complete your application using this name request.',
'DEFAULT': f'Use this name request to complete your application by visiting <a href="{url}">'
f'{url}</a>'
},
Expand Down
3 changes: 2 additions & 1 deletion services/emailer/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
DASHBOARD_URL=
AUTH_WEB_URL=
BUSINESS_REGISTRY_URL=


NAMEX_LD_SDK_ID=sdk-075200eb-4ff7-4e0e-872a-848585d3d460
6 changes: 3 additions & 3 deletions services/emailer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Config: # pylint: disable=too-few-public-methods

ENVIRONMENT = os.getenv("APP_ENV", "prod")

LD_SDK_KEY = os.getenv("LD_SDK_KEY", None)
NAMEX_LD_SDK_ID = os.getenv("NAMEX_LD_SDK_ID", None)

SENTRY_DSN = os.getenv("SENTRY_DSN", None)

Expand All @@ -90,8 +90,8 @@ class Config: # pylint: disable=too-few-public-methods
NOTIFY_API_VERSION = os.getenv("NOTIFY_API_VERSION", "")
NAMEX_API_URL = os.getenv("NAMEX_API_URL", "")
NAMEX_API_VERSION = os.getenv("NAMEX_API_VERSION", "")
LEGAL_API_URL = os.getenv("NOTIFY_API_URL", "https://legal-api-dev.apps.silver.devops.gov.bc.ca")
LEGAL_API_VERSION = os.getenv("NOTIFY_API_VERSION", "/api/v2")
LEGAL_API_URL = os.getenv("LEGAL_API_URL", "https://legal-api-dev.apps.silver.devops.gov.bc.ca")
LEGAL_API_VERSION = os.getenv("LEGAL_API_VERSION", "/api/v1")

NOTIFY_API_URL = f"{NOTIFY_API_URL + NOTIFY_API_VERSION}/notify"
NAMEX_SVC_URL = f"{NAMEX_API_URL + NAMEX_API_VERSION}"
Expand Down
6 changes: 6 additions & 0 deletions services/emailer/devops/vault.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@
"auth-web",
"business-registry-ui"
]
},
{
"vault": "launchdarkly",
"application": [
"namex"
]
}
]
2 changes: 2 additions & 0 deletions services/emailer/devops/vaults.gcp.env
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ BUSINESS_REGISTRY_URL="op://web-url/$APP_ENV/business-registry-ui/BUSINESS_REGIS
REPORT_API_URL="op://API/$APP_ENV/report-api/REPORT_API_URL"
REPORT_API_VERSION="op://API/$APP_ENV/report-api/REPORT_API_VERSION"
LEGAL_API_URL="op://API/$APP_ENV/legal-api/LEGAL_API_URL"
LEGAL_API_VERSION="op://API/$APP_ENV/legal-api/LEGAL_API_VERSION"
NAMEX_LD_SDK_ID="op://launchdarkly/$APP_ENV/namex/NAMEX_LD_SDK_ID"
SENTRY_DSN=""
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from namex.constants import RequestAction
from namex.resources.name_requests import ReportResource
from namex_emailer.email_processors import substitute_template_parts
from namex_emailer.services.helpers import as_legislation_timezone, format_as_report_string, get_magic_link, query_nr_number, get_instruction_group
from namex_emailer.services.helpers import as_legislation_timezone, format_as_report_string, get_magic_link, query_nr_number

class Option(Enum):
"""NR notification option."""
Expand Down Expand Up @@ -89,9 +89,7 @@ def process(email_info: SimpleCloudEvent, option) -> dict: # pylint: disable-ms
legal_type = nr_data["entity_type_cd"]
request_action = nr_data["request_action_cd"]
corpNum = nr_data["corpNum"]
# This function will be restred after the emailer service and NameX API are sync well.
# group = ReportResource._get_instruction_group(legal_type, request_action, corpNum)
group = get_instruction_group(legal_type, request_action, corpNum)
group = ReportResource._get_instruction_group(legal_type, request_action, corpNum)
if group:
instruction_group = "-" + group
file_name_suffix += instruction_group.upper()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from simple_cloudevent import SimpleCloudEvent
from datetime import datetime

from namex_emailer.services.helpers import get_magic_link, query_nr_number, get_instruction_group
from namex_emailer.services.helpers import get_magic_link, query_nr_number

RESULT_EMAIL_SUBJECT = 'Name Request Results from Corporate Registry'
CONSENT_EMAIL_SUBJECT = 'Consent Received by Corporate Registry'
Expand Down Expand Up @@ -50,11 +50,7 @@ def email_consent_letter(email_info: SimpleCloudEvent):
template_path = current_app.config.get('REPORT_TEMPLATE_PATH')
file_name = 'consent'
legal_type = nr_model['entity_type_cd']
request_action = nr_model["request_action_cd"]
corpNum = nr_model["corpNum"]
# This function will be restred after the emailer service and NameX API are sync well.
# instruction_group = ReportResource._get_instruction_group(legal_type, request_action, corpNum)
instruction_group = get_instruction_group(legal_type, request_action, corpNum)
instruction_group = ReportResource._get_instruction_group(legal_type)
if instruction_group:
file_name = f"{file_name}-{instruction_group}"
email_template = Path(f'{template_path}/{file_name}.md').read_text()
Expand Down Expand Up @@ -102,12 +98,7 @@ def email_report(email_info: SimpleCloudEvent):
email_template = Path(f'{template_path}/rejected.md').read_text()
if nr_model['stateCd'] in [State.APPROVED, State.CONDITIONAL]:
legal_type = nr_model['entity_type_cd']
request_action = nr_model["request_action_cd"]
corpNum = nr_model["corpNum"]
# This function will be restred after the emailer service and NameX API are sync well.
# instruction_group = ReportResource._get_instruction_group(legal_type, request_action, corpNum)
instruction_group = get_instruction_group(legal_type, request_action, corpNum)
structured_log(request, "DEBUG", f"NR_notification: {instruction_group}")
instruction_group = ReportResource._get_instruction_group(legal_type)
file_name=''
if nr_model['consentFlag'] in ['Y', 'R']:
file_name = 'conditional'
Expand All @@ -120,7 +111,6 @@ def email_report(email_info: SimpleCloudEvent):

email_template = Path(f'{template_path}/{file_name}.md').read_text()

structured_log(request, "DEBUG", f"NR_notification: {nr_model}")
email_body = _build_email_body(email_template, nr_model, recipient_emails[0], recipient_phones[0])

email = {
Expand Down Expand Up @@ -163,4 +153,4 @@ def _build_email_body(template: str, nr_model, email, phone):
if isinstance(val, datetime):
val = val.strftime(DATE_FORMAT)
template = template.replace(template_string, val)
return template
return template
44 changes: 4 additions & 40 deletions services/emailer/src/namex_emailer/services/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import pytz
import requests
from flask import current_app
from http import HTTPStatus
from flask import current_app, request
from gcp_queue.logging import structured_log
from cachetools import cached, TTLCache
from urllib.parse import urlencode
from namex.constants import RequestAction
from namex.resources.name_requests import ReportResource

@staticmethod
@cached(cache=TTLCache(maxsize=1, ttl=180))
Expand Down Expand Up @@ -70,41 +72,3 @@ def get_magic_link(nr_number, email, phone):
}
encoded_params = urlencode(params)
return f'{BUSINESS_REGISTRY_URL}incorporateNow/?{encoded_params}'


@staticmethod
def _is_lear_entity(corpNum):
if not corpNum:
return False
entity_url = f'{current_app.config.get("ENTITY_SVC_URL")}/businesses/{corpNum}'
token = get_bearer_token()
response = requests.get(entity_url, headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
})

return response


# This function will be removed if the emailer service and NameX API are in sync well
@staticmethod
def get_instruction_group(legal_type, request_action, corpNum):
legal_type_groups = {
'modernized': ['GP', 'DBA', 'FR', 'CP', 'BC'],
'colin': ['XCR', 'XUL', 'RLC'],
'society': ['SO', 'XSO'],
'potential_colin': ['CR', 'UL', 'CC']
}

if request_action in {RequestAction.CHG.value, RequestAction.CNV.value}:
return 'modernized' if _is_lear_entity(corpNum) else 'colin'
if legal_type in legal_type_groups['modernized']:
return 'modernized'
if legal_type in legal_type_groups['colin']:
return 'colin'
if legal_type in legal_type_groups['society']:
return 'so'
if legal_type in legal_type_groups['potential_colin']:
return 'new' if request_action == RequestAction.NEW.value else 'colin'

return ''
Loading