* refactors team views * split views.py into users.py and teams.py in users app * refactors method headers for _user_has_permission() * adds method and class comments and documentation to base view classes
94 lines
2.6 KiB
Python
94 lines
2.6 KiB
Python
"""
|
|
Author: Michel Peltriaux
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
|
Created on: 22.08.22
|
|
|
|
"""
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
from django.urls import reverse
|
|
|
|
from intervention.forms.modals.deduction import NewEcoAccountDeductionModalForm, EditEcoAccountDeductionModalForm, \
|
|
RemoveEcoAccountDeductionModalForm
|
|
from konova.utils.general import check_id_is_valid_uuid
|
|
from konova.views.base import BaseModalFormView
|
|
|
|
|
|
class AbstractDeductionView(BaseModalFormView):
|
|
_REDIRECT_URL = None
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
check_id_is_valid_uuid(kwargs.get("id"))
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
def _custom_check(self, obj):
|
|
"""
|
|
Can be used by inheriting classes to provide custom checks before further processing
|
|
|
|
"""
|
|
pass
|
|
|
|
def _user_has_permission(self, user, **kwargs) -> bool:
|
|
"""
|
|
|
|
Args:
|
|
user ():
|
|
|
|
Returns:
|
|
|
|
"""
|
|
return user.is_default_user()
|
|
|
|
def _user_has_shared_access(self, user, **kwargs) -> bool:
|
|
""" A user has shared access on
|
|
|
|
Args:
|
|
user (User): The performing user
|
|
kwargs (dict): Parameters
|
|
|
|
Returns:
|
|
bool: True if the user has access to the requested object, False otherwise
|
|
"""
|
|
ret_val: bool = False
|
|
try:
|
|
obj = self._MODEL_CLS.objects.get(
|
|
id=kwargs.get("id")
|
|
)
|
|
ret_val = obj.is_shared_with(user)
|
|
except ObjectDoesNotExist:
|
|
ret_val = False
|
|
return ret_val
|
|
|
|
def _get_redirect_url(self, *args, **kwargs):
|
|
obj = kwargs.get("obj", None)
|
|
assert obj is not None
|
|
return reverse(self._REDIRECT_URL, args=(obj.id,)) + "#related_data"
|
|
|
|
|
|
class AbstractNewDeductionView(AbstractDeductionView):
|
|
_FORM_CLS = NewEcoAccountDeductionModalForm
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
|
|
class AbstractEditDeductionView(AbstractDeductionView):
|
|
_FORM_CLS = EditEcoAccountDeductionModalForm
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
check_id_is_valid_uuid(kwargs.get("deduction_id"))
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
class AbstractRemoveDeductionView(AbstractDeductionView):
|
|
_FORM_CLS = RemoveEcoAccountDeductionModalForm
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
check_id_is_valid_uuid(kwargs.get("deduction_id"))
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
class Meta:
|
|
abstract = True
|