From 536073d5ebef11516f026e507712e00818d1516c Mon Sep 17 00:00:00 2001 From: Amogh M Aradhya Date: Mon, 24 Jul 2023 13:40:47 +0530 Subject: [PATCH 1/2] Added password reset and comment report sms template --- .../notifications/account_notification.py | 39 ++++++++++++------- .../notifications/comment_notification.py | 15 +++++-- sample.env | 2 + 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/funnel/views/notifications/account_notification.py b/funnel/views/notifications/account_notification.py index c3bb18de3..7d3c14044 100644 --- a/funnel/views/notifications/account_notification.py +++ b/funnel/views/notifications/account_notification.py @@ -2,17 +2,37 @@ from __future__ import annotations -from flask import render_template, url_for +from flask import render_template from baseframe import _, __ from ... import app from ...models import AccountPasswordNotification, User -from ...transports.sms import OneLineTemplate -from ..helpers import shortlink +from ...transports.sms import SmsTemplate from ..notification import RenderNotification +class PasswordResetNotificationTemplate(SmsTemplate): + """DLT registered template for Password Reset.""" + + registered_template = ( + "Your password has been updated. If this was not authorized," + " reset your password or contact support at {#var#}." + "\n\nhttps://bye.li to unsubscribe -Hasgeek" + ) + template = ( + "Your password has been updated. If this was not authorized," + " reset your password or contact support at {email}." + "\n\nhttps://bye.li to unsubscribe -Hasgeek" + ) + plaintext_template = ( + "Your password has been updated. If this was not authorized," + " reset your password or contact support at {email}." + ) + + email: str + + @AccountPasswordNotification.renderer class RenderAccountPasswordNotification(RenderNotification): """Notify user when their password is changed.""" @@ -44,14 +64,7 @@ def email_content(self): 'notifications/user_password_set_email.html.jinja2', view=self ) - def sms(self) -> OneLineTemplate: - return OneLineTemplate( - text1=_( - "Your password has been updated. If this was not authorized, reset" - " your password or contact support at {email}." - ).format(email=app.config['SITE_SUPPORT_EMAIL']), - url=shortlink( - url_for('reset', _external=True, **self.tracking_tags('sms')), - shorter=True, - ), + def sms(self) -> PasswordResetNotificationTemplate: + return PasswordResetNotificationTemplate( + email=app.config.get('SITE_SUPPORT_EMAIL') ) diff --git a/funnel/views/notifications/comment_notification.py b/funnel/views/notifications/comment_notification.py index 990fa13c3..df6c6d443 100644 --- a/funnel/views/notifications/comment_notification.py +++ b/funnel/views/notifications/comment_notification.py @@ -19,7 +19,7 @@ NewCommentNotification, User, ) -from ...transports.sms import OneLineTemplate, SmsTemplate +from ...transports.sms import SmsTemplate from ..helpers import shortlink from ..notification import RenderNotification from .mixins import TemplateVarMixin @@ -76,6 +76,14 @@ class CommentProjectTemplate(TemplateVarMixin, SmsTemplate): url: str +class CommentReportReceivedTemplate(SmsTemplate): + registered_template = 'A comment has been reported as spam: {#var#} -Hasgeek' + template = 'A comment has been reported as spam: {url} -Hasgeek' + plaintext_template = 'A comment has been reported as spam: {url}' + + url: str + + @CommentReportReceivedNotification.renderer class RenderCommentReportReceivedNotification(RenderNotification): """Notify site admins when a comment report is received.""" @@ -101,9 +109,8 @@ def email_content(self) -> str: 'notifications/comment_report_received_email.html.jinja2', view=self ) - def sms(self) -> OneLineTemplate: - return OneLineTemplate( - text1=_("A comment has been reported as spam."), + def sms(self) -> CommentReportReceivedTemplate: + return CommentReportReceivedTemplate( url=shortlink( url_for( 'siteadmin_review_comment', diff --git a/sample.env b/sample.env index 7c1fdc651..856aa7a68 100644 --- a/sample.env +++ b/sample.env @@ -197,3 +197,5 @@ FLASK_SMS_DLT_TEMPLATE_IDS__update_template=null FLASK_SMS_DLT_TEMPLATE_IDS__comment_project_template=null FLASK_SMS_DLT_TEMPLATE_IDS__comment_proposal_template=null FLASK_SMS_DLT_TEMPLATE_IDS__comment_reply_template=null +FLASK_SMS_DLT_TEMPLATE_IDS__comment_report_received_template=null +FLASK_SMS_DLT_TEMPLATE_IDS__password_reset_notification_template=null From 1a62da15d89f3441f6f5df98bb73d1c0de5acde3 Mon Sep 17 00:00:00 2001 From: Amogh M Aradhya Date: Wed, 27 Sep 2023 15:05:51 +0530 Subject: [PATCH 2/2] merged main --- funnel/views/notifications/account_notification.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/funnel/views/notifications/account_notification.py b/funnel/views/notifications/account_notification.py index 6f79725ea..f8f63140b 100644 --- a/funnel/views/notifications/account_notification.py +++ b/funnel/views/notifications/account_notification.py @@ -7,9 +7,8 @@ from baseframe import _, __ from ... import app -from ...models import AccountPasswordNotification -from ...transports.sms import SmsTemplate from ...models import Account, AccountPasswordNotification +from ...transports.sms import SmsTemplate from ..notification import RenderNotification