diff options
author | Andrea Lepori <alepori@student.ethz.ch> | 2022-04-27 22:29:25 +0200 |
---|---|---|
committer | Andrea Lepori <alepori@student.ethz.ch> | 2022-04-27 22:29:25 +0200 |
commit | 290b6e3cad5bb819516571cbf583ed8939a71da4 (patch) | |
tree | 2d9f85e65efc8cfb3e83c037fc449bcdf65b8ff6 /client/templatetags/app_filter.py | |
parent | multiuser logout support (diff) | |
download | scout-subs-290b6e3cad5bb819516571cbf583ed8939a71da4.tar.gz scout-subs-290b6e3cad5bb819516571cbf583ed8939a71da4.zip |
check if capi userlist enabled with an app_filter
Diffstat (limited to 'client/templatetags/app_filter.py')
-rw-r--r-- | client/templatetags/app_filter.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/client/templatetags/app_filter.py b/client/templatetags/app_filter.py index c447d35..ed44138 100644 --- a/client/templatetags/app_filter.py +++ b/client/templatetags/app_filter.py @@ -1,6 +1,6 @@ from django import template from django.db.models.query_utils import Q -from client.models import Document, KeyVal, Keys +from client.models import Document, GroupSettings, KeyVal, Keys import json @@ -55,4 +55,20 @@ def parse_userswitcher(str): if not str: return [] - return json.loads(str).keys()
\ No newline at end of file + return json.loads(str).keys() + +@register.filter(name="user_list") +def user_list(user): + # get user group + groups = user.groups.all() + + # check if any group has enabled RO documents + if user.is_staff or len(groups.filter(name="capi")) == 0: + # if user is staff then not needed + gr = [] + elif user.has_perm("client.staff"): + gr = GroupSettings.objects.filter(group__in=groups).filter(view_documents=True).filter(~Q(group=groups[0])) + else: + gr = GroupSettings.objects.filter(group__in=groups).filter(view_documents=True) + + return (len(gr) != 0)
\ No newline at end of file |