Missing group message

* adds group checker decorator for adding a message informing about missing group privileges
This commit is contained in:
mipel
2021-08-03 09:45:41 +02:00
parent d4b3b97f84
commit a06b532108
7 changed files with 134 additions and 89 deletions

View File

@@ -46,6 +46,25 @@ def superuser_required(function):
return wrap
def any_group_check(function):
"""
Checks for any group membership. Adds a message in case of having none.
"""
@wraps(function)
def wrap(request, *args, **kwargs):
user = request.user
# Inform user about missing group privileges!
groups = user.groups.all()
if not groups:
messages.info(
request,
_("+++ Attention: You are not part of any group. You won't be able to create, edit or do anything. Please contact an administrator. +++")
)
return function(request, *args, **kwargs)
return wrap
def default_group_required(function):
"""
A decorator for functions which shall only be usable for users of specific groups.

View File

@@ -16,6 +16,7 @@ from django.utils.translation import gettext_lazy as _
from compensation.models import Compensation, EcoAccount
from intervention.models import Intervention
from konova.contexts import BaseContext
from konova.decorators import any_group_check
from konova.forms import RemoveModalForm
from konova.models import Document
from news.models import ServerMessage
@@ -37,6 +38,7 @@ def logout_view(request: HttpRequest):
@login_required
@any_group_check
def home_view(request: HttpRequest):
"""
Renders the landing page