From 19d120e045991226a07bbe3929bc3ed0db818790 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Wed, 17 Mar 2021 22:20:58 +0100 Subject: users of group capi can optionally view documents --- client/migrations/0007_groupsettings.py | 23 +++++++++++++++++++++++ client/models.py | 4 ++++ client/views.py | 17 ++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 client/migrations/0007_groupsettings.py (limited to 'client') diff --git a/client/migrations/0007_groupsettings.py b/client/migrations/0007_groupsettings.py new file mode 100644 index 0000000..b5a23fa --- /dev/null +++ b/client/migrations/0007_groupsettings.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.2 on 2021-03-17 20:06 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ('client', '0006_documenttype_max_instances'), + ] + + operations = [ + migrations.CreateModel( + name='GroupSettings', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('view_documents', models.BooleanField(default=False)), + ('group', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='auth.group')), + ], + ), + ] diff --git a/client/models.py b/client/models.py index d14a267..5b5db6a 100644 --- a/client/models.py +++ b/client/models.py @@ -111,3 +111,7 @@ class UserCode(models.Model): phone = models.CharField(default="", max_length=250) school = models.CharField(default="", max_length=250) year = models.IntegerField(default=0) + +class GroupSettings(models.Model): + group = models.ForeignKey(Group, default=None, on_delete=models.CASCADE) + view_documents = models.BooleanField(default=False) \ No newline at end of file diff --git a/client/views.py b/client/views.py index 32678f5..6fdd3f2 100644 --- a/client/views.py +++ b/client/views.py @@ -1,6 +1,6 @@ from random import randint from django.contrib.auth.models import Group, Permission, User -from client.models import UserCode, Keys, DocumentType, Document, PersonalData, KeyVal, MedicalData +from client.models import GroupSettings, UserCode, Keys, DocumentType, Document, PersonalData, KeyVal, MedicalData from django.db.models import Q from django.http import HttpResponseRedirect, FileResponse, HttpResponse from django.contrib.auth.decorators import login_required @@ -17,6 +17,7 @@ import pytz def index(request): context = {} + group_view = False # check if user is logged if (request.user.is_authenticated): if not (request.user.is_staff or request.user.has_perm("client.approved")): @@ -39,6 +40,19 @@ def index(request): user_code = "U" + str(usercode.code) context = {"user_code": user_code} else: + # get user group + group = request.user.groups.values_list('name', flat=True)[0] + + # get group settings + settings = GroupSettings.objects.filter(group__name=group) + + # check if settings exists + if len(settings) == 0: + group_view = False + else: + # set settings value + group_view = settings[0].view_documents + # user action if request.method == "POST": # get document id @@ -123,6 +137,7 @@ def index(request): context = { "docs": out, "empty": len(out) == 0, + "group_view": group_view, } return render(request, 'client/index.html', context) -- cgit v1.2.1 From 1cc9fbd3bf0652439dc6722a810543c065ce223b Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Fri, 23 Jul 2021 17:34:07 +0200 Subject: add notification if user of group capi views document --- client/templates/client/index.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'client') diff --git a/client/templates/client/index.html b/client/templates/client/index.html index 932af1c..7d001ec 100644 --- a/client/templates/client/index.html +++ b/client/templates/client/index.html @@ -17,6 +17,18 @@ {% if user.is_authenticated %} {% if user.is_staff or perms.client.approved %} + {% if not empty %}