* adds creation of new compensation directly from intervention detail view
* adds comment rendering on compensation detail view (WIP)
* adds shared_access_required decorator
* adds/updates translations
This commit is contained in:
mipel
2021-10-04 13:23:14 +02:00
parent 9cfb400bad
commit 3d31a13508
12 changed files with 104 additions and 26 deletions

View File

@@ -9,11 +9,12 @@ Created on: 16.11.20
from functools import wraps
from django.contrib import messages
from django.shortcuts import redirect
from django.shortcuts import redirect, get_object_or_404
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from konova.settings import DEFAULT_GROUP, ETS_GROUP, ZB_GROUP
from konova.utils.message_templates import MISSING_GROUP_PERMISSION, DATA_UNSHARED
def staff_required(function):
@@ -80,7 +81,7 @@ def default_group_required(function):
if has_group:
return function(request, *args, **kwargs)
else:
messages.info(request, _("You need to be part of another user group."))
messages.info(request, MISSING_GROUP_PERMISSION)
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
return wrap
@@ -100,7 +101,7 @@ def registration_office_group_required(function):
if has_group:
return function(request, *args, **kwargs)
else:
messages.info(request, _("You need to be part of another user group."))
messages.info(request, MISSING_GROUP_PERMISSION)
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
return wrap
@@ -120,6 +121,35 @@ def conservation_office_group_required(function):
if has_group:
return function(request, *args, **kwargs)
else:
messages.info(request, _("You need to be part of another user group."))
messages.info(request, MISSING_GROUP_PERMISSION)
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
return wrap
return wrap
def shared_access_required(obj_class, id_key):
""" Checks whether the data is shared with the requesting user
Args:
obj_class (Model): The object/model class
id_key (str): The name of the identifier attribute in **kwargs
Returns:
"""
def decorator(function):
@wraps(function)
def wrap(request, *args, **kwargs):
user = request.user
_id = kwargs.get(id_key, None)
if _id is not None:
obj = get_object_or_404(obj_class, id=_id)
is_shared = obj.is_shared_with(user)
if not is_shared:
messages.info(
request,
DATA_UNSHARED
)
return redirect("home")
return function(request, *args, **kwargs)
return wrap
return decorator

View File

@@ -11,3 +11,5 @@ from django.utils.translation import gettext_lazy as _
FORM_INVALID = _("There was an error on this form.")
INTERVENTION_INVALID = _("There are errors in this intervention.")
IDENTIFIER_REPLACED = _("The identifier '{}' had to be changed to '{}' since another entry has been added in the meanwhile, which uses this identifier")
DATA_UNSHARED = _("This data is not shared with you")
MISSING_GROUP_PERMISSION = _("You need to be part of another user group.")