Skip to content

Commit

Permalink
add end_date property to email_verification template (#1975)
Browse files Browse the repository at this point in the history
* update email text

* hard coded text

* linting & adding tenant_name

* add get_tenant name method to submission service

* update text

* add buttons and css sheet

* update task

* Revert "update task"

This reverts commit 941daaf.

* add back & update email templates

* remove css file
  • Loading branch information
djnunez-aot authored Aug 9, 2023
1 parent cd20234 commit b7945e3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
46 changes: 31 additions & 15 deletions met-api/src/met_api/services/email_verification_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ def create(cls, email_verification: EmailVerificationSchema, session=None) -> Em
cls.validate_fields(email_verification)
email_address: str = email_verification.get('email_address')
survey = SurveyModel.get_open(email_verification.get('survey_id'))
engagement: EngagementModel = EngagementModel.find_by_id(survey.engagement_id)
engagement: EngagementModel = EngagementModel.find_by_id(
survey.engagement_id)
if engagement.is_internal and not email_address.endswith(INTERNAL_EMAIL_DOMAIN):
raise BusinessException(
error='Not an internal email address.',
status_code=HTTPStatus.INTERNAL_SERVER_ERROR)

if email_address is not None:
participant = ParticipantService.get_or_create_by_email(email_address)
participant = ParticipantService.get_or_create_by_email(
email_address)
email_verification['participant_id'] = participant.id

email_verification['created_by'] = email_verification.get('participant_id')
email_verification['created_by'] = email_verification.get(
'participant_id')
email_verification['verification_token'] = uuid.uuid4()
EmailVerification.create(email_verification, session)

Expand Down Expand Up @@ -105,9 +108,11 @@ def _send_verification_email(email_verification: dict) -> None:
survey, email_verification.get('verification_token'), email_verification.get('type'), participant_id)
try:
# user hasn't been created yet.so create token using SA.
notification.send_email(subject=subject, email=email_to, html_body=body, args=args, template_id=template_id)
notification.send_email(
subject=subject, email=email_to, html_body=body, args=args, template_id=template_id)
except Exception as exc: # noqa: B902
current_app.logger.error('<Notification for registration failed', exc)
current_app.logger.error(
'<Notification for registration failed', exc)
raise BusinessException(
error='Error sending verification email.',
status_code=HTTPStatus.INTERNAL_SERVER_ERROR) from exc
Expand All @@ -124,17 +129,21 @@ def _render_email_template(survey: SurveyModel, token, email_type: EmailVerifica
@staticmethod
def _render_subscribe_email_template(survey: SurveyModel, token, participant_id):
# url is origin url excluding context path
engagement: EngagementModel = EngagementModel.find_by_id(survey.engagement_id)
engagement: EngagementModel = EngagementModel.find_by_id(
survey.engagement_id)
engagement_name = engagement.name
template_id = current_app.config.get('SUBSCRIBE_EMAIL_TEMPLATE_ID', None)
template_id = current_app.config.get(
'SUBSCRIBE_EMAIL_TEMPLATE_ID', None)
template = Template.get_template('subscribe_email.html')
subject_template = current_app.config.get('SUBSCRIBE_EMAIL_SUBJECT')
confirm_path = current_app.config.get('SUBSCRIBE_PATH'). \
format(engagement_id=engagement.id, token=token)
unsubscribe_path = current_app.config.get('UNSUBSCRIBE_PATH'). \
format(engagement_id=engagement.id, participant_id=participant_id)
confirm_url = notification.get_tenant_site_url(engagement.tenant_id, confirm_path)
unsubscribe_url = notification.get_tenant_site_url(engagement.tenant_id, unsubscribe_path)
confirm_url = notification.get_tenant_site_url(
engagement.tenant_id, confirm_path)
unsubscribe_url = notification.get_tenant_site_url(
engagement.tenant_id, unsubscribe_path)
args = {
'engagement_name': engagement_name,
'confirm_url': confirm_url,
Expand All @@ -151,21 +160,26 @@ def _render_subscribe_email_template(survey: SurveyModel, token, participant_id)
@staticmethod
def _render_survey_email_template(survey: SurveyModel, token):
# url is origin url excluding context path
engagement: EngagementModel = EngagementModel.find_by_id(survey.engagement_id)
engagement: EngagementModel = EngagementModel.find_by_id(
survey.engagement_id)
engagement_name = engagement.name
template_id = current_app.config.get('VERIFICATION_EMAIL_TEMPLATE_ID', None)
template_id = current_app.config.get(
'VERIFICATION_EMAIL_TEMPLATE_ID', None)
template = Template.get_template('email_verification.html')
subject_template = current_app.config.get('VERIFICATION_EMAIL_SUBJECT')
survey_path = current_app.config.get('SURVEY_PATH'). \
format(survey_id=survey.id, token=token)
engagement_path = EmailVerificationService._get_engagement_path(engagement)
engagement_path = EmailVerificationService._get_engagement_path(
engagement)
site_url = notification.get_tenant_site_url(engagement.tenant_id)
tenant_name = EmailVerificationService._get_tenant_name(engagement.tenant_id)
tenant_name = EmailVerificationService._get_tenant_name(
engagement.tenant_id)
args = {
'engagement_name': engagement_name,
'survey_url': f'{site_url}{survey_path}',
'engagement_url': f'{site_url}{engagement_path}',
'tenant_name': tenant_name,
'end_date': datetime.strftime(engagement.end_date, EmailVerificationService.full_date_format),
}
subject = subject_template.format(engagement_name=engagement_name)
body = template.render(
Expand All @@ -178,7 +192,8 @@ def _render_survey_email_template(survey: SurveyModel, token):

@staticmethod
def _get_engagement_path(engagement: EngagementModel):
engagement_slug = EngagementSlugModel.find_by_engagement_id(engagement.id)
engagement_slug = EngagementSlugModel.find_by_engagement_id(
engagement.id)
if engagement_slug:
return current_app.config.get('ENGAGEMENT_PATH_SLUG'). \
format(slug=engagement_slug.slug)
Expand Down Expand Up @@ -208,7 +223,8 @@ def validate_email_verification(email_verification: EmailVerificationSchema):
verification_created_datetime = datetime.strptime(
email_verification.get('created_date'), EmailVerificationService.datetime_format)
verification_expiry_datetime = verification_created_datetime + \
timedelta(hours=EmailVerificationService.verification_expiry_hours)
timedelta(
hours=EmailVerificationService.verification_expiry_hours)
if datetime.now() >= verification_expiry_datetime:
raise ValueError('Email verification is expired')

Expand Down
18 changes: 10 additions & 8 deletions met-api/templates/email_rejected_comment.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
<h1>Thank you for taking the time to provide your feedback on {{ engagement_name }}.</h1>
<p>We have reviewed your feedback and can't accept it for the following reason(s):</p>
<br />
<p>Your feedback contained:</p>
<p>We have reviewed your feedback and can't accept it for the following reason(s):</p>
<br>
<ul>
{% if has_personal_info %}
<li>
One or many of your comments contain personal information such as name,
address, or other information that could identify you.
Your feedback contains personal information
</li>
{% endif %} {% if has_profanity %}
<li>One or many of your comments contain swear words or profanities.</li>
<li> Your feedback contains profanity or innapropriate language</li>
{% endif %} {% if has_other_reason %}
<li>
One or many of your comments can't be published because of {{ other_reason
}}.
Your feedback contains {{ other_reason
}}
</li>
{% endif %}
</ul>
<br />
<p>You can edit and re-submit your feedback <a href='{{ submission_url }}'>here</a>.</p>
<p>{{review_notes}}</p>
<br/>
<p>You can edit and re-submit your feedback.</p>
<p>
The comment period is open until {{ end_date }}. You must re-submit
your feedback before the comment period closes.
</p>
<br />
<p><a href='{{ submission_url }}'>Edit Feedback</a></p>
<br />
<p>Thank you,</p>
<br />
<p>The {{tenant_name}} Team</p>
11 changes: 8 additions & 3 deletions met-api/templates/email_verification.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<h1>Share your feedback about {{ engagement_name }}.</h1>
<p>Please click the link below to provide your feedback. This link will expire in 24 hours and is only valid once. If the link has expired, you can request request access again by visiting <a href='{{ engagement_url }}'>{{ engagement_name }}</a>.</p>
<h1>Thank you for sharing your feedback about {{engagement_name}}.</h1>
<br />
<p>Click <a href='{{ survey_url }}'>here</a> to provide your feedback.<p>
<p>Please click the link below to provide your feedback.</p>
<br />
<p>Access will expire in 24 hours and is only valid once. If your access has expired, you can request access again at <a href='{{ engagement_url }}'>{{ engagement_url }}</a>.</p>
<br />
<p><a href='{{ survey_url }}'>Provide Feedback</a></p>
<br />
<p>Written public feedback will be posted as soon as it is reviewed and approved (within 7 days). A report will be available after the public comment period is over, starting on {{ end_date }}.</p>
<br />
<p>Thank you,</p>
<br />
Expand Down

0 comments on commit b7945e3

Please sign in to comment.