diff --git a/konova/models/object.py b/konova/models/object.py index 6451fb83..65b0c1a1 100644 --- a/konova/models/object.py +++ b/konova/models/object.py @@ -11,7 +11,7 @@ from abc import abstractmethod from django.contrib import messages -from konova.tasks import celery_send_mail_shared_access_removed +from konova.tasks import celery_send_mail_shared_access_removed, celery_send_mail_shared_access_given from user.models import User from django.core.exceptions import ObjectDoesNotExist from django.http import HttpRequest @@ -416,8 +416,14 @@ class ShareableObjectMixin(models.Model): removed_users = self.users.all().exclude( id__in=accessing_users ).values("id") + + # Send mails for user in removed_users: celery_send_mail_shared_access_removed.delay(self.identifier, user["id"]) + for user in new_accessing_users: + celery_send_mail_shared_access_given.delay(self.identifier, user) + + # Set new shared users self.share_with_list(users) diff --git a/konova/tasks.py b/konova/tasks.py index eb4e91d5..54956835 100644 --- a/konova/tasks.py +++ b/konova/tasks.py @@ -22,4 +22,11 @@ def celery_update_parcels(geometry_id: str, recheck: bool = True): def celery_send_mail_shared_access_removed(obj_identifier, user_id): from user.models import User user = User.objects.get(id=user_id) - user.send_mail_shared_access_removed(obj_identifier) \ No newline at end of file + user.send_mail_shared_access_removed(obj_identifier) + + +@shared_task +def celery_send_mail_shared_access_given(obj_identifier, user_id): + from user.models import User + user = User.objects.get(id=user_id) + user.send_mail_shared_access_given(obj_identifier) \ No newline at end of file diff --git a/konova/utils/mailer.py b/konova/utils/mailer.py index f3f2efb0..87ffe29d 100644 --- a/konova/utils/mailer.py +++ b/konova/utils/mailer.py @@ -53,7 +53,7 @@ class Mailer: """ Send a mail if user has no access to the object anymore Args: - obj (): + obj_identifier (str): The object identifier Returns: @@ -71,3 +71,25 @@ class Mailer: msg ) + def send_mail_shared_access_given(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/sharing/shared_access_given.html", context) + user_mail_address = [user.email] + self.send( + user_mail_address, + _("{} - Shared access given").format(obj_identifier), + msg + ) + diff --git a/locale/de/LC_MESSAGES/django.mo b/locale/de/LC_MESSAGES/django.mo index 3143958d..d9103b58 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 65277896..f1f99f9f 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 14:12+0100\n" +"POT-Creation-Date: 2022-01-12 14:31+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1757,6 +1757,10 @@ msgstr "Dokument '{}' gelöscht" msgid "{} - Shared access removed" msgstr "{} - Zugriff entzogen" +#: konova/utils/mailer.py:92 +msgid "{} - Shared access given" +msgstr "{} - Zugriff freigegeben" + #: konova/utils/message_templates.py:11 msgid "There was an error on this form." msgstr "Es gab einen Fehler im Formular." @@ -1871,32 +1875,66 @@ msgstr "Alle" msgid "News" msgstr "Neuigkeiten" -#: templates/email/sharing/shared_access_removed.html:2 -msgid "Shared access removed" -msgstr "Freigegebener Zugriff entzogen" +#: templates/email/sharing/shared_access_given.html:4 +msgid "Access shared" +msgstr "Zugriff freigegeben" -#: templates/email/sharing/shared_access_removed.html:6 +#: templates/email/sharing/shared_access_given.html:8 +#: templates/email/sharing/shared_access_removed.html:8 msgid "Hello " msgstr "Hallo " -#: templates/email/sharing/shared_access_removed.html:8 +#: 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 " + +#: templates/email/sharing/shared_access_given.html:14 +msgid "This means you can now edit this dataset." +msgstr "Das bedeutet, dass Sie diesen Datensatz nun auch bearbeiten können." + +#: templates/email/sharing/shared_access_given.html:15 msgid "" -"your shared access, including editing, has been revoked for the dataset " +"The shared dataset appears now by default on your overview for this dataset " +"type." msgstr "" -"Ihnen wurde soeben der bearbeitende Zugriff auf den folgenden Datensatz entzogen: " +"Der freigegebene Datensatz ist nun standardmäßig in Ihrer Übersicht für den Datensatztyp im KSP gelistet." -#: templates/email/sharing/shared_access_removed.html:13 -msgid "However, you are still able to view the dataset content." -msgstr "Sie können den Datensatz aber immer noch im KSP einsehen." - -#: templates/email/sharing/shared_access_removed.html:14 -msgid "Please use the provided search filter on the dataset`s overview pages to find them." -msgstr "Nutzen Sie hierzu einfach die entsprechenden Suchfilter auf den Übersichtsseiten" +#: templates/email/sharing/shared_access_given.html:16 +msgid "" +"Please note: Shared access on an intervention means you automatically have " +"editing access to related compensations." +msgstr "" +"Bitte beachten Sie: Freigegebener Zugriff auf einen Eingriff bedeutet, dass Sie automatisch auch " +"Zugriff auf die zugehörigen Kompensationen erhalten haben." +#: templates/email/sharing/shared_access_given.html:19 #: templates/email/sharing/shared_access_removed.html:18 msgid "Best regards" msgstr "Beste Grüße" +#: templates/email/sharing/shared_access_removed.html:4 +msgid "Shared access removed" +msgstr "Freigegebener Zugriff entzogen" + +#: templates/email/sharing/shared_access_removed.html:10 +msgid "" +"your shared access, including editing, has been revoked for the dataset " +msgstr "" +"Ihnen wurde soeben der bearbeitende Zugriff auf den folgenden Datensatz " +"entzogen: " + +#: templates/email/sharing/shared_access_removed.html:14 +msgid "However, you are still able to view the dataset content." +msgstr "Sie können den Datensatz aber immer noch im KSP einsehen." + +#: templates/email/sharing/shared_access_removed.html:15 +msgid "" +"Please use the provided search filter on the dataset`s overview pages to " +"find them." +msgstr "" +"Nutzen Sie hierzu einfach die entsprechenden Suchfilter auf den " +"Übersichtsseiten" + #: templates/email/signature.html:6 msgid "Please do not reply on this mail." msgstr "Bitte antworten Sie nicht auf diese Mail." diff --git a/templates/email/sharing/shared_access_given.html b/templates/email/sharing/shared_access_given.html new file mode 100644 index 00000000..bf93e863 --- /dev/null +++ b/templates/email/sharing/shared_access_given.html @@ -0,0 +1,32 @@ +{% load i18n %} + +
+

{% trans 'Access shared' %}

+

{{obj_identifier}}

+
+
+ {% trans 'Hello ' %} {{user.username}}, +
+ {% trans 'the following dataset has just been shared with you' %} +
+ '{{obj_identifier}}' +
+ {% trans 'This means you can now edit this dataset.' %} + {% trans 'The shared dataset appears now by default on your overview for this dataset type.' %} +
+
+ {% trans 'Best regards' %} +
+ KSP +
+
+
+ + {% trans 'Please note: Shared access on an intervention means you automatically have editing access to related compensations.' %} + +
+
+ {% include 'email/signature.html' %} +
+
+ diff --git a/user/models/user.py b/user/models/user.py index c55896ee..e8e6ae79 100644 --- a/user/models/user.py +++ b/user/models/user.py @@ -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)