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

[MDS-5836] trigger notification report requested #3087

Merged
merged 3 commits into from
May 10, 2024
Merged
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
54 changes: 48 additions & 6 deletions services/core-api/app/api/mines/reports/models/mine_report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid

from flask import current_app
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.schema import FetchedValue
from sqlalchemy.ext.associationproxy import association_proxy
Expand All @@ -22,6 +22,7 @@
from app.api.mines.reports.models.mine_report_notification import MineReportNotification
from app.api.utils.helpers import get_current_core_or_ms_env_url
from app.api.utils.helpers import format_email_datetime_to_string
from app.api.mines.exceptions.mine_exceptions import MineException

class MineReport(SoftDeleteMixin, AuditMixin, Base):
__tablename__ = "mine_report"
Expand Down Expand Up @@ -223,15 +224,15 @@ def collectRecipients(self, is_proponent):
return core_recipients, ms_recipients

def getReportSpecificEmailsByReportType(self, compliance_details):
notificaiton_list = MineReportNotification.find_contact_by_compliance_article(compliance_details.section,
notification_list = MineReportNotification.find_contact_by_compliance_article(compliance_details.section,
compliance_details.sub_section, compliance_details.paragraph, compliance_details.sub_paragraph)
unique_recipients = set()
regional_email = self.mine.region.regional_contact_office.email

for ntf in notificaiton_list:
notifiy_email = ntf[0]
if notifiy_email not in unique_recipients:
unique_recipients.add(notifiy_email)
for ntf in notification_list:
notify_email = ntf[0]
if notify_email not in unique_recipients:
unique_recipients.add(notify_email)

if ntf[1] and self.mine.major_mine_ind and PERM_RECL_EMAIL not in unique_recipients:
unique_recipients.add(PERM_RECL_EMAIL)
Expand All @@ -256,6 +257,47 @@ def send_crr_report_update_email(self, is_edit):
body += f'<p>View updates in Core: <a href="{link}" target="_blank">{link}</a></p>'
EmailService.send_email(subject, recipients, body)

def send_report_requested_email(self, report_name, is_crr):
if self.mine.mine_manager:
recipients = [self.mine.mine_manager.party.email]
else:
current_app.logger.info(f"Can't find mine manager's email for the mine: {self.mine.mine_name}")
raise MineException(f"Couldn't send the email for the mine manager as no manager found for the mine: {self.mine.mine_name}")

if is_crr:
compliance_details = self.mine_report_definition.compliance_articles[0]
compliance_string = ComplianceArticle.get_compliance_article_string(self.mine_report_definition.compliance_articles[0])
report_name = f'{compliance_string} - {compliance_details.description}'
permit_info_value = ""
permit_info_label = ""

else: #PRR
report_name = self.report_name
permit_info_label = "Permit Number"
permit_info_value = self.permit_number + ": "

subject = "A Report is requested in MineSpace"
due_date = (self.due_date).strftime("%b %d %Y") if self.due_date else "N/A"
ms_url = get_current_core_or_ms_env_url("ms")
ms_report_page_link = f'{ms_url}/mines/{self.mine.mine_guid}/reports/{self.mine_report_guid}'

email_context = {
"report_request": {
"mine_number": self.mine.mine_no,
"mine_name": self.mine.mine_name,
"permit_info_label": permit_info_label,
"permit_info_value": permit_info_value,
"report_name": report_name,
"report_compliance_year": self.submission_year,
"report_due_date": due_date,
},
"minespace_login_link": ms_url,
"ms_report_page_link": ms_report_page_link
}

ms_email_body = open("app/templates/email/report/ms_new_report_requested_email.html", "r").read()
EmailService.send_template_email(subject, recipients, ms_email_body, email_context, cc=None)

@classmethod
def create(cls,
mine_report_definition_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid
from flask_restx import Resource
from flask import request
from flask import request, current_app
from datetime import datetime
from werkzeug.exceptions import BadRequest, NotFound, InternalServerError

Expand All @@ -22,6 +22,8 @@
from app.api.mines.permits.permit_conditions.models.permit_condition_category import PermitConditionCategory
from app.api.utils.custom_reqparser import CustomReqparser
from app.api.mines.response_models import MINE_REPORT_MODEL
from app.api.mines.exceptions.mine_exceptions import MineException



class MineReportListResource(Resource, UserMixin):
Expand Down Expand Up @@ -191,6 +193,10 @@ def post(self, mine_guid):
if is_report_request:
report_name = mine_report_definition.report_name if is_code_required_report else permit_condition_category.description
trigger_notification(f'A report has been requested by the ministry: {report_name}', ActivityType.report_requested, mine, 'MineReport', mine_report.mine_report_guid, None, None, ActivityRecipients.minespace_users)
try:
mine_report.send_report_requested_email(report_name, is_code_required_report)
except Exception as e:
current_app.logger.warning(f"Couldn't send the email notification for the requested report: {report_name}. {str(e)}")

return mine_report, 201

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
@media only screen and (max-width: 620px) {

table.body .wrapper,
s table.body .article {
padding: 10px !important;
}

table.body .content {
padding: 0 !important;
}

table.body .container {
padding: 0 !important;
width: 100% !important;
}

table.body .main {
border-left-width: 0 !important;
border-radius: 0 !important;
border-right-width: 0 !important;
}

table.body .btn table {
width: 100% !important;
}

table.body .btn a {
width: 100% !important;
}

table.body .img-responsive {
height: auto !important;
max-width: 100% !important;
width: auto !important;
}
}
</style>
</head>

<body
style="background-color: #ffffff; font-family: sans-serif; -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.4; margin: 0; padding: 0; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">
<table role="presentation" cellpadding="0" cellspacing="0" class="body"
style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #ffffff; width: 100%;"
width="100%">
<tr>
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top;" valign="top">&nbsp;</td>
<td class="container"
style="font-family: sans-serif; font-size: 14px; vertical-align: top; display: block; max-width: 580px; padding: 10px; width: 580px; margin: 0 auto;"
width="580" valign="top">
<div class="content"
style="box-sizing: border-box; display: block; margin: 0 auto; max-width: 580px; padding: 10px;">
<div class="content-block"
style="font-family: sans-serif; vertical-align: top; padding-bottom: 36px; padding-top: 10px; font-size: 12px; text-align: center;"
valign="top">
<img src="{{minespace_logo}}" width="60%" style="object-fit: contain;">
</div>
<!-- START CENTERED WHITE CONTAINER -->
<table role="presentation" class="main"
style=" border-width:1px; border-style:solid; border-color:#DED9D9; border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #ffffff; border-radius: 3px; width: 100%;"
width="100%">

<!-- START MAIN CONTENT AREA -->
<tr>
<td class="wrapper" style="vertical-align: top; box-sizing: border-box; padding: 20px;" valign="top">
<table role="presentation" cellpadding="0" cellspacing="0"
style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;"
width="100%">
<tr>
<td style="vertical-align: top; text-align: center; font-family: sans-serif; font-size: 24px; font-weight: 700; line-height: 30px; color: #003366; padding: 10px 0px 16px;"
valign="top">
A report has been requested in MineSpace
</td>
</tr>
<tr>
<td style="vertical-align: top; text-align:center; font-family: sans-serif; font-size: 16px; font-weight: 400; line-height: 20px; color: #6B6363; margin: 0; margin-bottom: 15px;"
valign="top">
<p style="text-align: center; margin-top: 16px;">
To view more information about this submission please
<a href="{{minespace_login_link}}">log into the Minespace application.</a>
</p>
<p>
Mine Name: {{ report_request.mine_name }}
<br/>
Mine Number: {{report_request.mine_number}}
</p>
<p>
{{report_request.permit_info_label}} {{report_request.permit_info_value}} <br/>
Report Name: {{report_request.report_name}}
</p>
<p>
Compliance Year: {{ report_request.report_compliance_year }} <br>
Due Date: {{ report_request.report_due_date }}
</p>
</td>
</tr>
<tr>
<td>
<div style="text-align:center; padding-top: 32px;">
<a href="{{ ms_report_page_link }}" type="button"
style="border: solid 1px #003366; border-radius: 5px; box-sizing: border-box; cursor: pointer; display: inline-block; font-size: 14px; font-weight: bold; margin: 0; padding: 12px 25px; text-decoration: none; text-transform: capitalize; background-color: #003366; border-color: #003366; color: #ffffff;">
Submit Report
</a>
</div>
</td>
</tr>
</table>
</td>
</tr>

<!-- END MAIN CONTENT AREA -->
</table>
<!-- END CENTERED WHITE CONTAINER -->

<!-- START FOOTER -->
<div class="footer" style="clear: both; margin-top: 10px; text-align: center; width: 100%;">
<table role="presentation" cellpadding="0" cellspacing="0"
style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;"
width="100%">
<tr>
<td class="content-block"
style="font-family: sans-serif; vertical-align: top; padding-bottom: 10px; padding-top: 16px; font-size: 12px; text-align: center;"
valign="top">
<p
style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px; font-weight: 400; line-height: 20px;">
Please note: This e-mail was sent from a notification-only address that cannot accept incoming
e-mail. Please do not reply to this message.</p>
</td>
</tr>
<tr>
<td class="content-block"
style="font-family: sans-serif; vertical-align: top; padding-bottom: 10px; padding-top: 10px; font-size: 12px; text-align: center;"
valign="top">
</tr>
</td>
</table>
</div>
<!-- END FOOTER -->

</div>
</td>
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top;" valign="top">&nbsp;</td>
</tr>
</table>
</body>

</html>
Loading