aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Lepori <alepori@student.ethz.ch>2022-04-27 22:29:25 +0200
committerAndrea Lepori <alepori@student.ethz.ch>2022-04-27 22:29:25 +0200
commit290b6e3cad5bb819516571cbf583ed8939a71da4 (patch)
tree2d9f85e65efc8cfb3e83c037fc449bcdf65b8ff6
parentmultiuser logout support (diff)
downloadscout-subs-290b6e3cad5bb819516571cbf583ed8939a71da4.tar.gz
scout-subs-290b6e3cad5bb819516571cbf583ed8939a71da4.zip
check if capi userlist enabled with an app_filter
-rw-r--r--client/templatetags/app_filter.py20
-rw-r--r--client/views.py14
-rw-r--r--templates/registration/base_client.html8
-rw-r--r--version.txt2
4 files changed, 25 insertions, 19 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
diff --git a/client/views.py b/client/views.py
index 086c1ba..a6087aa 100644
--- a/client/views.py
+++ b/client/views.py
@@ -18,7 +18,6 @@ from random import randint
@login_required()
def index(request):
context = {}
- group_view = False
if not (request.user.is_staff or request.user.has_perm("client.approved")):
# generate code if user has no code
users = UserCode.objects.filter(user=request.user)
@@ -40,20 +39,8 @@ def index(request):
context = {"user_code": user_code}
return render(request, 'client/index.html', context)
- # get user group
groups = request.user.groups.all()
- # check if any group has enabled RO documents
- if request.user.is_staff or len(groups.filter(name="capi")) == 0:
- # if user is staff then not needed
- gr = []
- elif request.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)
-
- group_view = len(gr) != 0
-
# user action
if request.method == "POST":
# get document id
@@ -116,7 +103,6 @@ def index(request):
"docs": documents,
"base_group": groups[0].name,
"empty": len(documents) == 0,
- "group_view": group_view,
"vac_file": vac_file,
"health_file": health_file,
"sign_doc_file": sign_doc_file
diff --git a/templates/registration/base_client.html b/templates/registration/base_client.html
index c4e62b6..09e7dd0 100644
--- a/templates/registration/base_client.html
+++ b/templates/registration/base_client.html
@@ -109,13 +109,17 @@
{% block breadcrumb %}
{% endblock %}
<ul class="right">
- <li class="userswitcher" data-target='userswitcher'><a href="#">{{ user.username }}</a></li>
+ {% if user.is_staff or perms.client.staff %}
+ <li class="userswitcher" data-target='userswitcher'><a href="#">{{ user.username }}<i class="right material-icons">supervisor_account</i></a></li>
+ {% else %}
+ <li class="userswitcher" data-target='userswitcher'><a href="#">{{ user.username }}</a></li>
+ {% endif %}
<ul id='userswitcher' class='dropdown-content'>
<li><a href="{% url 'personal' %}"><i class="material-icons">person</i>Gestione account</a></li>
{% if user.is_staff or perms.client.staff %}
<li><a href="{% url 'server' %}"><i class="material-icons">build</i>Pannello Admin</a></li>
{% endif %}
- {% if group_view %}
+ {% if user|user_list %}
<li><a class="modal-trigger" href="#modal_capi"><i class="material-icons">list</i>Lista documenti</a></li>
{% endif %}
diff --git a/version.txt b/version.txt
index bd2c9de..6b1314e 100644
--- a/version.txt
+++ b/version.txt
@@ -1,2 +1,2 @@
version=0.5
-rev=12
+rev=13