Merge pull request 'master' (#372) from master into Docker

Reviewed-on: SGD-Nord/konova#372
pull/380/head
mpeltriaux 10 months ago
commit 7c666fcb06

@ -0,0 +1,18 @@
# Generated by Django 4.2.6 on 2023-11-30 11:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='apiusertoken',
name='valid_until',
field=models.DateField(blank=True, help_text='Token is only valid until this date. Forever if null/blank.', null=True),
),
]

@ -0,0 +1,70 @@
# Generated by Django 4.2.6 on 2023-11-30 11:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('codelist', '0001_initial'),
('konova', '0014_resubmission'),
('compensation', '0014_auto_20221118_1620'),
]
operations = [
migrations.AlterField(
model_name='compensation',
name='after_states',
field=models.ManyToManyField(blank=True, help_text="Refers to 'Zielzustand Biotop'", related_name='+', to='compensation.compensationstate'),
),
migrations.AlterField(
model_name='compensation',
name='before_states',
field=models.ManyToManyField(blank=True, help_text="Refers to 'Ausgangszustand Biotop'", related_name='+', to='compensation.compensationstate'),
),
migrations.AlterField(
model_name='compensation',
name='deadlines',
field=models.ManyToManyField(blank=True, related_name='+', to='konova.deadline'),
),
migrations.AlterField(
model_name='compensation',
name='resubmissions',
field=models.ManyToManyField(blank=True, related_name='+', to='konova.resubmission'),
),
migrations.AlterField(
model_name='compensationaction',
name='action_type',
field=models.ManyToManyField(blank=True, limit_choices_to={'code_lists__in': [1026], 'is_archived': False, 'is_selectable': True}, related_name='+', to='codelist.konovacode'),
),
migrations.AlterField(
model_name='compensationaction',
name='action_type_details',
field=models.ManyToManyField(blank=True, limit_choices_to={'code_lists__in': [1035], 'is_archived': False, 'is_selectable': True}, related_name='+', to='codelist.konovacode'),
),
migrations.AlterField(
model_name='compensationstate',
name='biotope_type_details',
field=models.ManyToManyField(blank=True, limit_choices_to={'code_lists__in': [975], 'is_archived': False, 'is_selectable': True}, related_name='+', to='codelist.konovacode'),
),
migrations.AlterField(
model_name='ecoaccount',
name='after_states',
field=models.ManyToManyField(blank=True, help_text="Refers to 'Zielzustand Biotop'", related_name='+', to='compensation.compensationstate'),
),
migrations.AlterField(
model_name='ecoaccount',
name='before_states',
field=models.ManyToManyField(blank=True, help_text="Refers to 'Ausgangszustand Biotop'", related_name='+', to='compensation.compensationstate'),
),
migrations.AlterField(
model_name='ecoaccount',
name='deadlines',
field=models.ManyToManyField(blank=True, related_name='+', to='konova.deadline'),
),
migrations.AlterField(
model_name='ecoaccount',
name='resubmissions',
field=models.ManyToManyField(blank=True, related_name='+', to='konova.resubmission'),
),
]

@ -8,11 +8,13 @@ Created on: 16.11.21
import shutil
from django.contrib import messages
from django.urls import reverse
from analysis.settings import LKOMPVZVO_PUBLISH_DATE
from codelist.models import KonovaCode
from compensation.settings import COMPENSATION_IDENTIFIER_TEMPLATE, COMPENSATION_IDENTIFIER_LENGTH, \
COMPENSATION_LANIS_LAYER_NAME_RECORDED, COMPENSATION_LANIS_LAYER_NAME_UNRECORDED, COMPENSATION_LANIS_LAYER_NAME_UNRECORDED_OLD_ENTRY
from konova.sub_settings.django_settings import BASE_URL
from user.models import User, Team
from django.db import models, transaction
from django.db.models import QuerySet, Sum
@ -307,6 +309,13 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin, PikMixin):
def __str__(self):
return "{}".format(self.identifier)
def get_detail_url(self):
return reverse("compensation:detail", args=(self.id,))
def get_detail_url_absolute(self):
return BASE_URL + self.get_detail_url()
def save(self, *args, **kwargs):
if self.identifier is None or len(self.identifier) == 0:
# Create new identifier is none was given

@ -11,6 +11,7 @@ from django.urls import reverse
from compensation.settings import ECO_ACCOUNT_IDENTIFIER_TEMPLATE, ECO_ACCOUNT_IDENTIFIER_LENGTH, \
ECO_ACCOUNT_LANIS_LAYER_NAME_RECORDED, ECO_ACCOUNT_LANIS_LAYER_NAME_UNRECORDED
from konova.sub_settings.django_settings import BASE_URL
from konova.utils.message_templates import DEDUCTION_REMOVED, DOCUMENT_REMOVED_TEMPLATE
from django.core.validators import MinValueValidator
from django.db import models
@ -58,6 +59,12 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
def __str__(self):
return f"{self.identifier} ({self.title})"
def get_detail_url(self):
return reverse("compensation:acc:detail", args=(self.id,))
def get_detail_url_absolute(self):
return BASE_URL + self.get_detail_url()
def save(self, *args, **kwargs):
if self.identifier is None or len(self.identifier) == 0:
# Create new identifier if none was given
@ -161,12 +168,12 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
# Send mail
shared_users = self.shared_users.values_list("id", flat=True)
for user_id in shared_users:
celery_send_mail_deduction_changed.delay(self.identifier, self.title, user_id, data_change)
celery_send_mail_deduction_changed.delay(self.id, self.get_app_object_tuple(), user_id, data_change)
# Send mail
shared_teams = self.shared_teams.values_list("id", flat=True)
for team_id in shared_teams:
celery_send_mail_deduction_changed_team.delay(self.identifier, self.title, team_id, data_change)
celery_send_mail_deduction_changed_team.delay(self.id, self.get_app_object_tuple(), team_id, data_change)
def update_deductable_rest(self):
"""

@ -0,0 +1,35 @@
# Generated by Django 4.2.6 on 2023-11-30 11:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('compensation', '0015_alter_compensation_after_states_and_more'),
('konova', '0014_resubmission'),
('ema', '0008_auto_20221116_1322'),
]
operations = [
migrations.AlterField(
model_name='ema',
name='after_states',
field=models.ManyToManyField(blank=True, help_text="Refers to 'Zielzustand Biotop'", related_name='+', to='compensation.compensationstate'),
),
migrations.AlterField(
model_name='ema',
name='before_states',
field=models.ManyToManyField(blank=True, help_text="Refers to 'Ausgangszustand Biotop'", related_name='+', to='compensation.compensationstate'),
),
migrations.AlterField(
model_name='ema',
name='deadlines',
field=models.ManyToManyField(blank=True, related_name='+', to='konova.deadline'),
),
migrations.AlterField(
model_name='ema',
name='resubmissions',
field=models.ManyToManyField(blank=True, related_name='+', to='konova.resubmission'),
),
]

@ -19,6 +19,7 @@ from ema.settings import EMA_IDENTIFIER_LENGTH, EMA_IDENTIFIER_TEMPLATE, EMA_LAN
EMA_LANIS_LAYER_NAME_UNRECORDED
from ema.utils.quality import EmaQualityChecker
from konova.models import AbstractDocument, generate_document_file_upload_path, RecordableObjectMixin, ShareableObjectMixin
from konova.sub_settings.django_settings import BASE_URL
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, DOCUMENT_REMOVED_TEMPLATE
@ -46,6 +47,12 @@ class Ema(AbstractCompensation, ShareableObjectMixin, RecordableObjectMixin, Pik
def __str__(self):
return "{}".format(self.identifier)
def get_detail_url(self):
return reverse("ema:detail", args=(self.id,))
def get_detail_url_absolute(self):
return BASE_URL + self.get_detail_url()
def save(self, *args, **kwargs):
if self.identifier is None or len(self.identifier) == 0:
# Create new identifier

@ -0,0 +1,19 @@
# Generated by Django 4.2.6 on 2023-11-30 11:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('konova', '0014_resubmission'),
('intervention', '0008_auto_20221116_1322'),
]
operations = [
migrations.AlterField(
model_name='intervention',
name='resubmissions',
field=models.ManyToManyField(blank=True, related_name='+', to='konova.resubmission'),
),
]

@ -18,6 +18,7 @@ from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_I
INTERVENTION_LANIS_LAYER_NAME_RECORDED, INTERVENTION_LANIS_LAYER_NAME_UNRECORDED_OLD_ENTRY, \
INTERVENTION_LANIS_LAYER_NAME_UNRECORDED
from intervention.tasks import celery_export_to_egon
from konova.sub_settings.django_settings import BASE_URL
from user.models import User
from django.db import models, transaction
from django.db.models import QuerySet
@ -69,6 +70,12 @@ class Intervention(BaseObject,
def __str__(self):
return f"{self.identifier} ({self.title})"
def get_detail_url(self):
return reverse("intervention:detail", args=(self.id,))
def get_detail_url_absolute(self):
return BASE_URL + self.get_detail_url()
def save(self, *args, **kwargs):
""" Custom save functionality

@ -116,14 +116,13 @@ class DeletableObjectMixin(models.Model):
if send_mail:
# Send mail
shared_users = self.shared_users.values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user_id in shared_users:
celery_send_mail_shared_data_deleted.delay(self.identifier, self.title, user_id, municipals_names)
celery_send_mail_shared_data_deleted.delay(self.id, self.get_app_object_tuple(), user_id)
# Send mail
shared_teams = self.shared_teams.values_list("id", flat=True)
for team_id in shared_teams:
celery_send_mail_shared_data_deleted_team.delay(self.identifier, self.title, team_id, municipals_names)
celery_send_mail_shared_data_deleted_team.delay(self.id, self.get_app_object_tuple(), team_id)
self.save()
@ -216,6 +215,14 @@ class BaseObject(BaseResource, DeletableObjectMixin):
def get_detail_url(self):
raise NotImplementedError()
def get_app_object_tuple(self):
""" Getter for a tuple, consisting of app and object name of the object
Returns:
tuple (tuple)
"""
return (self._meta.app_label, self._meta.object_name)
class RecordableObjectMixin(models.Model):
""" Wraps record related fields and functionality
@ -253,13 +260,12 @@ class RecordableObjectMixin(models.Model):
shared_users = self.shared_users.values_list("id", flat=True)
shared_teams = self.shared_teams.values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user_id in shared_users:
celery_send_mail_shared_data_unrecorded.delay(self.identifier, self.title, user_id, municipals_names)
celery_send_mail_shared_data_unrecorded.delay(self.id, self.get_app_object_tuple(), user_id)
for team_id in shared_teams:
celery_send_mail_shared_data_unrecorded_team.delay(self.identifier, self.title, team_id, municipals_names)
celery_send_mail_shared_data_unrecorded_team.delay(self.id, self.get_app_object_tuple(), team_id)
return action
@ -284,13 +290,12 @@ class RecordableObjectMixin(models.Model):
shared_users = self.shared_users.values_list("id", flat=True)
shared_teams = self.shared_teams.values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user_id in shared_users:
celery_send_mail_shared_data_recorded.delay(self.identifier, self.title, user_id, municipals_names)
celery_send_mail_shared_data_recorded.delay(self.id, self.get_app_object_tuple(), user_id)
for team_id in shared_teams:
celery_send_mail_shared_data_recorded_team.delay(self.identifier, self.title, team_id, municipals_names)
celery_send_mail_shared_data_recorded_team.delay(self.id, self.get_app_object_tuple(), team_id)
return action
@ -361,17 +366,15 @@ class CheckableObjectMixin(models.Model):
self.checked = action
self.save()
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
# Send mail
shared_users = self.shared_users.values_list("id", flat=True)
for user_id in shared_users:
celery_send_mail_shared_data_checked.delay(self.identifier, self.title, user_id, municipals_names)
celery_send_mail_shared_data_checked.delay(self.id, self.get_app_object_tuple(), user_id)
# Send mail
shared_teams = self.shared_teams.values_list("id", flat=True)
for team_id in shared_teams:
celery_send_mail_shared_data_checked_team.delay(self.identifier, self.title, team_id, municipals_names)
celery_send_mail_shared_data_checked_team.delay(self.id, self.get_app_object_tuple(), team_id)
self.log.add(action)
return action
@ -554,11 +557,10 @@ class ShareableObjectMixin(models.Model):
id__in=shared_teams
).values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for team_id in new_teams:
celery_send_mail_shared_access_given_team.delay(self.identifier, self.title, team_id, municipals_names)
celery_send_mail_shared_access_given_team.delay(self.id, self.get_app_object_tuple(), team_id)
for team_id in removed_teams:
celery_send_mail_shared_access_removed_team.delay(self.identifier, self.title, team_id, municipals_names)
celery_send_mail_shared_access_removed_team.delay(self.id, self.get_app_object_tuple(), team_id)
self.share_with_team_list(accessing_teams)
@ -583,12 +585,11 @@ class ShareableObjectMixin(models.Model):
id__in=shared_users
).values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
# Send mails
for user_id in removed_users:
celery_send_mail_shared_access_removed.delay(self.identifier, self.title, user_id, municipals_names)
celery_send_mail_shared_access_removed.delay(self.id, self.get_app_object_tuple(), user_id)
for user_id in new_users:
celery_send_mail_shared_access_given.delay(self.identifier, self.title, user_id, municipals_names)
celery_send_mail_shared_access_given.delay(self.id, self.get_app_object_tuple(), user_id)
# Set new shared users
self.share_with_user_list(accessing_users)
@ -650,9 +651,8 @@ class ShareableObjectMixin(models.Model):
default_users.append(user)
self.share_with_user_list(cleaned_users)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user in default_users:
celery_send_mail_shared_access_removed.delay(self.identifier, self.title, user.id, municipals_names)
celery_send_mail_shared_access_removed.delay(self.id, self.get_app_object_tuple(), user.id)
class GeoReferencedMixin(models.Model):
@ -744,6 +744,5 @@ class ResubmitableObjectMixin(models.Model):
"""
resubmissions = self.resubmissions.all()
municipal_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for resubmission in resubmissions:
resubmission.send_resubmission_mail(self.identifier, municipal_names)
resubmission.send_resubmission_mail(self.id, self.get_app_object_tuple())

@ -6,6 +6,7 @@ Created on: 15.08.22
"""
from dateutil.utils import today
from django.apps import apps
from django.db import models
from konova.models import BaseResource
@ -31,16 +32,20 @@ class Resubmission(BaseResource):
help_text="Optional comment for the user itself"
)
def send_resubmission_mail(self, obj_identifier, municipal_names):
def send_resubmission_mail(self, obj_id, obj_class):
""" Sends a resubmission mail
"""
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipal_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
_today = today().date()
resubmission_handled = _today.__ge__(self.resubmit_on) and self.resubmission_sent
if resubmission_handled:
return
mailer = Mailer()
mailer.send_mail_resubmission(obj_identifier, self, municipal_names)
mailer.send_mail_resubmission(obj, self, municipal_names)
self.resubmission_sent = True
self.save()

@ -19,6 +19,7 @@ from konova.sub_settings.sso_settings import *
from konova.sub_settings.table_settings import *
from konova.sub_settings.lanis_settings import *
from konova.sub_settings.wfs_parcel_settings import *
from konova.sub_settings.logging_settings import *
# Max upload size for POST forms
DATA_UPLOAD_MAX_MEMORY_SIZE = 5242880

@ -37,6 +37,8 @@ ADMINS = [
('KSP-Servicestelle', 'ksp-servicestelle@sgdnord.rlp.de'),
]
BASE_URL = "http://localhost:8001"
ALLOWED_HOSTS = [
"127.0.0.1",
"localhost",

@ -0,0 +1,8 @@
"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 11.12.23
"""
DEFAULT_EXCEPTION_REPORTER = "konova.utils.exception_reporter.KonovaExceptionReporter"

@ -1,6 +1,7 @@
from time import sleep
from celery import shared_task
from django.apps import apps
from django.core.exceptions import ObjectDoesNotExist
@ -25,101 +26,167 @@ def celery_update_parcels(geometry_id: str, recheck: bool = True):
@shared_task
def celery_send_mail_shared_access_removed(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
def celery_send_mail_shared_access_removed(obj_id, obj_class, user_id=None):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_access_removed(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_access_removed(obj, municipals_names)
@shared_task
def celery_send_mail_shared_access_given(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
def celery_send_mail_shared_access_given(obj_id, obj_class, user_id=None):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_access_given(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_access_given(obj, municipals_names)
@shared_task
def celery_send_mail_shared_access_removed_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
def celery_send_mail_shared_access_removed_team(obj_id, obj_class, team_id=None):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_access_removed(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_access_removed(obj, municipals_names)
@shared_task
def celery_send_mail_shared_access_given_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
def celery_send_mail_shared_access_given_team(obj_id, obj_class, team_id=None):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_access_given_team(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_access_given_team(obj, municipals_names)
@shared_task
def celery_send_mail_shared_data_recorded(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
def celery_send_mail_shared_data_recorded(obj_id, obj_class, user_id=None):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_data_recorded(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_data_recorded(obj, municipals_names)
@shared_task
def celery_send_mail_shared_data_unrecorded(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
def celery_send_mail_shared_data_unrecorded(obj_id, obj_class, user_id=None):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_data_unrecorded(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_data_unrecorded(obj, municipals_names)
@shared_task
def celery_send_mail_shared_data_recorded_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
def celery_send_mail_shared_data_recorded_team(obj_id, obj_class, team_id=None):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_data_recorded(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_data_recorded(obj, municipals_names)
@shared_task
def celery_send_mail_shared_data_unrecorded_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
def celery_send_mail_shared_data_unrecorded_team(obj_id, obj_class, team_id=None):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_data_unrecorded(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_data_unrecorded(obj, municipals_names)
@shared_task
def celery_send_mail_shared_data_deleted(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
def celery_send_mail_shared_data_deleted(obj_id, obj_class, user_id=None):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_data_deleted(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_data_deleted(obj, municipals_names)
@shared_task
def celery_send_mail_shared_data_checked(obj_identifier, obj_title=None, user_id=None, municipals_names=[]):
def celery_send_mail_shared_data_checked(obj_id, obj_class, user_id=None):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_shared_data_checked(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_data_checked(obj, municipals_names)
@shared_task
def celery_send_mail_shared_data_deleted_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
def celery_send_mail_shared_data_deleted_team(obj_id, obj_class, team_id=None):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_data_deleted(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_data_deleted(obj, municipals_names)
@shared_task
def celery_send_mail_shared_data_checked_team(obj_identifier, obj_title=None, team_id=None, municipals_names=[]):
def celery_send_mail_shared_data_checked_team(obj_id, obj_class, team_id=None):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_shared_data_checked(obj_identifier, obj_title, municipals_names)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_data_checked(obj, municipals_names)
@shared_task
def celery_send_mail_deduction_changed_team(obj_identifier, obj_title=None, team_id=None, data_changes=None):
def celery_send_mail_deduction_changed_team(obj_id, obj_class, team_id=None, data_changes=None):
from user.models import Team
team = Team.objects.get(id=team_id)
team.send_mail_deduction_changed(obj_identifier, obj_title, data_changes)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
team.send_mail_deduction_changed(obj, data_changes)
@shared_task
def celery_send_mail_deduction_changed(obj_identifier, obj_title=None, user_id=None, data_changes=None):
def celery_send_mail_deduction_changed(obj_id, obj_class, user_id=None, data_changes=None):
from user.models import User
user = User.objects.get(id=user_id)
user.send_mail_deduction_changed(obj_identifier, obj_title, data_changes)
obj_class = apps.get_model(obj_class[0], obj_class[1])
obj = obj_class.objects.get(id=obj_id)
user.send_mail_deduction_changed(obj, data_changes)
@shared_task

@ -193,9 +193,7 @@ class ResubmissionTestCase(BaseTestCase):
self.assertFalse(resubmission.resubmission_sent)
resubmission.send_resubmission_mail(
self.intervention.identifier,
[
"Test_municipal_1"
],
self.intervention.id,
self.intervention.get_app_object_tuple()
)
self.assertTrue(resubmission.resubmission_sent)

@ -0,0 +1,62 @@
"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 11.12.23
"""
from django.views.debug import ExceptionReporter
class KonovaExceptionReporter(ExceptionReporter):
""" Custom exception reporter class
Adapts the base functionality of ExceptionReporter but adds whitelist filtering to prevent sensitive data
to be exploitable via mail delivery.
References:
https://docs.djangoproject.com/en/4.2/ref/logging/#handlers
"""
def _filter_traceback_data(self, tb_data: dict):
""" Filters given traceback data according to whitelist
Args:
tb_data (dict): Aggregates traceback data
Returns:
clean_data (dict): Whitelist based filtered traceback data
"""
whitelist = [
"is_email",
"unicdoe_hint",
"frames",
"request",
"user_str",
"sys_executable",
"sys_version_info",
"raising_view_name",
"exception_type",
"exception_value",
]
clean_data = dict()
for entry in whitelist:
try:
clean_data[entry] = tb_data[entry]
except KeyError:
continue
return clean_data
def get_traceback_data(self):
""" Custom traceback data aggregation
Returns:
tb_data (dict): The traceback data
"""
tb_data = super().get_traceback_data()
if self.is_email:
tb_data = self._filter_traceback_data(tb_data)
return tb_data

@ -45,12 +45,11 @@ class Mailer:
auth_password=self.auth_password
)
def send_mail_shared_access_removed(self, obj_identifier, obj_title, user, municipals_names):
def send_mail_shared_access_removed(self, obj, user, municipals_names):
""" Send a mail if user has no access to the object anymore
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
obj (): The object
user (User): Related user
municipals_names (iterable): List of municipals of the entry
@ -59,8 +58,7 @@ class Mailer:
"""
context = {
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -68,16 +66,15 @@ class Mailer:
user_mail_address = [user.email]
self.send(
user_mail_address,
_("{} - Shared access removed").format(obj_identifier),
_("{} - Shared access removed").format(obj.identifier),
msg
)
def send_mail_shared_access_given(self, obj_identifier, obj_title, user, municipals_names):
def send_mail_shared_access_given(self, obj, user, municipals_names):
""" Send a mail if user just got access to the object
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
obj (): The object
user (User): The related user
municipals_names (iterable): List of municipals for this entry
@ -86,8 +83,7 @@ class Mailer:
"""
context = {
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -95,16 +91,15 @@ class Mailer:
user_mail_address = [user.email]
self.send(
user_mail_address,
_("{} - Shared access given").format(obj_identifier),
_("{} - Shared access given").format(obj.identifier),
msg
)
def send_mail_shared_access_given_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
def send_mail_shared_access_given_team(self, obj, team, users_to_notify, municipals_names):
""" Send a mail if a team just got access to the object
Args:
obj_identifier (str): The object identifier
obj_title (str): Title of the main object
obj (): The object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
municipals_names (iterable): List of municipals for this entry
@ -114,8 +109,7 @@ class Mailer:
"""
context = {
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -123,16 +117,15 @@ class Mailer:
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared access given").format(obj_identifier),
_("{} - Shared access given").format(obj.identifier),
msg
)
def send_mail_shared_access_removed_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
def send_mail_shared_access_removed_team(self, obj, team, users_to_notify, municipals_names):
""" Send a mail if a team just lost access to the object
Args:
obj_identifier (str): The object identifier
obj_title (str): Title of the main object
obj (): The object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
municipals_names (iterable): List of municipals for this entry
@ -142,8 +135,7 @@ class Mailer:
"""
context = {
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -151,16 +143,15 @@ class Mailer:
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared access removed").format(obj_identifier),
_("{} - Shared access removed").format(obj.identifier),
msg
)
def send_mail_shared_data_unrecorded_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
def send_mail_shared_data_unrecorded_team(self,obj, team, users_to_notify, municipals_names):
""" Send a mail if data has just been unrecorded
Args:
obj_identifier (str): The object identifier
obj_title (str): Title of the main object
obj (): The object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
municipals_names (iterable): List of municipals for this entry
@ -170,8 +161,7 @@ class Mailer:
"""
context = {
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -179,16 +169,15 @@ class Mailer:
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared data unrecorded").format(obj_identifier),
_("{} - Shared data unrecorded").format(obj.identifier),
msg
)
def send_mail_shared_data_recorded_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
def send_mail_shared_data_recorded_team(self, obj, team, users_to_notify, municipals_names):
""" Send a mail if data has just been recorded
Args:
obj_identifier (str): The object identifier
obj_title (str): Title of the main object
obj (): The object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
municipals_names (iterable): List of municipals for this entry
@ -198,8 +187,7 @@ class Mailer:
"""
context = {
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -207,16 +195,15 @@ class Mailer:
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared data recorded").format(obj_identifier),
_("{} - Shared data recorded").format(obj.identifier),
msg
)
def send_mail_shared_data_checked_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
def send_mail_shared_data_checked_team(self, obj, team, users_to_notify, municipals_names):
""" Send a mail if data has just been checked
Args:
obj_identifier (str): The object identifier
obj_title (str): Title of the main object
obj (): The object
team (Team): Team to be notified
users_to_notify (QueryDict): Contains the team users which should be notified
municipals_names (iterable): List of municipals for this entry
@ -226,8 +213,7 @@ class Mailer:
"""
context = {
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -235,16 +221,15 @@ class Mailer:
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared data checked").format(obj_identifier),
_("{} - Shared data checked").format(obj.identifier),
msg
)
def send_mail_deduction_changed_team(self, obj_identifier, obj_title, team, data_changes, users_to_notify):
def send_mail_deduction_changed_team(self, obj, team, data_changes, users_to_notify):
""" Send a mail if deduction has been changed
Args:
obj_identifier (str): Identifier of the main object
obj_title (str): Title of the main object
obj (): The object
team (Team): Team to be notified
data_changes (dict): Contains the old|new changes of the deduction changes
users_to_notify (QueryDict): Contains the team users which should be notified
@ -253,8 +238,7 @@ class Mailer:
"""
context = {
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
"data_changes": data_changes,
}
@ -262,16 +246,15 @@ class Mailer:
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Deduction changed").format(obj_identifier),
_("{} - Deduction changed").format(obj.identifier),
msg
)
def send_mail_shared_data_deleted_team(self, obj_identifier, obj_title, team, users_to_notify, municipals_names):
def send_mail_shared_data_deleted_team(self, obj, team, users_to_notify, municipals_names):
""" Send a mail if data has just been deleted
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
obj (): The object
team (Team): The related team
users_to_notify (QuerySet): Contains team users who want to be notified
municipals_names (iterable): List of municipals for the entry
@ -281,8 +264,7 @@ class Mailer:
"""
context = {
"team": team,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -290,16 +272,15 @@ class Mailer:
user_mail_address = users_to_notify.values_list("email", flat=True)
self.send(
user_mail_address,
_("{} - Shared data deleted").format(obj_identifier),
_("{} - Shared data deleted").format(obj.identifier),
msg
)
def send_mail_shared_data_recorded(self, obj_identifier, obj_title, user, municipals_names):
def send_mail_shared_data_recorded(self, obj, user, municipals_names):
""" Send a mail if the user's shared data has just been unrecorded
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
obj (): The object
user (User): The related user
municipals_names (iterable): List of municipals for this entry
@ -308,8 +289,7 @@ class Mailer:
"""
context = {
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -317,16 +297,15 @@ class Mailer:
user_mail_address = [user.email]
self.send(
user_mail_address,
_("{} - Shared data recorded").format(obj_identifier),
_("{} - Shared data recorded").format(obj.identifier),
msg
)
def send_mail_shared_data_unrecorded(self, obj_identifier, obj_title, user, municipals_names):
def send_mail_shared_data_unrecorded(self, obj, user, municipals_names):
""" Send a mail if the user's shared data has just been unrecorded
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
obj (): The object
user (User): The related user
municipals_names (iterable): List of municipals for this entry
@ -335,8 +314,7 @@ class Mailer:
"""
context = {
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -344,16 +322,15 @@ class Mailer:
user_mail_address = [user.email]
self.send(
user_mail_address,
_("{} - Shared data unrecorded").format(obj_identifier),
_("{} - Shared data unrecorded").format(obj.identifier),
msg
)
def send_mail_shared_data_deleted(self, obj_identifier, obj_title, user, municipals_names):
def send_mail_shared_data_deleted(self, obj, user, municipals_names):
""" Send a mail if shared data has just been deleted
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
obj (): The object
user (User): The related user
municipals_names (iterable): List of municipals for this entry
@ -362,8 +339,7 @@ class Mailer:
"""
context = {
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -371,16 +347,15 @@ class Mailer:
user_mail_address = [user.email]
self.send(
user_mail_address,
_("{} - Shared data deleted").format(obj_identifier),
_("{} - Shared data deleted").format(obj.identifier),
msg
)
def send_mail_shared_data_checked(self, obj_identifier, obj_title, user, municipals_names):
def send_mail_shared_data_checked(self, obj, user, municipals_names):
""" Send a mail if shared data just has been checked
Args:
obj_identifier (str): The object identifier
obj_title (str): The object title
obj (): The object
user (User): The related user
municipals_names (iterable): List of municipals for this entry
@ -389,8 +364,7 @@ class Mailer:
"""
context = {
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
}
@ -398,16 +372,15 @@ class Mailer:
user_mail_address = [user.email]
self.send(
user_mail_address,
_("{} - Shared data checked").format(obj_identifier),
_("{} - Shared data checked").format(obj.identifier),
msg
)
def send_mail_deduction_changed(self, obj_identifier, obj_title, user, data_changes):
def send_mail_deduction_changed(self, obj, user, data_changes):
""" Send a mail if deduction has been changed
Args:
obj_identifier (str): Identifier of the main object
obj_title (str): Title of the main object
obj (): The object
user (User): User to be notified
data_changes (dict): Contains the old|new changes of the deduction changes
@ -417,8 +390,7 @@ class Mailer:
"""
context = {
"user": user,
"obj_identifier": obj_identifier,
"obj_title": obj_title,
"obj": obj,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
"data_changes": data_changes,
}
@ -426,7 +398,7 @@ class Mailer:
user_mail_address = [user.email]
self.send(
user_mail_address,
_("{} - Deduction changed").format(obj_identifier),
_("{} - Deduction changed").format(obj.identifier),
msg
)
@ -451,11 +423,11 @@ class Mailer:
msg
)
def send_mail_resubmission(self, obj_identifier, resubmission, municipals_names):
def send_mail_resubmission(self, obj, resubmission, municipals_names):
""" Send a resubmission mail for a user
Args:
obj_identifier (str): The (resubmitted) object's identifier
obj (): The (resubmitted) object
resubmission (Resubmission): The resubmission
municipals_names (iterable): List of municipals for this entry
@ -463,7 +435,7 @@ class Mailer:
"""
context = {
"obj_identifier": obj_identifier,
"obj": obj,
"resubmission": resubmission,
"municipals_names": municipals_names,
"EMAIL_REPLY_TO": EMAIL_REPLY_TO,
@ -472,7 +444,7 @@ class Mailer:
user_mail_address = [resubmission.user.email]
self.send(
user_mail_address,
_("Resubmission - {}").format(obj_identifier),
_("Resubmission - {}").format(obj.identifier),
msg
)

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Shared data checked' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello ' %} {{user.username}},
@ -10,9 +10,9 @@
<br>
{% trans 'the following dataset has just been checked' %}
<br>
<strong>{{obj_identifier}}</strong>
<a href="{{ obj.get_detail_url_absolute }}"><strong>{{obj.identifier}}</strong></a>
<br>
<strong>{{obj_title}}</strong>
<strong>{{obj.title}}</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Shared data checked' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello team' %} {{team.name}},
@ -10,9 +10,9 @@
<br>
{% trans 'the following dataset has just been checked' %}
<br>
<strong>{{obj_identifier}}</strong>
<a href="{{ obj.get_detail_url_absolute }}"><strong>{{obj.identifier}}</strong></a>
<br>
<strong>{{obj_title}}</strong>
<strong>{{obj.title}}</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Shared data deleted' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello ' %} {{user.username}},
@ -10,9 +10,9 @@
<br>
{% trans 'the following dataset has just been deleted' %}
<br>
<strong>{{obj_identifier}}</strong>
<strong>{{obj.identifier}}</strong>
<br>
<strong>"{{obj_title}}"</strong>
<strong>"{{obj.title}}"</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Shared data deleted' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello team' %} {{team.name}},
@ -10,9 +10,9 @@
<br>
{% trans 'the following dataset has just been deleted' %}
<br>
<strong>{{obj_identifier}}</strong>
<strong>{{obj.identifier}}</strong>
<br>
<strong>"{{obj_title}}"</strong>
<strong>"{{obj.title}}"</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -2,7 +2,7 @@
<div>
<h2>{% translate 'Deduction changed' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% translate 'Hello ' %} {{user.username}},
@ -10,6 +10,7 @@
<br>
{% translate 'a deduction of this eco account has changed:' %}
<br>
<a href="{{ obj.get_detail_url_absolute }}"><strong>{{obj.identifier}}</strong></a>
<br>
<table>
<tr>

@ -2,7 +2,7 @@
<div>
<h2>{% translate 'Deduction changed' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello team' %} {{team.name}},
@ -10,6 +10,7 @@
<br>
{% translate 'a deduction of this eco account has changed:' %}
<br>
<a href="{{ obj.get_detail_url_absolute }}"><strong>{{obj.identifier}}</strong></a>
<br>
<table>
<tr>

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Shared data recorded' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello ' %} {{user.username}},
@ -10,9 +10,9 @@
<br>
{% trans 'the following dataset has just been recorded' %}
<br>
<strong>{{obj_identifier}}</strong>
<a href="{{ obj.get_detail_url_absolute }}"><strong>{{obj.identifier}}</strong></a>
<br>
<strong>"{{obj_title}}"</strong>
<strong>"{{obj.title}}"</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Shared data recorded' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello team' %} {{team.name}},
@ -10,9 +10,9 @@
<br>
{% trans 'the following dataset has just been recorded' %}
<br>
<strong>{{obj_identifier}}</strong>
<a href="{{ obj.get_detail_url_absolute }}"><strong>{{obj.identifier}}</strong></a>
<br>
<strong>"{{obj_title}}"</strong>
<strong>"{{obj.title}}"</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Shared data unrecorded' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello ' %} {{user.username}},
@ -10,9 +10,9 @@
<br>
{% trans 'the following dataset has just been unrecorded' %}
<br>
<strong>{{obj_identifier}}</strong>
<a href="{{ obj.get_detail_url_absolute }}"><strong>{{obj.identifier}}</strong></a>
<br>
<strong>"{{obj_title}}"</strong>
<strong>"{{obj.title}}"</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Shared data unrecorded' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello team' %} {{team.name}},
@ -10,9 +10,9 @@
<br>
{% trans 'the following dataset has just been unrecorded' %}
<br>
<strong>{{obj_identifier}}</strong>
<a href="{{ obj.get_detail_url_absolute }}"><strong>{{obj.identifier}}</strong></a>
<br>
<strong>"{{obj_title}}"</strong>
<strong>"{{obj.title}}"</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Resubmission' %}</h2>
<h4>{{obj_identifier}}</h4>
<a href="{{ obj.get_detail_url_absolute }}"><h4>{{obj.identifier}}</h4></a>
<hr>
<article>
{% trans 'Hello ' %} {{resubmission.user.username}},

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Access shared' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello ' %} {{user.username}},
@ -10,9 +10,9 @@
<br>
{% trans 'the following dataset has just been shared with you' %}
<br>
<strong>{{obj_identifier}}</strong>
<a href="{{ obj.get_detail_url_absolute }}"><h4>{{obj.identifier}}</h4></a>
<br>
<strong>"{{obj_title}}"</strong>
<strong>"{{obj.title}}"</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Access shared' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello team' %} {{team.name}},
@ -10,9 +10,9 @@
<br>
{% trans 'the following dataset has just been shared with your team' %}
<br>
<strong>{{obj_identifier}}</strong>
<a href="{{ obj.get_detail_url_absolute }}"><strong>{{obj.identifier}}</strong></a>
<br>
<strong>"{{obj_title}}"</strong>
<strong>"{{obj.title}}"</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Shared access removed' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello ' %} {{user.username}},
@ -10,9 +10,9 @@
<br>
{% trans 'your shared access, including editing, has been revoked for the dataset ' %}
<br>
<strong>{{obj_identifier}}</strong>
<a href="{{ obj.get_detail_url_absolute }}"><strong>{{obj.identifier}}</strong></a>
<br>
<strong>"{{obj_title}}"</strong>
<strong>"{{obj.title}}"</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -2,7 +2,7 @@
<div>
<h2>{% trans 'Shared access removed' %}</h2>
<h4>{{obj_identifier}}</h4>
<h4>{{obj.identifier}}</h4>
<hr>
<article>
{% trans 'Hello team' %} {{team.name}},
@ -10,9 +10,9 @@
<br>
{% trans 'your teams shared access, including editing, has been revoked for the dataset ' %}
<br>
<strong>{{obj_identifier}}</strong>
<a href="{{ obj.get_detail_url_absolute }}"><strong>{{obj.identifier}}</strong></a>
<br>
<strong>"{{obj_title}}"</strong>
<strong>"{{obj.title}}"</strong>
<br>
<br>
{% trans 'This entry is located in' %}

@ -0,0 +1,24 @@
# Generated by Django 4.2.6 on 2023-11-30 11:56
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('user', '0006_auto_20220815_0759'),
]
operations = [
migrations.AlterField(
model_name='team',
name='admins',
field=models.ManyToManyField(blank=True, related_name='+', to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='user',
name='notifications',
field=models.ManyToManyField(blank=True, related_name='+', to='user.usernotification'),
),
]

@ -31,12 +31,11 @@ class Team(UuidModel, DeletableObjectMixin):
self.deleted = delete_action
self.save()
def send_mail_shared_access_given_team(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_access_given_team(self, obj, municipals_names):
""" Sends a mail to the team members in case of given shared access
Args:
obj_identifier (str): The entry identifier
obj_title (str): The entry title
obj (str): The entry
municipals_names (iterable): List of municipals for this entry
Returns:
@ -46,14 +45,13 @@ class Team(UuidModel, DeletableObjectMixin):
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_ACCESS_GAINED.value]
)
mailer.send_mail_shared_access_given_team(obj_identifier, obj_title, self, users_to_notify, municipals_names)
mailer.send_mail_shared_access_given_team(obj, self, users_to_notify, municipals_names)
def send_mail_shared_access_removed(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_access_removed(self, obj, municipals_names):
""" Sends a mail to the team members in case of removed shared access
Args:
obj_identifier (str): The entry identifier
obj_title (str): The entry title
obj (): The entry
municipals_names (iterable): List of municipals for this entry
Returns:
@ -63,14 +61,13 @@ class Team(UuidModel, DeletableObjectMixin):
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_ACCESS_REMOVED.value]
)
mailer.send_mail_shared_access_removed_team(obj_identifier, obj_title, self, users_to_notify, municipals_names)
mailer.send_mail_shared_access_removed_team(obj, self, users_to_notify, municipals_names)
def send_mail_shared_data_unrecorded(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_data_unrecorded(self, obj, municipals_names):
""" Sends a mail to the team members in case of unrecorded data
Args:
obj_identifier (str): The entry identifier
obj_title (str): The entry title
obj (): The entry
municipals_names (iterable): List of municipals for this entry
Returns:
@ -80,14 +77,13 @@ class Team(UuidModel, DeletableObjectMixin):
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_DATA_RECORDED.value]
)
mailer.send_mail_shared_data_unrecorded_team(obj_identifier, obj_title, self, users_to_notify, municipals_names)
mailer.send_mail_shared_data_unrecorded_team(obj, self, users_to_notify, municipals_names)
def send_mail_shared_data_recorded(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_data_recorded(self, obj, municipals_names):
""" Sends a mail to the team members in case of unrecorded data
Args:
obj_identifier (str): The entry identifier
obj_title (str): The entry title
obj (): The entry
municipals_names (iterable): List of municipals for this entry
Returns:
@ -97,14 +93,13 @@ class Team(UuidModel, DeletableObjectMixin):
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_DATA_RECORDED.value]
)
mailer.send_mail_shared_data_recorded_team(obj_identifier, obj_title, self, users_to_notify, municipals_names)
mailer.send_mail_shared_data_recorded_team(obj, self, users_to_notify, municipals_names)
def send_mail_shared_data_checked(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_data_checked(self, obj, municipals_names):
""" Sends a mail to the team members in case of checked data
Args:
obj_identifier (str): The entry identifier
obj_title (str): The entry title
obj (): The entry
municipals_names (iterable): List of municipals for this entry
Returns:
@ -114,14 +109,13 @@ class Team(UuidModel, DeletableObjectMixin):
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_DATA_CHECKED.value]
)
mailer.send_mail_shared_data_checked_team(obj_identifier, obj_title, self, users_to_notify, municipals_names)
mailer.send_mail_shared_data_checked_team(obj, self, users_to_notify, municipals_names)
def send_mail_deduction_changed(self, obj_identifier, obj_title, data_changes):
def send_mail_deduction_changed(self, obj, data_changes):
""" Sends a mail to the team members in case of changed deduction values
Args:
obj_identifier (str): Identifier of the main object
obj_title (str): Title of the main object
obj (): The main object
data_changes (dict): Contains the old|new changes of the deduction changes
Returns:
@ -131,14 +125,13 @@ class Team(UuidModel, DeletableObjectMixin):
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_DEDUCTION_CHANGES.value]
)
mailer.send_mail_deduction_changed_team(obj_identifier, obj_title, self, data_changes, users_to_notify)
mailer.send_mail_deduction_changed_team(obj, self, data_changes, users_to_notify)
def send_mail_shared_data_deleted(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_data_deleted(self, obj, municipals_names):
""" Sends a mail to the team members in case of deleted data
Args:
obj_identifier (str): The entry identifier
obj_title (str): The entry title
obj (): The entry
municipals_names (iterable): List of municipals for this entry
Returns:
@ -148,7 +141,7 @@ class Team(UuidModel, DeletableObjectMixin):
users_to_notify = self.users.filter(
notifications__in=[UserNotificationEnum.NOTIFY_ON_SHARED_DATA_DELETED.value]
)
mailer.send_mail_shared_data_deleted_team(obj_identifier, obj_title, self, users_to_notify, municipals_names)
mailer.send_mail_shared_data_deleted_team(obj, self, users_to_notify, municipals_names)
def remove_user(self, user):
""" Removes a user from the team

@ -83,12 +83,11 @@ class User(AbstractUser):
name=group
)
def send_mail_shared_access_removed(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_access_removed(self, obj, municipals_names):
""" Sends a mail to the user in case of removed shared access
Args:
obj_identifier ():
obj_title ():
obj ():
municipals_names ():
Returns:
@ -97,14 +96,13 @@ class User(AbstractUser):
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, obj_title, self, municipals_names)
mailer.send_mail_shared_access_removed(obj, self, municipals_names)
def send_mail_shared_access_given(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_access_given(self, obj, municipals_names):
""" Sends a mail to the user in case of given shared access
Args:
obj_identifier (str): The entry identifier
obj_title (str): The entry title
obj (): The entry
municipals_names (iterable): List of municipals for this entry
Returns:
@ -113,14 +111,13 @@ class User(AbstractUser):
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, obj_title, self, municipals_names)
mailer.send_mail_shared_access_given(obj, self, municipals_names)
def send_mail_shared_data_recorded(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_data_recorded(self, obj, municipals_names):
""" Sends a mail to the user in case of shared data has been recorded
Args:
obj_identifier (str): The entry identifier
obj_title (str): The entry title
obj (): The entry
municipals_names (iterable): List of municipals for this entry
Returns:
@ -129,14 +126,13 @@ class User(AbstractUser):
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, obj_title, self, municipals_names)
mailer.send_mail_shared_data_recorded(obj, self, municipals_names)
def send_mail_shared_data_unrecorded(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_data_unrecorded(self, obj, municipals_names):
""" Sends a mail to the user in case of shared data has been unrecorded
Args:
obj_identifier (str): The entry identifier
obj_title (str): The entry title
obj (): The entry
municipals_names (iterable): List of municipals for this entry
Returns:
@ -145,14 +141,13 @@ class User(AbstractUser):
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, obj_title, self, municipals_names)
mailer.send_mail_shared_data_unrecorded(obj, self, municipals_names)
def send_mail_shared_data_deleted(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_data_deleted(self, obj, municipals_names):
""" Sends a mail to the user in case of shared data has been deleted
Args:
obj_identifier (str): The entry identifier
obj_title (str): The entry title
obj (): The entry
municipals_names (iterable): List of municipals for this entry
Returns:
@ -161,14 +156,13 @@ class User(AbstractUser):
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, obj_title, self, municipals_names)
mailer.send_mail_shared_data_deleted(obj, self, municipals_names)
def send_mail_shared_data_checked(self, obj_identifier, obj_title, municipals_names):
def send_mail_shared_data_checked(self, obj, municipals_names):
""" Sends a mail to the user in case of shared data has been deleted
Args:
obj_identifier (str): The entry identifier
obj_title (str): The entry title
obj (): The entry
municipals_names (iterable): List of municipals for this entry
Returns:
@ -177,14 +171,13 @@ class User(AbstractUser):
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, obj_title, self, municipals_names)
mailer.send_mail_shared_data_checked(obj, self, municipals_names)
def send_mail_deduction_changed(self, obj_identifier, obj_title, data_changes):
def send_mail_deduction_changed(self, obj, data_changes):
""" Sends a mail to the user in case of a changed deduction
Args:
obj_identifier (str): Identifier of the main object
obj_title (str): Title of the main object
obj (): The object
data_changes (dict): Contains the old|new changes of the deduction changes
Returns:
@ -193,7 +186,7 @@ class User(AbstractUser):
notification_set = self.is_notification_setting_set(UserNotificationEnum.NOTIFY_ON_DEDUCTION_CHANGES)
if notification_set:
mailer = Mailer()
mailer.send_mail_deduction_changed(obj_identifier, obj_title, self, data_changes)
mailer.send_mail_deduction_changed(obj, self, data_changes)
def get_API_token(self):
""" Getter for an API token

Loading…
Cancel
Save