def process(email_msg: dict) -> dict: """Build the email for mras notification.""" logger.debug('mras_notification: %s', email_msg) # get template and fill in parts template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/BC-MRAS.html').read_text() filled_template = substitute_template_parts(template) # get template info from filing filing, business, leg_tmz_filing_date, leg_tmz_effective_date = get_filing_info(email_msg['filingId']) # render template with vars jnja_template = Template(filled_template, autoescape=True) html_out = jnja_template.render( business=business, incorporationApplication=(filing.json)['filing']['incorporationApplication'], header=(filing.json)['filing']['header'], filing_date_time=leg_tmz_filing_date, effective_date_time=leg_tmz_effective_date ) # get recipients recipients = get_recipients(email_msg['option'], filing.filing_json) return { 'recipients': recipients, 'requestBy': '*****@*****.**', 'content': { 'subject': 'BC Business Registry Partner Information', 'body': f'{html_out}', 'attachments': [] } }
def process(email_msg: dict) -> dict: """Build the email for Business Number notification.""" logger.debug('bn notification: %s', email_msg) # get template and fill in parts template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/BC-BN.html').read_text() filled_template = substitute_template_parts(template) # get filing and business json business = Business.find_by_identifier(email_msg['identifier']) filing = (Filing.get_a_businesses_most_recent_filing_of_a_type(business.id, 'incorporationApplication')) # render template with vars jnja_template = Template(filled_template, autoescape=True) html_out = jnja_template.render( business=business.json() ) # get recipients recipients = get_recipients(email_msg['option'], filing.filing_json) return { 'recipients': recipients, 'requestBy': '*****@*****.**', 'content': { 'subject': f'{business.legal_name} - Business Number Information', 'body': html_out, 'attachments': [] } }
def process(email_msg: dict, token: str) -> dict: # pylint: disable=too-many-locals """Build the email for Business Number notification.""" logger.debug('incorp_notification: %s', email_msg) # get template and fill in parts template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/BC-{email_msg["option"]}-success.html').read_text() filled_template = substitute_template_parts(template) # get template vars from filing filing, business, leg_tmz_filing_date, leg_tmz_effective_date = get_filing_info(email_msg['filingId']) # render template with vars jnja_template = Template(filled_template, autoescape=True) html_out = jnja_template.render( business=business, incorporationApplication=(filing.json)['filing']['incorporationApplication'], header=(filing.json)['filing']['header'], filing_date_time=leg_tmz_filing_date, effective_date_time=leg_tmz_effective_date, entity_dashboard_url=current_app.config.get('DASHBOARD_URL') + (filing.json)['filing']['business'].get('identifier', '') ) # get attachments pdfs = _get_pdfs(email_msg['option'], token, business, filing, leg_tmz_filing_date) # get recipients recipients = get_recipients(email_msg['option'], filing.filing_json) # assign subject if email_msg['option'] == 'filed': subject = 'Confirmation of Filing from the Business Registry' elif email_msg['option'] == 'registered': subject = 'Incorporation Documents from the Business Registry' else: # fallback case - should never happen subject = 'Notification from the BC Business Registry' return { 'recipients': recipients, 'requestBy': '*****@*****.**', 'content': { 'subject': subject, 'body': f'{html_out}', 'attachments': pdfs } }
def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-locals, , too-many-branches """Build the email for Affiliation notification.""" logger.debug('filing_notification: %s', email_info) # get template vars from filing filing, business, leg_tmz_filing_date, leg_tmz_effective_date = \ get_filing_info(email_info['data']['filing']['header']['filingId']) filing_type = filing.filing_type status = filing.status filing_name = filing.filing_type[0].upper() + ' '.join(re.findall('[a-zA-Z][^A-Z]*', filing.filing_type[1:])) template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/BC-ALT-DRAFT.html').read_text() filled_template = substitute_template_parts(template) # render template with vars jnja_template = Template(filled_template, autoescape=True) filing_data = (filing.json)['filing'][f'{filing_type}'] html_out = jnja_template.render( business=business, filing=filing_data, header=(filing.json)['filing']['header'], filing_date_time=leg_tmz_filing_date, effective_date_time=leg_tmz_effective_date, entity_dashboard_url=current_app.config.get('DASHBOARD_URL') + (filing.json)['filing']['business'].get('identifier', ''), email_header=filing_name.upper(), filing_type=filing_type ) # get recipients recipients = get_recipients(status, filing.filing_json, token) if not recipients: return {} # assign subject legal_name = business.get('legalName', None) subject = f'{legal_name} - How to use BCRegistry.ca' return { 'recipients': recipients, 'requestBy': '*****@*****.**', 'content': { 'subject': subject, 'body': f'{html_out}' } }
def process(email_info: dict) -> dict: """Build the email for Name Request notification.""" logger.debug('NR_notification: %s', email_info) nr_number = email_info['identifier'] payment_token = email_info.get('data', {}).get('request', {}).get('paymentToken', '') template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/NR-PAID.html').read_text() filled_template = substitute_template_parts(template) # render template with vars mail_template = Template(filled_template, autoescape=True) html_out = mail_template.render( identifier=nr_number ) # get nr data nr_response = NameXService.query_nr_number(nr_number) if nr_response.status_code != HTTPStatus.OK: logger.error('Failed to get nr info for name request: %s', nr_number) capture_message(f'Email Queue: nr_id={nr_number}, error=receipt generation', level='error') return {} nr_data = nr_response.json() # get attachments pdfs = _get_pdfs(nr_data['id'], payment_token) if not pdfs: return {} # get recipients recipients = nr_data['applicants']['emailAddress'] if not recipients: return {} subject = f'{nr_number} - Receipt from Corporate Registry' return { 'recipients': recipients, 'requestBy': '*****@*****.**', 'content': { 'subject': subject, 'body': f'{html_out}', 'attachments': pdfs } }
def process(email_msg: dict, token: str) -> dict: """Build the email for annual report reminder notification.""" logger.debug('ar_reminder_notification: %s', email_msg) ar_fee = email_msg['arFee'] ar_year = email_msg['arYear'] # get template and fill in parts template = Path( f'{current_app.config.get("TEMPLATE_PATH")}/AR-REMINDER.html' ).read_text() filled_template = substitute_template_parts(template) business = Business.find_by_internal_id(email_msg['businessId']) corp_type = CorpType.find_by_id(business.legal_type) # render template with vars jnja_template = Template(filled_template, autoescape=True) html_out = jnja_template.render( business=business, ar_fee=ar_fee, ar_year=ar_year, entity_type=corp_type.full_desc, entity_dashboard_url=current_app.config.get('DASHBOARD_URL') + business.identifier) # get recipients recipients = get_recipient_from_auth(business.identifier, token) subject = f'{business.legal_name} {ar_year} Annual Report Reminder' return { 'recipients': recipients, 'requestBy': '*****@*****.**', 'content': { 'subject': subject, 'body': f'{html_out}', 'attachments': [] } }
def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-locals, , too-many-branches """Build the email for Business Number notification.""" logger.debug('filing_notification: %s', email_info) # get template and fill in parts filing_type, status = email_info['type'], email_info['option'] # get template vars from filing filing, business, leg_tmz_filing_date, leg_tmz_effective_date = get_filing_info( email_info['filingId']) if filing_type == 'correction': original_filing_type = filing.filing_json['filing']['correction'][ 'correctedFilingType'] if original_filing_type != 'incorporationApplication': return None original_filing_name = original_filing_type[0].upper() + ' '.join( re.findall('[a-zA-Z][^A-Z]*', original_filing_type[1:])) filing_name = f'Correction of {original_filing_name}' else: filing_name = filing.filing_type[0].upper() + ' '.join( re.findall('[a-zA-Z][^A-Z]*', filing.filing_type[1:])) if filing_type == 'correction': template = Path( f'{current_app.config.get("TEMPLATE_PATH")}/BC-{FILING_TYPE_CONVERTER[filing_type]}-' f'{FILING_TYPE_CONVERTER[original_filing_type]}-{status}.html' ).read_text() else: template = Path( f'{current_app.config.get("TEMPLATE_PATH")}/BC-{FILING_TYPE_CONVERTER[filing_type]}-{status}.html' ).read_text() filled_template = substitute_template_parts(template) # render template with vars jnja_template = Template(filled_template, autoescape=True) filing_data = (filing.json)['filing'][f'{original_filing_type}'] if filing_type == 'correction' \ else (filing.json)['filing'][f'{filing_type}'] html_out = jnja_template.render( business=business, filing=filing_data, header=(filing.json)['filing']['header'], filing_date_time=leg_tmz_filing_date, effective_date_time=leg_tmz_effective_date, entity_dashboard_url=current_app.config.get('DASHBOARD_URL') + (filing.json)['filing']['business'].get('identifier', ''), email_header=filing_name.upper(), filing_type=filing_type, additional_info=get_additional_info(filing)) # get attachments pdfs = _get_pdfs(status, token, business, filing, leg_tmz_filing_date, leg_tmz_effective_date) # get recipients recipients = get_recipients(status, filing.filing_json, token) if not recipients: return {} # assign subject if status == Filing.Status.PAID.value: if filing_type == 'incorporationApplication': subject = 'Confirmation of Filing from the Business Registry' elif filing_type == 'correction': subject = f'Confirmation of Correction of {original_filing_name}' elif filing_type in ['changeOfAddress', 'changeOfDirectors']: address_director = [ x for x in ['Address', 'Director'] if x in filing_type ][0] subject = f'Confirmation of {address_director} Change' elif filing_type == 'annualReport': subject = 'Confirmation of Annual Report' elif filing_type == 'alteration': subject = 'Confirmation of Alteration from the Business Registry' elif status == Filing.Status.COMPLETED.value: if filing_type == 'incorporationApplication': subject = 'Incorporation Documents from the Business Registry' if filing_type == 'correction': subject = f'{original_filing_name} Correction Documents from the Business Registry' elif filing_type in [ 'changeOfAddress', 'changeOfDirectors', 'alteration', 'correction' ]: subject = 'Notice of Articles' if not subject: # fallback case - should never happen subject = 'Notification from the BC Business Registry' if filing.filing_type == 'incorporationApplication': legal_name = \ filing.filing_json['filing']['incorporationApplication']['nameRequest'].get('legalName', None) else: legal_name = business.get('legalName', None) subject = f'{legal_name} - {subject}' if legal_name else subject return { 'recipients': recipients, 'requestBy': '*****@*****.**', 'content': { 'subject': subject, 'body': f'{html_out}', 'attachments': pdfs } }
def process(email_info: dict, option) -> dict: # pylint: disable-msg=too-many-locals """ Build the email for Name Request notification. valid values of option: Option """ logger.debug('NR %s notification: %s', option, email_info) nr_number = email_info['identifier'] template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/NR-{option.upper()}.html').read_text() filled_template = substitute_template_parts(template) nr_response = NameXService.query_nr_number(nr_number) if nr_response.status_code != HTTPStatus.OK: logger.error('Failed to get nr info for name request: %s', nr_number) capture_message(f'Email Queue: nr_id={nr_number}, error=receipt generation', level='error') return {} nr_data = nr_response.json() expiration_date = '' if nr_data['expirationDate']: exp_date = datetime.fromisoformat(nr_data['expirationDate']) expiration_date = LegislationDatetime.format_as_report_string(exp_date) refund_value = '' if option == Option.REFUND.value: refund_value = email_info.get('data', {}).get('request', {}).get('refundValue', None) legal_name = '' for n_item in nr_data['names']: if n_item['state'] in ('APPROVED', 'CONDITION'): legal_name = n_item['name'] break # render template with vars mail_template = Template(filled_template, autoescape=True) html_out = mail_template.render( nr_number=nr_number, expiration_date=expiration_date, legal_name=legal_name, refund_value=refund_value ) # get recipients recipients = nr_data['applicants']['emailAddress'] if not recipients: return {} subjects = { Option.BEFORE_EXPIRY.value: 'Expiring Soon', Option.EXPIRED.value: 'Expired', Option.RENEWAL.value: 'Confirmation of Renewal', Option.UPGRADE.value: 'Confirmation of Upgrade', Option.REFUND.value: 'Refund request confirmation' } return { 'recipients': recipients, 'requestBy': '*****@*****.**', 'content': { 'subject': f'{nr_number} - {subjects[option]}', 'body': f'{html_out}', 'attachments': [] } }
def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-locals, , too-many-branches """Build the email for Dissolution notification.""" logger.debug('dissolution_notification: %s', email_info) # get template and fill in parts filing_type, status = email_info['type'], email_info['option'] # get template vars from filing filing, business, leg_tmz_filing_date, leg_tmz_effective_date = get_filing_info( email_info['filingId']) filing_name = filing.filing_type[0].upper() + ' '.join( re.findall('[a-zA-Z][^A-Z]*', filing.filing_type[1:])) template = Path( f'{current_app.config.get("TEMPLATE_PATH")}/DIS-{status}.html' ).read_text() filled_template = substitute_template_parts(template) # render template with vars jnja_template = Template(filled_template, autoescape=True) filing_data = (filing.json)['filing'][f'{filing_type}'] html_out = jnja_template.render( business=business, filing=filing_data, header=(filing.json)['filing']['header'], filing_date_time=leg_tmz_filing_date, effective_date_time=leg_tmz_effective_date, entity_dashboard_url=current_app.config.get('DASHBOARD_URL') + (filing.json)['filing']['business'].get('identifier', ''), email_header=filing_name.upper(), filing_type=filing_type) # get attachments pdfs = _get_pdfs(status, token, business, filing, leg_tmz_filing_date, leg_tmz_effective_date) # get recipients identifier = filing.filing_json['filing']['business']['identifier'] recipients = [] recipients.append(get_recipient_from_auth(identifier, token)) if filing.submitter_roles and UserRoles.STAFF.value in filing.submitter_roles: # when staff file a dissolution documentOptionalEmail may contain completing party email recipients.append(filing.filing_json['filing']['header'].get( 'documentOptionalEmail')) else: recipients.append( get_user_email_from_auth(filing.filing_submitter.username, token)) for party in filing.filing_json['filing']['dissolution']['parties']: for role in party['roles']: if role['roleType'] == 'Custodian': recipients.append(party['officer']['email']) break recipients = list(set(recipients)) recipients = ', '.join(filter(None, recipients)).strip() # assign subject if status == Filing.Status.PAID.value: subject = 'Voluntary dissolution' elif status == Filing.Status.COMPLETED.value: subject = 'Confirmation of Dissolution from the Business Registry' if not subject: # fallback case - should never happen subject = 'Notification from the BC Business Registry' legal_name = business.get('legalName', None) subject = f'{legal_name} - {subject}' if legal_name else subject return { 'recipients': recipients, 'requestBy': '*****@*****.**', 'content': { 'subject': subject, 'body': f'{html_out}', 'attachments': pdfs } }