# 63 Refactoring

* refactors django User model to custom User model to provide further attributes and methods directly on the user model
This commit is contained in:
2022-01-12 12:56:22 +01:00
parent 37fffd639f
commit 02970b19b4
32 changed files with 174 additions and 136 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ Created on: 07.12.20
"""
from dal_select2.views import Select2QuerySetView, Select2GroupQuerySetView
from django.contrib.auth.models import User
from user.models import User
from django.db.models import Q
from codelist.models import KonovaCode
+1 -1
View File
@@ -12,7 +12,7 @@ from bootstrap_modal_forms.forms import BSModalForm
from bootstrap_modal_forms.utils import is_ajax
from django import forms
from django.contrib import messages
from django.contrib.auth.models import User
from user.models import User
from django.contrib.gis.forms import OSMWidget, MultiPolygonField
from django.contrib.gis.geos import MultiPolygon
from django.db import transaction
+2 -1
View File
@@ -7,7 +7,8 @@ Created on: 15.12.20
"""
from getpass import getpass
from django.contrib.auth.models import User, Group
from user.models import User
from django.contrib.auth.models import Group
from django.core.management import BaseCommand, call_command
from django.db import transaction
+1 -2
View File
@@ -23,8 +23,7 @@ GROUPS_DATA = [
# Must match with UserNotificationEnum
USER_NOTIFICATIONS_NAMES = {
"NOTIFY_ON_NEW_RELATED_DATA": _("On new related data"),
"NOTIFY_ON_SHARE_LINK_DISABLED": _("On disabled share link"),
"NOTIFY_ON_SHARED_ACCESS_GAINED": _("On shared access gained"),
"NOTIFY_ON_SHARED_ACCESS_REMOVED": _("On shared access removed"),
"NOTIFY_ON_SHARED_DATA_RECORDED": _("On shared data recorded"),
"NOTIFY_ON_SHARED_DATA_DELETED": _("On shared data deleted"),
+6 -1
View File
@@ -10,7 +10,7 @@ import uuid
from abc import abstractmethod
from django.contrib import messages
from django.contrib.auth.models import User
from user.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpRequest
from django.utils.timezone import now
@@ -411,6 +411,11 @@ class ShareableObjectMixin(models.Model):
users = User.objects.filter(
id__in=accessing_users
)
removed_users = self.users.all().exclude(
id__in=accessing_users
)
for user in removed_users:
user.send_mail_shared_access_removed(self)
self.share_with_list(users)
+2 -1
View File
@@ -5,9 +5,10 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 17.08.21
"""
from django.contrib.auth.models import User
from simple_sso.sso_client.client import Client
from user.models import User
class KonovaSSOClient(Client):
""" Konova specialized derivate of general sso.Client.
+1 -1
View File
@@ -129,7 +129,7 @@ DATABASES = {
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_USER_MODEL = "user.User"
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+7 -2
View File
@@ -1,3 +1,5 @@
from time import sleep
from celery import shared_task
from django.core.exceptions import ObjectDoesNotExist
@@ -5,10 +7,13 @@ from konova.models import Geometry
@shared_task
def celery_update_parcels(geometry_id: str):
def celery_update_parcels(geometry_id: str, recheck: bool = True):
try:
geom = Geometry.objects.get(id=geometry_id)
geom.parcels.clear()
geom.update_parcels()
except ObjectDoesNotExist:
return
if recheck:
sleep(5)
celery_update_parcels(geometry_id, False)
+2 -1
View File
@@ -7,7 +7,8 @@ Created on: 26.10.21
"""
import datetime
from django.contrib.auth.models import User, Group
from user.models import User
from django.contrib.auth.models import Group
from django.contrib.gis.geos import MultiPolygon, Polygon
from django.core.exceptions import ObjectDoesNotExist
from django.test import TestCase, Client
+28 -9
View File
@@ -8,6 +8,8 @@ Created on: 09.11.20
import logging
from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from konova.sub_settings.django_settings import DEFAULT_FROM_EMAIL
@@ -26,18 +28,13 @@ class Mailer:
auth_user = None
auth_password = None
def __init__(self, to_mail: list, from_mail: str = DEFAULT_FROM_EMAIL, auth_user: str = None, auth_password: str = None, fail_silently: bool = False):
# Make sure given to_mail parameter is a list
if isinstance(to_mail, str):
to_mail = [to_mail]
def __init__(self, from_mail: str = DEFAULT_FROM_EMAIL, auth_user: str = None, auth_password: str = None, fail_silently: bool = False):
self.from_mail = from_mail
self.to_mail = to_mail
self.fail_silently = fail_silently
self.auth_user = auth_user
self.auth_password = auth_password
def send(self, subject: str, msg: str):
def send(self, recipient_list: list, subject: str, msg: str):
"""
Sends a mail with subject and message
"""
@@ -45,8 +42,30 @@ class Mailer:
subject=subject,
message=msg,
from_email=self.from_mail,
recipient_list=self.to_mail,
recipient_list=recipient_list,
fail_silently=self.fail_silently,
auth_user=self.auth_user,
auth_password=self.auth_password
)
)
def send_mail_shared_access_removed(self, obj, user):
""" Send a mail if user has no access to the object anymore
Args:
obj ():
Returns:
"""
context = {
"user": user,
"obj": obj,
}
msg = render_to_string("email/sharing/shared_access_removed.html", context)
user_mail_address = [user.email]
self.send(
user_mail_address,
_("{} - Shared access removed").format(obj.identifier),
msg
)
+1 -1
View File
@@ -8,7 +8,7 @@ Created on: 17.08.21
from collections import Iterable
import requests
from django.contrib.auth.models import User
from user.models import User
from django.utils.translation import gettext_lazy as _
from konova.settings import SSO_SERVER_BASE, SSO_PUBLIC_KEY, PROXIES
+1 -1
View File
@@ -5,7 +5,7 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 02.07.21
"""
from django.contrib.auth.models import User
from user.models import User
from konova.settings import ETS_GROUP, ZB_GROUP