From d441b1b93f6b66c4a4037ec84aede5a8c11a3ea2 Mon Sep 17 00:00:00 2001 From: VineetBala-AOT Date: Wed, 13 Dec 2023 11:42:37 -0800 Subject: [PATCH] Comments rejection after engagement is closed --- met-api/sample.env | 3 +- met-api/src/met_api/config.py | 7 ++++- .../met_api/services/submission_service.py | 21 ++++++++----- .../email_rejected_comment_closed.html | 30 +++++++++++++++++++ openshift/api.dc.yml | 7 ++++- 5 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 met-api/templates/email_rejected_comment_closed.html diff --git a/met-api/sample.env b/met-api/sample.env index eae1169c9..4c2a02746 100644 --- a/met-api/sample.env +++ b/met-api/sample.env @@ -32,7 +32,8 @@ MET_ADMIN_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 diff --git a/met-api/src/met_api/config.py b/met-api/src/met_api/config.py index b1ed7a0db..c5bce4fb5 100644 --- a/met-api/src/met_api/config.py +++ b/met-api/src/met_api/config.py @@ -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'), diff --git a/met-api/src/met_api/services/submission_service.py b/met-api/src/met_api/services/submission_service.py index f13fd17da..19cf78039 100644 --- a/met-api/src/met_api/services/submission_service.py +++ b/met-api/src/met_api/services/submission_service.py @@ -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, @@ -349,11 +348,21 @@ 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 + survey: SurveyModel = SurveyModel.get_open(submission.survey_id) + if not survey: + 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) @@ -362,8 +371,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, @@ -389,7 +396,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: diff --git a/met-api/templates/email_rejected_comment_closed.html b/met-api/templates/email_rejected_comment_closed.html new file mode 100644 index 000000000..da334437f --- /dev/null +++ b/met-api/templates/email_rejected_comment_closed.html @@ -0,0 +1,30 @@ +

Thank you for taking the time to provide your feedback on {{ engagement_name }}.

+
+

We have reviewed your feedback and can't accept it for the following reason(s):

+
+ +
+

{{review_notes}}

+
+

+ We are sorry, but the public commenting period for {{ engagement_name }} + is now closed and your feedback cannot be edited. +

+
+

Thank you,

+
+

The {{tenant_name}} Team

+

{{email_environment}}

\ No newline at end of file diff --git a/openshift/api.dc.yml b/openshift/api.dc.yml index e94e8a9a1..fed696112 100644 --- a/openshift/api.dc.yml +++ b/openshift/api.dc.yml @@ -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} @@ -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