# 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
pull/65/head
mpeltriaux 3 years ago
parent dbf32f3138
commit 17dc3f7537

@ -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)

@ -23,3 +23,10 @@ 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)
@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
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
)

Binary file not shown.

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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: "
#: 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."
"Der freigegebene Datensatz ist nun standardmäßig in Ihrer Übersicht für den Datensatztyp im KSP gelistet."
#: 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."

@ -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 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)

Loading…
Cancel
Save