From 7de4a3f2c5fab3428925cfb51d646b9579ba232f Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 30 Nov 2024 16:06:10 +0100 Subject: [PATCH] feat: Enhances registration notifications Adds moderator messages to registration emails. Introduces 'notify' flag to control email notifications. Improves customization of user communication during status updates. --- .../registration/models.py | 2 + .../registration/signals.py | 48 ++++++++++++------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/synapse_registration/registration/models.py b/src/synapse_registration/registration/models.py index 2dde4f6..a9a1aec 100644 --- a/src/synapse_registration/registration/models.py +++ b/src/synapse_registration/registration/models.py @@ -23,6 +23,8 @@ class UserRegistration(models.Model): status = models.IntegerField(choices=STATUS_CHOICES, default=STATUS_STARTED) token = models.CharField(max_length=64, unique=True) email_verified = models.BooleanField(default=False) + mod_message = models.TextField(blank=True, default="") + notify = models.BooleanField(default=True) timestamp = models.DateTimeField(auto_now_add=True) def __str__(self): diff --git a/src/synapse_registration/registration/signals.py b/src/synapse_registration/registration/signals.py index 809a602..e874c45 100644 --- a/src/synapse_registration/registration/signals.py +++ b/src/synapse_registration/registration/signals.py @@ -37,15 +37,21 @@ def handle_status_change(sender, instance, created, **kwargs): headers={"Authorization": f"Bearer {settings.SYNAPSE_ADMIN_TOKEN}"}, ) - try: - send_mail( - "Registration Approved", - f"Congratulations, {instance.username}! Your registration at {settings.MATRIX_DOMAIN} has been approved.", - settings.DEFAULT_FROM_EMAIL, - [instance.email], - ) - except SMTPRecipientsRefused: - pass + if instance.notify: + message = f"Congratulations, your registration request at {settings.MATRIX_DOMAIN} has been approved." + + if instance.mod_message: + message += f"\n\nMessage from moderator: {instance.mod_message}" + + try: + send_mail( + "Registration Approved", + message, + settings.DEFAULT_FROM_EMAIL, + [instance.email], + ) + except SMTPRecipientsRefused: + pass elif status == UserRegistration.STATUS_DENIED: response = requests.put( @@ -62,12 +68,18 @@ def handle_status_change(sender, instance, created, **kwargs): [settings.ADMIN_EMAIL], ) - try: - send_mail( - "Registration Denied", - f"Sorry, your registration request at {settings.MATRIX_DOMAIN} has been denied.", - settings.DEFAULT_FROM_EMAIL, - [instance.email], - ) - except SMTPRecipientsRefused: - pass \ No newline at end of file + if instance.notify: + message = f"Sorry, your registration request at {settings.MATRIX_DOMAIN} has been denied." + + if instance.mod_message: + message += f"\n\nMessage from moderator: {instance.mod_message}" + + try: + send_mail( + "Registration Denied", + message, + settings.DEFAULT_FROM_EMAIL, + [instance.email], + ) + except SMTPRecipientsRefused: + pass