Skip to content

Commit

Permalink
Comments rejection after engagement is closed (#35)
Browse files Browse the repository at this point in the history
* Comments rejection after engagement is closed

* Updating condition
  • Loading branch information
VineetBala-AOT authored Dec 13, 2023
1 parent e17746e commit 6d7fd31
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
3 changes: 2 additions & 1 deletion met-api/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ MET_ADMIN_CLIENT_SECRET=<GENERATED_CLIENT_SECRET>
NOTIFICATIONS_EMAIL_ENDPOINT=https://localhost:5002/api/v1/notifications/email
VERIFICATION_EMAIL_TEMPLATE_ID=c4cc1633-321a-4400-8a22-272acecd836a
SUBSCRIBE_EMAIL_TEMPLATE_ID=9cd4942b-8ac9-49ae-a869-c800c57a7472
REJECTED_EMAIL_TEMPLATE_ID=fede7ed2-4e4f-4278-9881-dadc21df8f11
REJECTED_EMAIL_TEMPLATE_ID=8410c055-587b-4788-bd2f-b563562bcb2d
CLOSED_ENGAGEMENT_REJECTED_EMAIL_TEMPLATE_ID=e942dea1-094e-4021-9aac-21a0ac1f240d
ACCESS_REQUEST_EMAIL_ADDRESS=tiago.x.graf@gov.bc.ca
ACCESS_REQUEST_EMAIL_TEMPLATE_ID=41afa792-4c75-425a-9ad9-c558561d6669

Expand Down
7 changes: 6 additions & 1 deletion met-api/src/met_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ class _Config(): # pylint: disable=too-few-public-methods
'SUBSCRIBE_EMAIL_TEMPLATE_ID': os.getenv('SUBSCRIBE_EMAIL_TEMPLATE_ID'),
'SUBSCRIBE_EMAIL_SUBJECT': os.getenv('SUBSCRIBE_EMAIL_SUBJECT', 'Confirm your subscription'),
'REJECTED_EMAIL_TEMPLATE_ID': os.getenv('REJECTED_EMAIL_TEMPLATE_ID'),
'REJECTED_EMAIL_SUBJECT': os.getenv('REJECTED_EMAIL_SUBJECT', '{engagement_name} - About your Comments'),
'REJECTED_EMAIL_SUBJECT': os.getenv('REJECTED_EMAIL_SUBJECT',
'Your comment on {engagement_name} needs to be edited'),
'CLOSED_ENGAGEMENT_REJECTED_EMAIL_TEMPLATE_ID': os.getenv('CLOSED_ENGAGEMENT_REJECTED_EMAIL_TEMPLATE_ID'),
'CLOSED_ENGAGEMENT_REJECTED_EMAIL_SUBJECT':
os.getenv('CLOSED_ENGAGEMENT_REJECTED_EMAIL_SUBJECT',
'Your comment on {engagement_name} has been rejected'),
'SUBMISSION_RESPONSE_EMAIL_TEMPLATE_ID': os.getenv('SUBMISSION_RESPONSE_EMAIL_TEMPLATE_ID'),
'SUBMISSION_RESPONSE_EMAIL_SUBJECT': os.getenv('SUBMISSION_RESPONSE_EMAIL_SUBJECT',
'Your feedback was successfully submitted'),
Expand Down
20 changes: 13 additions & 7 deletions met-api/src/met_api/services/submission_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ def _send_rejected_email(staff_review_details: dict, submission: SubmissionModel
"""Send an verification email.Throws error if fails."""
participant_id = submission.participant_id
participant = ParticipantModel.find_by_id(participant_id)
template_id = get_gc_notify_config('REJECTED_EMAIL_TEMPLATE_ID')
subject, body, args = SubmissionService._render_email_template(
template_id, subject, body, args = SubmissionService._render_email_template(
staff_review_details, submission, review_note, token)
try:
notification.send_email(subject=subject,
Expand All @@ -349,11 +348,20 @@ def _send_rejected_email(staff_review_details: dict, submission: SubmissionModel
@staticmethod
# pylint: disable-msg=too-many-locals
def _render_email_template(staff_review_details: dict, submission: SubmissionModel, review_note, token):
template = Template.get_template('email_rejected_comment.html')
engagement: EngagementModel = EngagementModel.find_by_id(
submission.engagement_id)
survey: SurveyModel = SurveyModel.find_by_id(submission.survey_id)
engagement_name = engagement.name
if engagement.status_id == EngagementStatus.Closed.value:
template_id = get_gc_notify_config('CLOSED_ENGAGEMENT_REJECTED_EMAIL_TEMPLATE_ID')
template = Template.get_template('email_rejected_comment_closed.html')
subject = get_gc_notify_config('CLOSED_ENGAGEMENT_REJECTED_EMAIL_SUBJECT'). \
format(engagement_name=engagement_name)
else:
template_id = get_gc_notify_config('REJECTED_EMAIL_TEMPLATE_ID')
template = Template.get_template('email_rejected_comment.html')
subject = get_gc_notify_config('REJECTED_EMAIL_SUBJECT'). \
format(engagement_name=engagement_name)
survey: SurveyModel = SurveyModel.find_by_id(submission.survey_id)
survey_name = survey.name
tenant_name = SubmissionService._get_tenant_name(
engagement.tenant_id)
Expand All @@ -362,8 +370,6 @@ def _render_email_template(staff_review_details: dict, submission: SubmissionMod
submission_id=submission.id, token=token)
submission_url = notification.get_tenant_site_url(
engagement.tenant_id, submission_path)
subject = get_gc_notify_config('REJECTED_EMAIL_SUBJECT'). \
format(engagement_name=engagement_name)
email_environment = get_gc_notify_config('EMAIL_ENVIRONMENT')
args = {
'engagement_name': engagement_name,
Expand All @@ -389,7 +395,7 @@ def _render_email_template(staff_review_details: dict, submission: SubmissionMod
end_date=args.get('end_date'),
email_environment=args.get('email_environment'),
)
return subject, body, args
return template_id, subject, body, args

@staticmethod
def _send_submission_response_email(participant_id, engagement_id) -> None:
Expand Down
30 changes: 30 additions & 0 deletions met-api/templates/email_rejected_comment_closed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<h1>Thank you for taking the time to provide your feedback on {{ engagement_name }}.</h1>
<br />
<p>We have reviewed your feedback and can't accept it for the following reason(s):</p>
<br>
<ul>
{% if has_personal_info %}
<li>
Your feedback contains personal information
</li>
{% endif %} {% if has_profanity %}
<li> Your feedback contains profanity or innapropriate language</li>
{% endif %} {% if has_other_reason %}
<li>
Your feedback contains {{ other_reason
}}
</li>
{% endif %}
</ul>
<br />
<p>{{review_notes}}</p>
<br/>
<p>
We are sorry, but the public commenting period for {{ engagement_name }}
is now closed and your feedback cannot be edited.
</p>
<br />
<p>Thank you,</p>
<br />
<p>The {{tenant_name}} Team</p>
<p>{{email_environment}}</p>
7 changes: 6 additions & 1 deletion openshift/api.dc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ objects:
SITE_URL: ${SITE_URL}
VERIFICATION_EMAIL_TEMPLATE_ID: ${VERIFICATION_EMAIL_TEMPLATE_ID}
SUBSCRIBE_EMAIL_TEMPLATE_ID: ${SUBSCRIBE_EMAIL_TEMPLATE_ID}
REJECTED_EMAIL_TEMPLATE_ID: ${REJECTED_EMAIL_TEMPLATE_ID}
REJECTED_EMAIL_TEMPLATE_ID: ${REJECTED_EMAIL_TEMPLATE_ID}
CLOSED_ENGAGEMENT_REJECTED_EMAIL_TEMPLATE_ID: ${CLOSED_ENGAGEMENT_REJECTED_EMAIL_TEMPLATE_ID}
ACCESS_REQUEST_EMAIL_TEMPLATE_ID: ${ACCESS_REQUEST_EMAIL_TEMPLATE_ID}
KEYCLOAK_REALMNAME: ${KEYCLOAK_REALMNAME}
KEYCLOAK_BASE_URL: ${KEYCLOAK_BASE_URL}
Expand Down Expand Up @@ -272,6 +273,10 @@ parameters:
description: "The rejected comment email template id"
required: true
value: '8410c055-587b-4788-bd2f-b563562bcb2d'
- name: CLOSED_ENGAGEMENT_REJECTED_EMAIL_TEMPLATE_ID
description: "The rejected comment email template id for closed engagement"
required: true
value: 'e942dea1-094e-4021-9aac-21a0ac1f240d'
- name: ACCESS_REQUEST_EMAIL_TEMPLATE_ID
description: "The access request email template id"
required: true
Expand Down

0 comments on commit 6d7fd31

Please sign in to comment.