diff --git a/konova/models/object.py b/konova/models/object.py index 175cf3a..8353a04 100644 --- a/konova/models/object.py +++ b/konova/models/object.py @@ -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): diff --git a/konova/tasks.py b/konova/tasks.py index ee7aabd..16925e5 100644 --- a/konova/tasks.py +++ b/konova/tasks.py @@ -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) diff --git a/konova/utils/mailer.py b/konova/utils/mailer.py index 107ac8c..b919164 100644 --- a/konova/utils/mailer.py +++ b/konova/utils/mailer.py @@ -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,7 +116,7 @@ class Mailer: ) def send_mail_shared_data_unrecorded(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 @@ -129,7 +129,7 @@ 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/recording/shared_data_unrecorded.html", context) user_mail_address = [user.email] self.send( user_mail_address, @@ -137,3 +137,25 @@ class Mailer: msg ) + def send_mail_shared_data_deleted(self, obj_identifier, user): + """ Send a mail if user just got access to the object + + 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/deleting/shared_data_deleted.html", context) + user_mail_address = [user.email] + self.send( + user_mail_address, + _("{} - Shared data deleted").format(obj_identifier), + msg + ) + diff --git a/locale/de/LC_MESSAGES/django.mo b/locale/de/LC_MESSAGES/django.mo index 77a5727..f2b82d6 100644 Binary files a/locale/de/LC_MESSAGES/django.mo and b/locale/de/LC_MESSAGES/django.mo differ diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index 012d25d..6f82e79 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -26,7 +26,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-01-12 15:06+0100\n" +"POT-Creation-Date: 2022-01-12 15:22+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1762,10 +1762,10 @@ msgid "{} - Shared access given" msgstr "{} - Zugriff freigegeben" #: konova/utils/mailer.py:114 -msgid "{} - Shared data recorded" -msgstr "{} - Freigegebene Daten verzeichnet" +msgid "{} - Shared data deleted" +msgstr "{} - Freigegebene Daten gelöscht" -#: konova/utils/mailer.py:136 +#: konova/utils/mailer.py:136 konova/utils/mailer.py:158 msgid "{} - Shared data unrecorded" msgstr "{} - Freigegebene Daten entzeichnet" @@ -1883,17 +1883,83 @@ msgstr "Alle" msgid "News" msgstr "Neuigkeiten" -#: templates/email/sharing/shared_access_given.html:4 -msgid "Access shared" -msgstr "Zugriff freigegeben" +#: templates/email/deleting/shared_data_deleted.html:4 +msgid "Shared data deleted" +msgstr "Freigegebene Daten gelöscht" +#: templates/email/deleting/shared_data_deleted.html:8 +#: templates/email/recording/shared_data_recorded.html:8 +#: templates/email/recording/shared_data_unrecorded.html:8 #: templates/email/sharing/shared_access_given.html:8 #: templates/email/sharing/shared_access_removed.html:8 -#: templates/email/sharing/shared_data_recorded.html:8 -#: templates/email/sharing/shared_data_unrecorded.html:8 msgid "Hello " msgstr "Hallo " +#: templates/email/deleting/shared_data_deleted.html:10 +msgid "the following dataset has just been deleted" +msgstr "der folgende Datensatz wurde soeben gelöscht " + +#: templates/email/deleting/shared_data_deleted.html:14 +msgid "" +"If this should not have been happened, please contact us. See the signature " +"for details." +msgstr "" +"Falls das nicht hätte passieren dürfen, kontaktieren Sie uns bitte. In der E-mail Signatur finden Sie " +"weitere Kontaktinformationen." + +#: templates/email/deleting/shared_data_deleted.html:17 +#: templates/email/recording/shared_data_recorded.html:17 +#: templates/email/recording/shared_data_unrecorded.html:17 +#: templates/email/sharing/shared_access_given.html:18 +#: templates/email/sharing/shared_access_removed.html:18 +msgid "Best regards" +msgstr "Beste Grüße" + +#: templates/email/recording/shared_data_recorded.html:4 +msgid "Shared data recorded" +msgstr "Freigegebene Daten verzeichnet" + +#: templates/email/recording/shared_data_recorded.html:10 +msgid "the following dataset has just been recorded" +msgstr "der folgende Datensatz wurde soeben verzeichnet " + +#: templates/email/recording/shared_data_recorded.html:14 +msgid "This means the data is now publicly available, e.g. in LANIS" +msgstr "" +"Das bedeutet, dass die Daten nun öffentlich verfügbar sind, z.B. im LANIS." + +#: templates/email/recording/shared_data_recorded.html:24 +msgid "" +"Please note: Recorded intervention means the compensations are recorded as " +"well." +msgstr "" +"Bitte beachten Sie: Verzeichnete Eingriffe bedeuten, dass auch die " +"zugehörigen Kompensationen automatisch verzeichnet sind." + +#: templates/email/recording/shared_data_unrecorded.html:4 +msgid "Shared data unrecorded" +msgstr "Freigegebene Daten entzeichnet" + +#: templates/email/recording/shared_data_unrecorded.html:10 +msgid "the following dataset has just been unrecorded" +msgstr "der folgende Datensatz wurde soeben entzeichnet " + +#: templates/email/recording/shared_data_unrecorded.html:14 +msgid "This means the data is no longer publicly available." +msgstr "Das bedeutet, dass die Daten nicht länger öffentlich verfügbar sind." + +#: templates/email/recording/shared_data_unrecorded.html:24 +msgid "" +"Please note: Unrecorded intervention means the compensations are unrecorded " +"as well." +msgstr "" +"Bitte beachten Sie: Entzeichnete Eingriffe bedeuten, dass auch die " +"zugehörigen Kompensationen automatisch entzeichnet worden sind." + +#: templates/email/sharing/shared_access_given.html:4 +msgid "Access shared" +msgstr "Zugriff freigegeben" + #: templates/email/sharing/shared_access_given.html:10 msgid "the following dataset has just been shared with you" msgstr "der folgende Datensatz wurde soeben für Sie freigegeben " @@ -1910,13 +1976,6 @@ msgstr "" "Der freigegebene Datensatz ist nun standardmäßig in Ihrer Übersicht für den " "Datensatztyp im KSP gelistet." -#: templates/email/sharing/shared_access_given.html:18 -#: templates/email/sharing/shared_access_removed.html:18 -#: templates/email/sharing/shared_data_recorded.html:17 -#: templates/email/sharing/shared_data_unrecorded.html:17 -msgid "Best regards" -msgstr "Beste Grüße" - #: templates/email/sharing/shared_access_given.html:25 msgid "" "Please note: Shared access on an intervention means you automatically have " @@ -1949,48 +2008,6 @@ msgstr "" "Nutzen Sie hierzu einfach die entsprechenden Suchfilter auf den " "Übersichtsseiten" -#: templates/email/sharing/shared_data_recorded.html:4 -msgid "Shared data recorded" -msgstr "Freigegebene Daten verzeichnet" - -#: templates/email/sharing/shared_data_recorded.html:10 -msgid "the following dataset has just been recorded" -msgstr "der folgende Datensatz wurde soeben verzeichnet " - -#: templates/email/sharing/shared_data_recorded.html:14 -msgid "This means the data is now publicly available, e.g. in LANIS" -msgstr "" -"Das bedeutet, dass die Daten nun öffentlich verfügbar sind, z.B. im LANIS." - -#: templates/email/sharing/shared_data_recorded.html:24 -msgid "" -"Please note: Recorded intervention means the compensations are recorded as " -"well." -msgstr "" -"Bitte beachten Sie: Verzeichnete Eingriffe bedeuten, dass auch die " -"zugehörigen Kompensationen automatisch verzeichnet sind." - -#: templates/email/sharing/shared_data_unrecorded.html:4 -msgid "Shared data unrecorded" -msgstr "Freigegebene Daten entzeichnet" - -#: templates/email/sharing/shared_data_unrecorded.html:10 -msgid "the following dataset has just been unrecorded" -msgstr "der folgende Datensatz wurde soeben entzeichnet " - -#: templates/email/sharing/shared_data_unrecorded.html:14 -msgid "This means the data is no longer publicly available." -msgstr "" -"Das bedeutet, dass die Daten nicht länger öffentlich verfügbar sind." - -#: templates/email/sharing/shared_data_unrecorded.html:24 -msgid "" -"Please note: Unrecorded intervention means the compensations are unrecorded " -"as well." -msgstr "" -"Bitte beachten Sie: Entzeichnete Eingriffe bedeuten, dass auch die " -"zugehörigen Kompensationen automatisch entzeichnet worden sind." - #: templates/email/signature.html:6 msgid "Please do not reply on this mail." msgstr "Bitte antworten Sie nicht auf diese Mail." @@ -3730,6 +3747,9 @@ msgstr "" msgid "Unable to connect to qpid with SASL mechanism %s" msgstr "" +#~ msgid "{} - Shared data recorded" +#~ msgstr "{} - Freigegebene Daten verzeichnet" + #~ msgid "Not recorded" #~ msgstr "Noch nicht verzeichnet" diff --git a/templates/email/deleting/shared_data_deleted.html b/templates/email/deleting/shared_data_deleted.html new file mode 100644 index 0000000..36c80b0 --- /dev/null +++ b/templates/email/deleting/shared_data_deleted.html @@ -0,0 +1,26 @@ +{% load i18n %} + +
+

{% trans 'Shared data deleted' %}

+

{{obj_identifier}}

+
+
+ {% trans 'Hello ' %} {{user.username}}, +
+ {% trans 'the following dataset has just been deleted' %} +
+ '{{obj_identifier}}' +
+ {% trans 'If this should not have been happened, please contact us. See the signature for details.' %} +
+
+ {% trans 'Best regards' %} +
+ KSP +
+
+
+ {% include 'email/signature.html' %} +
+
+ diff --git a/templates/email/sharing/shared_data_recorded.html b/templates/email/recording/shared_data_recorded.html similarity index 100% rename from templates/email/sharing/shared_data_recorded.html rename to templates/email/recording/shared_data_recorded.html diff --git a/templates/email/sharing/shared_data_unrecorded.html b/templates/email/recording/shared_data_unrecorded.html similarity index 100% rename from templates/email/sharing/shared_data_unrecorded.html rename to templates/email/recording/shared_data_unrecorded.html diff --git a/user/models/user.py b/user/models/user.py index 51c8bcf..12f138e 100644 --- a/user/models/user.py +++ b/user/models/user.py @@ -76,3 +76,17 @@ class User(AbstractUser): if notification_set: mailer = Mailer() mailer.send_mail_shared_data_unrecorded(obj_identifier, self) + + def send_mail_shared_data_deleted(self, obj_identifier): + """ Sends a mail to the user in case of shared data has been deleted + + Args: + obj_identifier (): + + Returns: + + """ + notification_set = self.is_notification_setting_set(UserNotificationEnum.NOTIFY_ON_SHARED_DATA_DELETED) + if notification_set: + mailer = Mailer() + mailer.send_mail_shared_data_deleted(obj_identifier, self) diff --git a/user/models/user_action.py b/user/models/user_action.py index 72e8615..d902c5d 100644 --- a/user/models/user_action.py +++ b/user/models/user_action.py @@ -49,9 +49,6 @@ class UserActionLogEntry(models.Model): "-timestamp", ) - def __str__(self): - return "{} | {} | {}".format(self.user.username, self.timestamp, self.action) - @property def action_humanize(self): """ Returns humanized version of enum