# 63 Mail celery
* moves mail sending to celery worker using shared_task in konova/tasks.py * adds mail sending for shared access given * adds UserNotification settings checks for mail sending * adds/updates translations
This commit is contained in:
parent
dbf32f3138
commit
17dc3f7537
@ -11,7 +11,7 @@ from abc import abstractmethod
|
|||||||
|
|
||||||
from django.contrib import messages
|
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 user.models import User
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
@ -416,8 +416,14 @@ class ShareableObjectMixin(models.Model):
|
|||||||
removed_users = self.users.all().exclude(
|
removed_users = self.users.all().exclude(
|
||||||
id__in=accessing_users
|
id__in=accessing_users
|
||||||
).values("id")
|
).values("id")
|
||||||
|
|
||||||
|
# Send mails
|
||||||
for user in removed_users:
|
for user in removed_users:
|
||||||
celery_send_mail_shared_access_removed.delay(self.identifier, user["id"])
|
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)
|
self.share_with_list(users)
|
||||||
|
|
||||||
|
|
||||||
|
@ -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):
|
def celery_send_mail_shared_access_removed(obj_identifier, user_id):
|
||||||
from user.models import User
|
from user.models import User
|
||||||
user = User.objects.get(id=user_id)
|
user = User.objects.get(id=user_id)
|
||||||
user.send_mail_shared_access_removed(obj_identifier)
|
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)
|
@ -53,7 +53,7 @@ class Mailer:
|
|||||||
""" Send a mail if user has no access to the object anymore
|
""" Send a mail if user has no access to the object anymore
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
obj ():
|
obj_identifier (str): The object identifier
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
@ -71,3 +71,25 @@ class Mailer:
|
|||||||
msg
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
Binary file not shown.
@ -26,7 +26,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \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"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@ -1757,6 +1757,10 @@ msgstr "Dokument '{}' gelöscht"
|
|||||||
msgid "{} - Shared access removed"
|
msgid "{} - Shared access removed"
|
||||||
msgstr "{} - Zugriff entzogen"
|
msgstr "{} - Zugriff entzogen"
|
||||||
|
|
||||||
|
#: konova/utils/mailer.py:92
|
||||||
|
msgid "{} - Shared access given"
|
||||||
|
msgstr "{} - Zugriff freigegeben"
|
||||||
|
|
||||||
#: konova/utils/message_templates.py:11
|
#: konova/utils/message_templates.py:11
|
||||||
msgid "There was an error on this form."
|
msgid "There was an error on this form."
|
||||||
msgstr "Es gab einen Fehler im Formular."
|
msgstr "Es gab einen Fehler im Formular."
|
||||||
@ -1871,32 +1875,66 @@ msgstr "Alle"
|
|||||||
msgid "News"
|
msgid "News"
|
||||||
msgstr "Neuigkeiten"
|
msgstr "Neuigkeiten"
|
||||||
|
|
||||||
#: templates/email/sharing/shared_access_removed.html:2
|
#: templates/email/sharing/shared_access_given.html:4
|
||||||
msgid "Shared access removed"
|
msgid "Access shared"
|
||||||
msgstr "Freigegebener Zugriff entzogen"
|
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 "
|
msgid "Hello "
|
||||||
msgstr "Hallo "
|
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 ""
|
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 ""
|
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
|
#: templates/email/sharing/shared_access_given.html:16
|
||||||
msgid "However, you are still able to view the dataset content."
|
msgid ""
|
||||||
msgstr "Sie können den Datensatz aber immer noch im KSP einsehen."
|
"Please note: Shared access on an intervention means you automatically have "
|
||||||
|
"editing access to related compensations."
|
||||||
#: templates/email/sharing/shared_access_removed.html:14
|
msgstr ""
|
||||||
msgid "Please use the provided search filter on the dataset`s overview pages to find them."
|
"Bitte beachten Sie: Freigegebener Zugriff auf einen Eingriff bedeutet, dass Sie automatisch auch "
|
||||||
msgstr "Nutzen Sie hierzu einfach die entsprechenden Suchfilter auf den Übersichtsseiten"
|
"Zugriff auf die zugehörigen Kompensationen erhalten haben."
|
||||||
|
|
||||||
|
#: templates/email/sharing/shared_access_given.html:19
|
||||||
#: templates/email/sharing/shared_access_removed.html:18
|
#: templates/email/sharing/shared_access_removed.html:18
|
||||||
msgid "Best regards"
|
msgid "Best regards"
|
||||||
msgstr "Beste Grüße"
|
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
|
#: templates/email/signature.html:6
|
||||||
msgid "Please do not reply on this mail."
|
msgid "Please do not reply on this mail."
|
||||||
msgstr "Bitte antworten Sie nicht auf diese Mail."
|
msgstr "Bitte antworten Sie nicht auf diese Mail."
|
||||||
|
32
templates/email/sharing/shared_access_given.html
Normal file
32
templates/email/sharing/shared_access_given.html
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h2>{% trans 'Access shared' %}</h2>
|
||||||
|
<h4>{{obj_identifier}}</h4>
|
||||||
|
<hr>
|
||||||
|
<article>
|
||||||
|
{% trans 'Hello ' %} {{user.username}},
|
||||||
|
<br>
|
||||||
|
{% trans 'the following dataset has just been shared with you' %}
|
||||||
|
<br>
|
||||||
|
<strong>'{{obj_identifier}}'</strong>
|
||||||
|
<br>
|
||||||
|
{% trans 'This means you can now edit this dataset.' %}
|
||||||
|
{% trans 'The shared dataset appears now by default on your overview for this dataset type.' %}
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
{% trans 'Best regards' %}
|
||||||
|
<br>
|
||||||
|
KSP
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<small>
|
||||||
|
{% trans 'Please note: Shared access on an intervention means you automatically have editing access to related compensations.' %}
|
||||||
|
</small>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
{% include 'email/signature.html' %}
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
|
@ -10,11 +10,17 @@ from django.contrib.auth.models import AbstractUser
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from konova.utils.mailer import Mailer
|
from konova.utils.mailer import Mailer
|
||||||
|
from user.enums import UserNotificationEnum
|
||||||
|
|
||||||
|
|
||||||
class User(AbstractUser):
|
class User(AbstractUser):
|
||||||
notifications = models.ManyToManyField("user.UserNotification", related_name="+", blank=True)
|
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):
|
def send_mail_shared_access_removed(self, obj_identifier):
|
||||||
""" Sends a mail to the user in case of removed shared access
|
""" Sends a mail to the user in case of removed shared access
|
||||||
|
|
||||||
@ -24,5 +30,21 @@ class User(AbstractUser):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
mailer = Mailer()
|
notification_set = self.is_notification_setting_set(UserNotificationEnum.NOTIFY_ON_SHARED_ACCESS_REMOVED)
|
||||||
mailer.send_mail_shared_access_removed(obj_identifier, self)
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user