2022-01-12 12:56:22 +01:00
|
|
|
"""
|
|
|
|
Author: Michel Peltriaux
|
|
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
|
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
|
|
Created on: 15.11.21
|
|
|
|
|
|
|
|
"""
|
|
|
|
from django.contrib.auth.models import AbstractUser
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
from konova.utils.mailer import Mailer
|
2022-01-12 14:51:50 +01:00
|
|
|
from user.enums import UserNotificationEnum
|
2022-01-12 12:56:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
class User(AbstractUser):
|
|
|
|
notifications = models.ManyToManyField("user.UserNotification", related_name="+", blank=True)
|
|
|
|
|
2022-01-12 14:51:50 +01:00
|
|
|
def is_notification_setting_set(self, notification_enum: UserNotificationEnum):
|
|
|
|
return self.notifications.filter(
|
|
|
|
id=notification_enum.value
|
|
|
|
).exists()
|
|
|
|
|
2022-01-12 14:27:39 +01:00
|
|
|
def send_mail_shared_access_removed(self, obj_identifier):
|
2022-01-12 12:56:22 +01:00
|
|
|
""" Sends a mail to the user in case of removed shared access
|
|
|
|
|
|
|
|
Args:
|
2022-01-12 15:09:52 +01:00
|
|
|
obj_identifier ():
|
2022-01-12 12:56:22 +01:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2022-01-12 14:51:50 +01:00
|
|
|
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):
|
2022-01-12 15:09:52 +01:00
|
|
|
""" Sends a mail to the user in case of given shared access
|
2022-01-12 14:51:50 +01:00
|
|
|
|
|
|
|
Args:
|
2022-01-12 15:09:52 +01:00
|
|
|
obj_identifier ():
|
2022-01-12 14:51:50 +01:00
|
|
|
|
|
|
|
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)
|
2022-01-12 15:09:52 +01:00
|
|
|
|
|
|
|
def send_mail_shared_data_recorded(self, obj_identifier):
|
|
|
|
""" Sends a mail to the user in case of shared data has been recorded
|
|
|
|
|
|
|
|
Args:
|
|
|
|
obj_identifier ():
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
notification_set = self.is_notification_setting_set(UserNotificationEnum.NOTIFY_ON_SHARED_DATA_RECORDED)
|
|
|
|
if notification_set:
|
|
|
|
mailer = Mailer()
|
|
|
|
mailer.send_mail_shared_data_recorded(obj_identifier, self)
|
|
|
|
|
|
|
|
def send_mail_shared_data_unrecorded(self, obj_identifier):
|
|
|
|
""" Sends a mail to the user in case of shared data has been unrecorded
|
|
|
|
|
|
|
|
Args:
|
|
|
|
obj_identifier ():
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
notification_set = self.is_notification_setting_set(UserNotificationEnum.NOTIFY_ON_SHARED_DATA_RECORDED)
|
|
|
|
if notification_set:
|
|
|
|
mailer = Mailer()
|
|
|
|
mailer.send_mail_shared_data_unrecorded(obj_identifier, self)
|
2022-01-12 15:31:25 +01:00
|
|
|
|
|
|
|
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)
|
2022-01-12 15:48:47 +01:00
|
|
|
|
|
|
|
def send_mail_shared_data_checked(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_CHECKED)
|
|
|
|
if notification_set:
|
|
|
|
mailer = Mailer()
|
|
|
|
mailer.send_mail_shared_data_checked(obj_identifier, self)
|