Skip to content

Commit

Permalink
NRO Decommissioning: Allow user to modify cancel from legacy side#25224
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Chen <steven.chen@gov.bc.ca>
  • Loading branch information
stevenc987 committed Jan 11, 2025
2 parents 76223e4 + e650f96 commit 5f0dff3
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 93 deletions.
3 changes: 2 additions & 1 deletion api/namex/VERSION.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__version__ = '1.2.21b'
__version__ = '1.2.21c'

32 changes: 4 additions & 28 deletions api/namex/resources/name_requests/report_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ def _get_template_data(nr_model):
nr_report_json['legalAct'] = ReportResource._get_legal_act(nr_model['entity_type_cd'])
isXPRO = nr_model['entity_type_cd'] in ['XCR', 'XUL', 'RLC', 'XLP', 'XLL', 'XCP', 'XSO']
nr_report_json['isXPRO'] = isXPRO
instruction_group = ReportResource._get_instruction_group(nr_model['entity_type_cd'], nr_model['request_action_cd'], nr_model['corpNum'])
instruction_group = ReportResource._get_instruction_group(nr_model['entity_type_cd'])
nr_report_json['isModernized'] = True if instruction_group == 'modernized' else False
nr_report_json['isColin'] = True if instruction_group == 'colin' else False
nr_report_json['isSociety'] = True if instruction_group == 'so' else False
nr_report_json['isNew'] = True if instruction_group == 'new' else False
nr_report_json['isPaper'] = not (ReportResource._is_colin(nr_model['entity_type_cd']) or ReportResource._is_modernized(nr_model['entity_type_cd']) or ReportResource._is_society(nr_model['entity_type_cd']) or ReportResource._is_potential_colin(nr_model['entity_type_cd']))
nr_report_json['isPaper'] = not (ReportResource._is_colin(nr_model['entity_type_cd']) or ReportResource._is_modernized(nr_model['entity_type_cd']) or ReportResource._is_society(nr_model['entity_type_cd']))
nr_report_json['requestCodeDescription'] = \
ReportResource._get_request_action_cd_description(nr_report_json['request_action_cd'])
nr_report_json['nrStateDescription'] = \
Expand Down Expand Up @@ -266,15 +265,6 @@ def _get_entity_type_description(entity_type_cd: str):
}
return entity_type_descriptions.get(entity_type_cd, None)

@staticmethod
def _is_lear_entity(corpNum):
if not corpNum:
return False
entity_url = f'{current_app.config.get("ENTITY_SVC_URL")}/businesses/{corpNum}'
response = EntityUtils.make_authenticated_request(entity_url)
if response.status_code == HTTPStatus.OK and response.json():
return True
return False

@staticmethod
def _is_modernized(legal_type):
Expand All @@ -283,7 +273,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 +282,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 +367,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 +413,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
4 changes: 4 additions & 0 deletions api/namex/resources/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,10 @@ def put(nr, *args, **kwargs):

try:
user = get_or_create_user_by_jwt(g.jwt_oidc_token_info)

current_app.logger.debug(f"User found!")
nrd = RequestDAO.find_by_nr(nr)
current_app.logger.debug(f"nrd found!")
if not nrd:
return make_response(jsonify({"message": "Request:{} not found".format(nr)}), 404)
orig_nrd = nrd.json()
Expand All @@ -728,6 +731,7 @@ def put(nr, *args, **kwargs):
current_app.logger.error("Error when patching NR:{0} Err:{1}".format(nr, err))
return make_response(jsonify({"message": "NR had an internal error"}), 404)

current_app.logger.debug(f"Before valid_state_transition")
if not valid_state_transition(user, nrd, state):
return make_response(jsonify(message='you are not authorized to make these changes'), 401)

Expand Down
2 changes: 2 additions & 0 deletions api/namex/services/name_request/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ def valid_state_transition(user, nr, new_state):
"""
# when the legacy user just created a new NR from legacy side, the user should be allowed to
# modify and cancel it from the legacy side (while the NR still in DRAFT state).
current_app.logger.debug(f"inside valid_state_transition")
if nr.stateCd == State.DRAFT and (new_state == State.DRAFT or new_state == State.CANCELLED):
return True

current_app.logger.debug(f"inside valid_state_transition continue")
if (new_state in (State.APPROVED,
State.REJECTED,
State.CONDITIONAL)) \
Expand Down
2 changes: 0 additions & 2 deletions services/emailer/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
NAMEX_API_VERSION=
REPORT_API_URL=
REPORT_API_VERSION=
LEGAL_API_URL=
LEGAL_API_VERSION=

# Letter urls
DECIDE_BUSINESS_URL=
Expand Down
3 changes: 0 additions & 3 deletions services/emailer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,9 @@ 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")

NOTIFY_API_URL = f"{NOTIFY_API_URL + NOTIFY_API_VERSION}/notify"
NAMEX_SVC_URL = f"{NAMEX_API_URL + NAMEX_API_VERSION}"
ENTITY_SVC_URL= f"{LEGAL_API_URL + LEGAL_API_VERSION}"

REPORT_SVC_URL = f'{os.getenv("REPORT_API_URL", None)}{os.getenv("REPORT_API_VERSION", None)}/reports'

Expand Down
3 changes: 1 addition & 2 deletions services/emailer/devops/vault.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"application": [
"notify-api",
"namex-api",
"report-api",
"legal-api"
"report-api"
]
},
{
Expand Down
1 change: 0 additions & 1 deletion services/emailer/devops/vaults.gcp.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ AUTH_WEB_URL="op://web-url/$APP_ENV/auth-web/AUTH_WEB_URL"
BUSINESS_REGISTRY_URL="op://web-url/$APP_ENV/business-registry-ui/BUSINESS_REGISTRY_URL"
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"
SENTRY_DSN=""
2 changes: 1 addition & 1 deletion services/emailer/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -87,11 +87,7 @@ def process(email_info: SimpleCloudEvent, option) -> dict: # pylint: disable-ms
if option == Option.BEFORE_EXPIRY.value:
if "entity_type_cd" in nr_data:
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)
if group:
instruction_group = "-" + group
file_name_suffix += instruction_group.upper()
Expand Down
14 changes: 3 additions & 11 deletions services/emailer/src/namex_emailer/email_processors/nr_result.py
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,11 +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)
instruction_group = ReportResource._get_instruction_group(legal_type)
structured_log(request, "DEBUG", f"NR_notification: {instruction_group}")
file_name=''
if nr_model['consentFlag'] in ['Y', 'R']:
Expand Down
38 changes: 0 additions & 38 deletions services/emailer/src/namex_emailer/services/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,41 +70,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 ''

0 comments on commit 5f0dff3

Please sign in to comment.