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

@@ -92,11 +92,14 @@ class Mailer:
msg
)
def send_mail_shared_access_given_team(self, obj_identifier, obj_title, team):
def send_mail_shared_access_given_team(self, obj_identifier, obj_title, team, users_to_notify):
""" Send a mail if a team just got access to the object
Args:
obj_identifier (str): The object identifier
obj_title (str): Title of the main object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
Returns:
@@ -108,18 +111,21 @@ class Mailer:
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/sharing/shared_access_given_team.html", context)
user_mail_address = team.users.values_list("email", flat=True)
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared access given").format(obj_identifier),
msg
)
def send_mail_shared_access_removed_team(self, obj_identifier, obj_title, team):
def send_mail_shared_access_removed_team(self, obj_identifier, obj_title, team, users_to_notify):
""" Send a mail if a team just lost access to the object
Args:
obj_identifier (str): The object identifier
obj_title (str): Title of the main object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
Returns:
@@ -131,18 +137,21 @@ class Mailer:
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/sharing/shared_access_removed_team.html", context)
user_mail_address = team.users.values_list("email", flat=True)
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared access removed").format(obj_identifier),
msg
)
def send_mail_shared_data_unrecorded_team(self, obj_identifier, obj_title, team):
def send_mail_shared_data_unrecorded_team(self, obj_identifier, obj_title, team, users_to_notify):
""" Send a mail if data has just been unrecorded
Args:
obj_identifier (str): The object identifier
obj_title (str): Title of the main object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
Returns:
@@ -154,18 +163,21 @@ class Mailer:
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/recording/shared_data_unrecorded_team.html", context)
user_mail_address = team.users.values_list("email", flat=True)
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared data unrecorded").format(obj_identifier),
msg
)
def send_mail_shared_data_recorded_team(self, obj_identifier, obj_title, team):
def send_mail_shared_data_recorded_team(self, obj_identifier, obj_title, team, users_to_notify):
""" Send a mail if data has just been recorded
Args:
obj_identifier (str): The object identifier
obj_title (str): Title of the main object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
Returns:
@@ -177,18 +189,21 @@ class Mailer:
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/recording/shared_data_recorded_team.html", context)
user_mail_address = team.users.values_list("email", flat=True)
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared data recorded").format(obj_identifier),
msg
)
def send_mail_shared_data_checked_team(self, obj_identifier, obj_title, team):
def send_mail_shared_data_checked_team(self, obj_identifier, obj_title, team, users_to_notify):
""" Send a mail if data has just been checked
Args:
obj_identifier (str): The object identifier
obj_title (str): Title of the main object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
Returns:
@@ -200,14 +215,14 @@ class Mailer:
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/checking/shared_data_checked_team.html", context)
user_mail_address = team.users.values_list("email", flat=True)
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared data checked").format(obj_identifier),
msg
)
def send_mail_deduction_changed_team(self, obj_identifier, obj_title, team, data_changes):
def send_mail_deduction_changed_team(self, obj_identifier, obj_title, team, data_changes, users_to_notify):
""" Send a mail if deduction has been changed
Args:
@@ -215,7 +230,7 @@ class Mailer:
obj_title (str): Title of the main object
team (Team): Team to be notified
data_changes (dict): Contains the old|new changes of the deduction changes
users_to_notify (QueryDict): Contains the team users which should be notified
Returns:
"""
@@ -227,14 +242,14 @@ class Mailer:
"data_changes": data_changes,
}
msg = render_to_string("email/other/deduction_changed_team.html", context)
user_mail_address = team.users.values_list("email", flat=True)
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Deduction changed").format(obj_identifier),
msg
)
def send_mail_shared_data_deleted_team(self, obj_identifier, obj_title, team):
def send_mail_shared_data_deleted_team(self, obj_identifier, obj_title, team, users_to_notify):
""" Send a mail if data has just been deleted
Args:
@@ -250,7 +265,7 @@ class Mailer:
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/deleting/shared_data_deleted_team.html", context)
user_mail_address = team.users.values_list("email", flat=True)
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared data deleted").format(obj_identifier),