Team mail fix

* filters team members by notification settings before sending team mails
This commit is contained in:
2022-11-14 07:19:04 +01:00
parent ddb1e82fbc
commit 11e5d82086
2 changed files with 59 additions and 22 deletions

View File

@@ -2,6 +2,7 @@ from django.db import models
from konova.models import UuidModel, DeletableObjectMixin
from konova.utils.mailer import Mailer
from user.enums import UserNotificationEnum
from user.models import UserActionLogEntry
@@ -41,7 +42,10 @@ class Team(UuidModel, DeletableObjectMixin):
"""
mailer = Mailer()
mailer.send_mail_shared_access_given_team(obj_identifier, obj_title, self)
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_ACCESS_GAINED.value]
)
mailer.send_mail_shared_access_given_team(obj_identifier, obj_title, self, users_to_notify)
def send_mail_shared_access_removed(self, obj_identifier, obj_title):
""" Sends a mail to the team members in case of removed shared access
@@ -54,7 +58,10 @@ class Team(UuidModel, DeletableObjectMixin):
"""
mailer = Mailer()
mailer.send_mail_shared_access_removed_team(obj_identifier, obj_title, self)
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_ACCESS_REMOVED.value]
)
mailer.send_mail_shared_access_removed_team(obj_identifier, obj_title, self, users_to_notify)
def send_mail_shared_data_unrecorded(self, obj_identifier, obj_title):
""" Sends a mail to the team members in case of unrecorded data
@@ -67,7 +74,10 @@ class Team(UuidModel, DeletableObjectMixin):
"""
mailer = Mailer()
mailer.send_mail_shared_data_unrecorded_team(obj_identifier, obj_title, self)
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_DATA_RECORDED.value]
)
mailer.send_mail_shared_data_unrecorded_team(obj_identifier, obj_title, self, users_to_notify)
def send_mail_shared_data_recorded(self, obj_identifier, obj_title):
""" Sends a mail to the team members in case of unrecorded data
@@ -80,7 +90,10 @@ class Team(UuidModel, DeletableObjectMixin):
"""
mailer = Mailer()
mailer.send_mail_shared_data_recorded_team(obj_identifier, obj_title, self)
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_DATA_RECORDED.value]
)
mailer.send_mail_shared_data_recorded_team(obj_identifier, obj_title, self, users_to_notify)
def send_mail_shared_data_checked(self, obj_identifier, obj_title):
""" Sends a mail to the team members in case of checked data
@@ -93,7 +106,10 @@ class Team(UuidModel, DeletableObjectMixin):
"""
mailer = Mailer()
mailer.send_mail_shared_data_checked_team(obj_identifier, obj_title, self)
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_DATA_CHECKED.value]
)
mailer.send_mail_shared_data_checked_team(obj_identifier, obj_title, self, users_to_notify)
def send_mail_deduction_changed(self, obj_identifier, obj_title, data_changes):
""" Sends a mail to the team members in case of changed deduction values
@@ -107,7 +123,10 @@ class Team(UuidModel, DeletableObjectMixin):
"""
mailer = Mailer()
mailer.send_mail_deduction_changed_team(obj_identifier, obj_title, self, data_changes)
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_DEDUCTION_CHANGES.value]
)
mailer.send_mail_deduction_changed_team(obj_identifier, obj_title, self, data_changes, users_to_notify)
def send_mail_shared_data_deleted(self, obj_identifier, obj_title):
""" Sends a mail to the team members in case of deleted data
@@ -120,7 +139,10 @@ class Team(UuidModel, DeletableObjectMixin):
"""
mailer = Mailer()
mailer.send_mail_shared_data_deleted_team(obj_identifier, obj_title, self)
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_DATA_DELETED.value]
)
mailer.send_mail_shared_data_deleted_team(obj_identifier, obj_title, self, users_to_notify)
def remove_user(self, user):
""" Removes a user from the team