# 63 Mail data deleted

* adds mail sending if shared data is deleted
* adds/updates translations
* refactors recording mails into separate email template folder email/recording
This commit is contained in:
2022-01-12 15:31:25 +01:00
parent d7a9f72c3e
commit 5295c08d99
10 changed files with 160 additions and 68 deletions

View File

@@ -12,7 +12,7 @@ from abc import abstractmethod
from django.contrib import messages
from konova.tasks import celery_send_mail_shared_access_removed, celery_send_mail_shared_access_given, \
celery_send_mail_shared_data_recorded, celery_send_mail_shared_data_unrecorded
celery_send_mail_shared_data_recorded, celery_send_mail_shared_data_unrecorded, celery_send_mail_shared_data_deleted
from user.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpRequest
@@ -121,6 +121,12 @@ class BaseObject(BaseResource):
action = UserActionLogEntry.get_deleted_action(user)
self.deleted = action
self.log.add(action)
# Send mail
shared_users = self.users.all().values_list("id", flat=True)
for user_id in shared_users:
celery_send_mail_shared_data_deleted.delay(self.identifier, user_id)
self.save()
def add_log_entry(self, action: UserAction, user: User, comment: str):

View File

@@ -44,3 +44,10 @@ def celery_send_mail_shared_data_unrecorded(obj_identifier, user_id):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_data_unrecorded(obj_identifier)
@shared_task
def celery_send_mail_shared_data_deleted(obj_identifier, user_id):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_data_deleted(obj_identifier)

View File

@@ -94,7 +94,7 @@ class Mailer:
)
def send_mail_shared_data_recorded(self, obj_identifier, user):
""" Send a mail if user just got access to the object
""" Send a mail if the user's shared data has just been unrecorded
Args:
obj_identifier (str): The object identifier
@@ -107,7 +107,7 @@ class Mailer:
"obj_identifier": obj_identifier,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/sharing/shared_data_recorded.html", context)
msg = render_to_string("email/recording/shared_data_recorded.html", context)
user_mail_address = [user.email]
self.send(
user_mail_address,
@@ -116,6 +116,28 @@ class Mailer:
)
def send_mail_shared_data_unrecorded(self, obj_identifier, user):
""" Send a mail if the user's shared data has just been unrecorded
Args:
obj_identifier (str): The object identifier
Returns:
"""
context = {
"user": user,
"obj_identifier": obj_identifier,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/recording/shared_data_unrecorded.html", context)
user_mail_address = [user.email]
self.send(
user_mail_address,
_("{} - Shared data unrecorded").format(obj_identifier),
msg
)
def send_mail_shared_data_deleted(self, obj_identifier, user):
""" Send a mail if user just got access to the object
Args:
@@ -129,11 +151,11 @@ class Mailer:
"obj_identifier": obj_identifier,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
msg = render_to_string("email/sharing/shared_data_unrecorded.html", context)
msg = render_to_string("email/deleting/shared_data_deleted.html", context)
user_mail_address = [user.email]
self.send(
user_mail_address,
_("{} - Shared data unrecorded").format(obj_identifier),
_("{} - Shared data deleted").format(obj_identifier),
msg
)