Skip to content

Commit

Permalink
[MDS-5895] Setting report email links with right env (#3038)
Browse files Browse the repository at this point in the history
* fixing email view button urls

* adding other environment urls for report email links

* changing conditional to not set url as test env in prod

* made retrieval of environment url into a function
  • Loading branch information
asinn134 authored Apr 5, 2024
1 parent e0df301 commit 59913a1
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 25 deletions.
8 changes: 4 additions & 4 deletions services/core-api/app/api/incidents/models/mine_incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def send_incidents_email(self):
"mine_name": self.mine_table.mine_name,
"mine_no": self.mine_table.mine_no,
},
"incident_link": f'{Config.CORE_PRODUCTION_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}',
"incident_link": f'{Config.CORE_PROD_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}',
}

minespace_context = {
Expand All @@ -310,7 +310,7 @@ def send_incidents_email(self):
"mine_name": self.mine_table.mine_name,
"mine_no": self.mine_table.mine_no,
},
"minespace_incident_link": f'{Config.MINESPACE_PRODUCTION_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}',
"minespace_incident_link": f'{Config.MINESPACE_PROD_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}',
}
EmailService.send_template_email(subject, emli_recipients, emli_body, emli_context, cc=cc)
EmailService.send_template_email(subject, minespace_recipients, minespace_body, minespace_context, cc=cc)
Expand All @@ -322,7 +322,7 @@ def send_awaiting_final_report_email(self, is_prop):
cc = None

subject = f'{self.mine_name}: The status of a reportable incident {self.mine_incident_report_no} has been updated on {format_email_datetime_to_string(self.update_timestamp)}'
link = f'{Config.MINESPACE_PRODUCTION_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}/review' if is_prop else f'{Config.CORE_PRODUCTION_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}'
link = f'{Config.MINESPACE_PROD_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}/review' if is_prop else f'{Config.CORE_PROD_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}'
body = open("app/templates/email/incident/minespace_awaiting_incident_final_report_email.html", "r").read() if is_prop else open("app/templates/email/incident/emli_awaiting_incident_final_report_email.html", "r").read()

context = {
Expand All @@ -343,7 +343,7 @@ def send_final_report_received_email(self, is_prop):
recipients = [PROP_EMAIL if is_prop else OCI_EMAIL]
cc = None

link = f'{Config.MINESPACE_PRODUCTION_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}/review' if is_prop else f'{Config.CORE_PRODUCTION_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}'
link = f'{Config.MINESPACE_PROD_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}/review' if is_prop else f'{Config.CORE_PROD_URL}/mines/{self.mine.mine_guid}/incidents/{self.mine_incident_guid}'
body = open("app/templates/email/incident/minespace_final_report_received_incident_email.html", "r").read() if is_prop else open("app/templates/email/incident/emli_final_report_received_incident_email.html", "r").read()
subject = f'{self.mine_name}: A final incident report on {self.mine_incident_report_no} has been submitted on {format_email_datetime_to_string(self.update_timestamp)}'
context = {
Expand Down
13 changes: 9 additions & 4 deletions services/core-api/app/api/mines/reports/models/mine_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from app.api.activity.utils import trigger_notification
from app.api.activity.models.activity_notification import ActivityType, ActivityRecipients
from app.api.mines.reports.models.mine_report_notification import MineReportNotification
from app.api.utils.helpers import get_current_core_or_ms_env_url

class MineReport(SoftDeleteMixin, AuditMixin, Base):
__tablename__ = "mine_report"
Expand Down Expand Up @@ -138,8 +139,12 @@ def send_crr_and_prr_add_notification_email(self, is_proponent, crr_or_prr):
core_recipients, ms_recipients = self.collectRecipients(is_proponent)

due_date = due_date = (self.due_date).strftime("%b %d %Y") if self.due_date else "N/A"
core_report_page_link = f'{Config.CORE_PRODUCTION_URL}/dashboard/reporting/mine/{self.mine.mine_guid}/report/{self.mine_report_guid}'
ms_report_page_link = f'{Config.MINESPACE_PRODUCTION_URL}/mines/{self.mine.mine_guid}/reports/{self.mine_report_guid}'

core_url = get_current_core_or_ms_env_url("core")
ms_url = get_current_core_or_ms_env_url("ms")

core_report_page_link = f'{core_url}/dashboard/reporting/mine/{self.mine.mine_guid}/report/{self.mine_report_guid}'
ms_report_page_link = f'{ms_url}/mines/{self.mine.mine_guid}/reports/{self.mine_report_guid}'
report_name = ""

if is_crr:
Expand Down Expand Up @@ -167,7 +172,7 @@ def send_crr_and_prr_add_notification_email(self, is_proponent, crr_or_prr):
"report_due_date": due_date,
"report_recieved_date": (self.received_date).strftime("%b %d %Y at %I:%M %p"),
},
"minespace_login_link": Config.MINESPACE_PRODUCTION_URL,
"minespace_login_link": ms_url,
"core_report_page_link": core_report_page_link,
"ms_report_page_link": ms_report_page_link
}
Expand Down Expand Up @@ -244,7 +249,7 @@ def send_crr_report_update_email(self, is_edit):
body_verb = 'uploaded document(s) to' if is_edit else 'submitted'
body = f'<p>{self.mine.mine_name} (Mine no: {self.mine.mine_no}) has {body_verb} a "{self.mine_report_definition_report_name}" report.</p>'

link = f'{Config.CORE_PRODUCTION_URL}/mine-dashboard/{self.mine.mine_guid}/reports/code-required-reports'
link = f'{Config.CORE_PROD_URL}/mine-dashboard/{self.mine.mine_guid}/reports/code-required-reports'
body += f'<p>View updates in Core: <a href="{link}" target="_blank">{link}</a></p>'
EmailService.send_email(subject, recipients, body)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,6 @@ def send_email_tsf_update(self):
recipients = MINESPACE_TSF_UPDATE_EMAIL
subject = f'TSF Information Update for {self.mine.mine_name}'
body = f'<p>{self.mine.mine_name} (Mine No.: {self.mine.mine_no}) has requested to update their TSF information.</p>'
link = f'{Config.CORE_PRODUCTION_URL}/mine-dashboard/{self.mine.mine_guid}/permits-and-approvals/tailings'
link = f'{Config.CORE_PROD_URL}/mine-dashboard/{self.mine.mine_guid}/permits-and-approvals/tailings'
body += f'<p>View updates in Core: <a href="{link}" target="_blank">{link}</a></p>'
EmailService.send_email(subject, recipients, body)
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def send_work_status_update_email(self):
body += f'<p><b>Work Status: </b>{self.work_status}</p>'
body += f'<p><b>Comments: </b>{self.work_comments}</p>'
body += f'<p><b>Updated By: </b>{self.updated_by}</p>'
link = f'{Config.CORE_PRODUCTION_URL}/mine-dashboard/{self.mine.mine_guid}/mine-information/general'
link = f'{Config.CORE_PROD_URL}/mine-dashboard/{self.mine.mine_guid}/mine-information/general'
body += f'<p>View updates in Core: <a href="{link}" target="_blank">{link}</a></p>'
EmailService.send_email(subject, recipients, body)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,6 @@ def nod_submission_email(self):

subject = f'Notice of Departure Submitted for {self.mine.mine_name}'
body = f'<p>{self.mine.mine_name} (Mine no: {self.mine.mine_no}) has submitted a "Notice of Departure from Approval" report.</p>'
link = f'{Config.CORE_PRODUCTION_URL}/mine-dashboard/{self.mine.mine_guid}/permits-and-approvals/notices-of-departure'
link = f'{Config.CORE_PROD_URL}/mine-dashboard/{self.mine.mine_guid}/permits-and-approvals/notices-of-departure'
body += f'<p>View updates in Core: <a href="{link}" target="_blank">{link}</a></p>'
EmailService.send_email(subject, recipients, body, cc=cc)
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def send_party_assigned_email(self):
if recipients:
cache.set(EDIT_TSF_EMAILS, recipients, timeout=TIMEOUT_24_HOURS)

button_link = f'{Config.CORE_PRODUCTION_URL}/mine-dashboard/{self.mine.mine_guid}/permits-and-approvals/tailings/{self.mine_tailings_storage_facility.mine_tailings_storage_facility_guid}/{party_page}'
button_link = f'{Config.CORE_PROD_URL}/mine-dashboard/{self.mine.mine_guid}/permits-and-approvals/tailings/{self.mine_tailings_storage_facility.mine_tailings_storage_facility_guid}/{party_page}'
# change from UTC to PST
submitted_at = format_email_datetime_to_string(datetime.utcnow())
start_date = self.start_date.strftime('%b %d %Y') if self.start_date else 'No date provided',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ def send_irt_submit_email(self):
subject = f'IRT Submitted for {self.project.mine_name}'
body = f'<p>{self.project.mine_name} (Mine no: {self.project.mine_no}) has updated {self.project.project_title} by submitting an IRT.</p>'

link = f'{Config.CORE_PRODUCTION_URL}/pre-applications/{self.project.project_guid}/information-requirements-table/{self.irt_guid}/intro-project-overview'
link = f'{Config.CORE_PROD_URL}/pre-applications/{self.project.project_guid}/information-requirements-table/{self.irt_guid}/intro-project-overview'
body += f'<p>View IRT in Core: <a href="{link}" target="_blank">{link}</a></p>'
EmailService.send_email(subject, recipients, body)

def send_irt_approval_email(self):
recipients = [contact.email for contact in self.project.contacts]
link = f'{Config.MINESPACE_PRODUCTION_URL}/projects/{self.project.project_guid}/information-requirements-table/{self.irt_guid}/review/intro-project-overview'
link = f'{Config.MINESPACE_PROD_URL}/projects/{self.project.project_guid}/information-requirements-table/{self.irt_guid}/review/intro-project-overview'

subject = f'IRT Notification for {self.project.mine_name}:{self.project.project_title}'
body = f'<p>An IRT has been approved for {self.project.mine_name}:(Mine no: {self.project.mine_no})-{self.project.project_title}.</p>'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def send_mma_submit_email(self):
def generate_list_element(element):
return f'<li>{element}</li>'

# TODO: Update this link with Config.MINESPACE_PRODUCTION_URL}/projects/{self.project_guid}/major-mine-application/{self.major_mine_application_guid}/review?step=3 and update frontend to support that
link = f'{Config.MINESPACE_PRODUCTION_URL}/projects/{self.project_guid}/major-mine-application/entry'
# TODO: Update this link with Config.MINESPACE_PROD_URL}/projects/{self.project_guid}/major-mine-application/{self.major_mine_application_guid}/review?step=3 and update frontend to support that
link = f'{Config.MINESPACE_PROD_URL}/projects/{self.project_guid}/major-mine-application/entry'

subject = f'Major Mine Application Submitted for {self.project.project_title}'
body = '<p>The following documents have been submitted with this Major Mine Application:</p>'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,15 +553,15 @@ def send_project_summary_email(self, mine):
"mine_name": mine.mine_name,
"mine_no": mine.mine_no,
},
"core_project_summary_link": f'{Config.CORE_PRODUCTION_URL}/pre-applications/{self.project.project_guid}/overview'
"core_project_summary_link": f'{Config.CORE_PROD_URL}/pre-applications/{self.project.project_guid}/overview'
}

minespace_context = {
"mine": {
"mine_name": mine.mine_name,
"mine_no": mine.mine_no,
},
"minespace_project_summary_link": f'{Config.MINESPACE_PRODUCTION_URL}/projects/{self.project.project_guid}/overview',
"minespace_project_summary_link": f'{Config.MINESPACE_PROD_URL}/projects/{self.project.project_guid}/overview',
"ema_auth_link": f'{Config.EMA_AUTH_LINK}',
}

Expand Down
14 changes: 10 additions & 4 deletions services/core-api/app/api/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pytz import timezone, utc
from PIL import Image
from flask import current_app
from app.config import Config


def clean_HTML_string(raw_html):
Expand Down Expand Up @@ -81,14 +82,19 @@ def create_image_with_aspect_ratio(source, width=None, height=None):
return {'source': source, 'width': width, 'height': height}

def validate_phone_no(phone_no, address_type_code='CAN'):
current_app.logger.info("inside validate_phone_no")
current_app.logger.info(phone_no)
current_app.logger.info(address_type_code)
if not phone_no:
raise AssertionError('Phone number is not provided.')
# TODO: this is an arbitrary limit for phone number characters, actual number depends on formatting decisions
if address_type_code == 'INT' and len(phone_no) > 50:
raise AssertionError('Invalid phone number, max 50 characters')
if address_type_code in ['CAN', 'USA'] and not re.match(r'[0-9]{3}-[0-9]{3}-[0-9]{4}', phone_no):
raise AssertionError('Invalid phone number format, must be of XXX-XXX-XXXX.')
return phone_no
return phone_no

def get_current_core_or_ms_env_url(app):
if app == 'core':
core_config_property = f'CORE_{(Config.ENVIRONMENT_NAME).upper()}_URL'
return getattr(Config, core_config_property)
elif app == 'ms':
ms_config_property = f'MINESPACE_{(Config.ENVIRONMENT_NAME).upper()}_URL'
return getattr(Config, ms_config_property)
2 changes: 1 addition & 1 deletion services/core-api/app/api/variances/models/variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,6 @@ def send_variance_application_email(self):
body += f'<p><b>Description: </b>{self.note}</p>'
body += f'<p><b>Applied for By: </b>{self.created_by}</p>'

link = f'{Config.CORE_PRODUCTION_URL}/mine-dashboard/{self.mine.mine_guid}/permits-and-approvals/variances/'
link = f'{Config.CORE_PROD_URL}/mine-dashboard/{self.mine.mine_guid}/permits-and-approvals/variances/'
body += f'<p>View updates in Core: <a href="{link}" target="_blank">{link}</a></p>'
EmailService.send_email(subject, recipients, body)
18 changes: 16 additions & 2 deletions services/core-api/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,24 @@ class Config(object):
NRIS_USER_NAME = os.environ.get('NRIS_USER_NAME', None)
NRIS_PASS = os.environ.get('NRIS_PASS', None)
ENVIRONMENT_NAME = os.environ.get('ENVIRONMENT_NAME', 'dev')
CORE_PRODUCTION_URL = os.environ.get('CORE_PRODUCTION_URL',
CORE_PROD_URL = os.environ.get('CORE_PRODUCTION_URL',
'https://minesdigitalservices.gov.bc.ca')
MINESPACE_PRODUCTION_URL = os.environ.get('MINESPACE_PRODUCTION_URL',
CORE_TEST_URL = os.environ.get('CORE_TEST_URL',
'https://mds-test.apps.silver.devops.gov.bc.ca')
CORE_DEV_URL = os.environ.get('CORE_DEV_URL',
'https://mds-dev.apps.silver.devops.gov.bc.ca')
CORE_LOCAL_URL = os.environ.get('CORE_LOCAL_URL',
'http://localhost:3000')

MINESPACE_PROD_URL = os.environ.get('MINESPACE_PRODUCTION_URL',
'https://minespace.gov.bc.ca')
MINESPACE_TEST_URL = os.environ.get('MINESPACE_TEST_URL',
'https://minespace-test.apps.silver.devops.gov.bc.ca')
MINESPACE_DEV_URL = os.environ.get('MINESPACE_DEV_URL',
'https://minespace-dev.apps.silver.devops.gov.bc.ca')
MINESPACE_LOCAL_URL = os.environ.get('MINESPACE_LOCAL_URL',
'http://localhost:3020')

MDS_NO_REPLY_EMAIL = os.environ.get('MDS_NO_REPLY_EMAIL', '[email protected]')
MDS_EMAIL = os.environ.get('MDS_EMAIL', '[email protected]')
MAJOR_MINES_OFFICE_EMAIL = os.environ.get('MAJOR_MINES_OFFICE_EMAIL', '[email protected]')
Expand Down

0 comments on commit 59913a1

Please sign in to comment.