# 63 Mail celery

* moves mail sending to celery worker using shared_task in konova/tasks.py
* adds mail sending for shared access given
* adds UserNotification settings checks for mail sending
* adds/updates translations
This commit is contained in:
2022-01-12 14:51:50 +01:00
parent 82778d1fec
commit eb54443aca
7 changed files with 147 additions and 20 deletions

View File

@@ -10,11 +10,17 @@ from django.contrib.auth.models import AbstractUser
from django.db import models
from konova.utils.mailer import Mailer
from user.enums import UserNotificationEnum
class User(AbstractUser):
notifications = models.ManyToManyField("user.UserNotification", related_name="+", blank=True)
def is_notification_setting_set(self, notification_enum: UserNotificationEnum):
return self.notifications.filter(
id=notification_enum.value
).exists()
def send_mail_shared_access_removed(self, obj_identifier):
""" Sends a mail to the user in case of removed shared access
@@ -24,5 +30,21 @@ class User(AbstractUser):
Returns:
"""
mailer = Mailer()
mailer.send_mail_shared_access_removed(obj_identifier, self)
notification_set = self.is_notification_setting_set(UserNotificationEnum.NOTIFY_ON_SHARED_ACCESS_REMOVED)
if notification_set:
mailer = Mailer()
mailer.send_mail_shared_access_removed(obj_identifier, self)
def send_mail_shared_access_given(self, obj_identifier):
""" Sends a mail to the user in case of removed shared access
Args:
obj ():
Returns:
"""
notification_set = self.is_notification_setting_set(UserNotificationEnum.NOTIFY_ON_SHARED_ACCESS_GAINED)
if notification_set:
mailer = Mailer()
mailer.send_mail_shared_access_given(obj_identifier, self)