Group access constraints
* adds new decorators for all three important groups * reorganize some default group settings for setup_data.py
This commit is contained in:
@@ -13,6 +13,8 @@ from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from konova.settings import DEFAULT_GROUP, ETS_GROUP, ZB_GROUP
|
||||
|
||||
|
||||
def staff_required(function):
|
||||
"""
|
||||
@@ -41,4 +43,64 @@ def superuser_required(function):
|
||||
else:
|
||||
messages.info(request, _("You need to be administrator to perform this action!"))
|
||||
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
|
||||
return wrap
|
||||
|
||||
|
||||
def default_group_required(function):
|
||||
"""
|
||||
A decorator for functions which shall only be usable for users of specific groups.
|
||||
Group identifiers can be found in konova/settings.py
|
||||
|
||||
"""
|
||||
@wraps(function)
|
||||
def wrap(request, *args, **kwargs):
|
||||
user = request.user
|
||||
has_group = user.groups.filter(
|
||||
name=DEFAULT_GROUP
|
||||
).exists()
|
||||
if has_group:
|
||||
return function(request, *args, **kwargs)
|
||||
else:
|
||||
messages.info(request, _("You need to be part of another user group."))
|
||||
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
|
||||
return wrap
|
||||
|
||||
|
||||
def registration_office_group_required(function):
|
||||
"""
|
||||
A decorator for functions which shall only be usable for users of specific groups.
|
||||
Group identifiers can be found in konova/settings.py
|
||||
|
||||
"""
|
||||
@wraps(function)
|
||||
def wrap(request, *args, **kwargs):
|
||||
user = request.user
|
||||
has_group = user.groups.filter(
|
||||
name=ZB_GROUP
|
||||
).exists()
|
||||
if has_group:
|
||||
return function(request, *args, **kwargs)
|
||||
else:
|
||||
messages.info(request, _("You need to be part of another user group."))
|
||||
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
|
||||
return wrap
|
||||
|
||||
|
||||
def conservation_office_group_required(function):
|
||||
"""
|
||||
A decorator for functions which shall only be usable for users of specific groups.
|
||||
Group identifiers can be found in konova/settings.py
|
||||
|
||||
"""
|
||||
@wraps(function)
|
||||
def wrap(request, *args, **kwargs):
|
||||
user = request.user
|
||||
has_group = user.groups.filter(
|
||||
name=ETS_GROUP
|
||||
).exists()
|
||||
if has_group:
|
||||
return function(request, *args, **kwargs)
|
||||
else:
|
||||
messages.info(request, _("You need to be part of another user group."))
|
||||
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
|
||||
return wrap
|
||||
Reference in New Issue
Block a user