From 4a19eef7c03d76327ee9e03300250ba6b63f5c6c Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Tue, 19 Dec 2023 14:42:56 +0100 Subject: [PATCH] fixes #539. Added new group for chairs, po & data manager --- fetc/constants.py | 1 + main/templatetags/fetc_filters.py | 12 ++++++++++++ reviews/api/views.py | 14 ++++++++++---- reviews/menus.py | 16 ++++++++-------- reviews/views.py | 20 ++++++++++---------- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/fetc/constants.py b/fetc/constants.py index a35827f82..42d64370f 100644 --- a/fetc/constants.py +++ b/fetc/constants.py @@ -6,6 +6,7 @@ GROUP_PRIMARY_SECRETARY = 'Primaire secretaris' GROUP_LINGUISTICS_CHAMBER = 'LK' GROUP_GENERAL_CHAMBER = 'AK' +GROUP_CHAIR = 'Voorzitter' # Route durations PREASSESSMENT_ROUTE_WEEKS = 1 diff --git a/main/templatetags/fetc_filters.py b/main/templatetags/fetc_filters.py index 340351339..e9598f344 100644 --- a/main/templatetags/fetc_filters.py +++ b/main/templatetags/fetc_filters.py @@ -1,6 +1,7 @@ from django import template from django.conf import settings from django.contrib.auth.models import Group +from django.db.models import Q register = template.Library() @@ -29,3 +30,14 @@ def is_secretary(current_user): Check whether the current user is in the 'Secretary' group """ return Group.objects.get(name=settings.GROUP_SECRETARY) in current_user.groups.all() + +@register.filter +def is_chair_or_secretary(current_user): + """ + Check whether the current user is in the 'Chair' group + """ + user_groups = current_user.groups.all() + return ( + Group.objects.get(name=settings.GROUP_CHAIR) in user_groups + or Group.objects.get(name=settings.GROUP_SECRETARY) in user_groups + ) diff --git a/reviews/api/views.py b/reviews/api/views.py index 29409d76c..48c2b8cde 100644 --- a/reviews/api/views.py +++ b/reviews/api/views.py @@ -21,6 +21,7 @@ class BaseDecisionApiView(GroupRequiredMixin, CommitteeMixin, FancyListApiView): serializer_class = DecisionSerializer group_required = [ settings.GROUP_SECRETARY, + settings.GROUP_CHAIR, settings.GROUP_GENERAL_CHAMBER, settings.GROUP_LINGUISTICS_CHAMBER, ] @@ -227,6 +228,7 @@ def get_queryset_for_secretary(self): class OpenDecisionsApiView(BaseDecisionApiView): group_required = [ settings.GROUP_SECRETARY, + settings.GROUP_CHAIR, ] def get_queryset(self): @@ -269,6 +271,7 @@ def get_queryset(self): class OpenSupervisorDecisionApiView(BaseDecisionApiView): group_required = [ settings.GROUP_SECRETARY, + settings.GROUP_CHAIR, ] sort_definitions = [ @@ -369,7 +372,10 @@ def get_context(self): class ToConcludeReviewApiView(BaseReviewApiView): - group_required = settings.GROUP_SECRETARY + group_required = [ + settings.GROUP_SECRETARY, + settings.GROUP_CHAIR, + ] def get_queryset(self): """Returns all open Committee Decisions of all Users""" @@ -412,7 +418,7 @@ class InRevisionApiView(BaseReviewApiView): but for which a revision has not yet been submitted""" default_sort = ('date_start', 'desc') - group_required = [settings.GROUP_SECRETARY] + group_required = [settings.GROUP_SECRETARY, settings.GROUP_CHAIR] def get_queryset(self): # 1. Find reviews of revisions: @@ -448,7 +454,7 @@ class AllOpenReviewsApiView(BaseReviewApiView): def get_group_required(self): # Depending on committee kwarg we test for the correct group - group_required = [settings.GROUP_SECRETARY] + group_required = [settings.GROUP_SECRETARY, settings.GROUP_CHAIR] if self.committee.name == 'AK': group_required += [settings.GROUP_GENERAL_CHAMBER] @@ -495,7 +501,7 @@ class AllReviewsApiView(BaseReviewApiView): def get_group_required(self): # Depending on committee kwarg we test for the correct group - group_required = [settings.GROUP_SECRETARY] + group_required = [settings.GROUP_SECRETARY, settings.GROUP_CHAIR] if self.committee.name == 'AK': group_required += [settings.GROUP_GENERAL_CHAMBER] diff --git a/reviews/menus.py b/reviews/menus.py index 462d11514..c6d4983ff 100644 --- a/reviews/menus.py +++ b/reviews/menus.py @@ -5,7 +5,7 @@ from menu import Menu, MenuItem from main.templatetags.fetc_filters import in_general_chamber, \ - in_linguistics_chamber, is_secretary + in_linguistics_chamber, is_secretary, is_chair_or_secretary def create_committee_menu(commitee: str) -> List[MenuItem]: @@ -21,37 +21,37 @@ def create_committee_menu(commitee: str) -> List[MenuItem]: MenuItem( _("Alle openstaande besluiten commissieleden"), reverse("reviews:open", args=[commitee]), - check=lambda x: is_secretary(x.user), + check=lambda x: is_chair_or_secretary(x.user), ), MenuItem( _("Alle openstaande besluiten eindverantwoordelijken"), reverse("reviews:open_supervisors", args=[commitee]), - check=lambda x: is_secretary(x.user), + check=lambda x: is_chair_or_secretary(x.user), ), MenuItem( _("Nog af te handelen aanvragen"), reverse("reviews:to_conclude", args=[commitee]), - check=lambda x: is_secretary(x.user), + check=lambda x: is_chair_or_secretary(x.user), ), MenuItem( _("Aanvragen in revisie"), reverse("reviews:in_revision", args=[commitee]), - check=lambda x: is_secretary(x.user), + check=lambda x: is_chair_or_secretary(x.user), ), MenuItem( _("Alle lopende aanvragen"), reverse("reviews:all_open", args=[commitee]), - check=lambda x: is_secretary(x.user), + check=lambda x: is_chair_or_secretary(x.user), ), MenuItem( _("Alle ingezonden aanvragen"), reverse("reviews:archive", args=[commitee]), - check=lambda x: is_secretary(x.user), + check=lambda x: is_chair_or_secretary(x.user), ), MenuItem( _("Overzicht werkverdeling commissieleden"), reverse("reviews:workload", args=[commitee]), - check=lambda x: is_secretary(x.user), + check=lambda x: is_chair_or_secretary(x.user), ), ] diff --git a/reviews/views.py b/reviews/views.py index 8ac4761f8..16fd124a7 100644 --- a/reviews/views.py +++ b/reviews/views.py @@ -43,6 +43,7 @@ class BaseDecisionListView(GroupRequiredMixin, CommitteeMixin, generic.TemplateV settings.GROUP_SECRETARY, settings.GROUP_GENERAL_CHAMBER, settings.GROUP_LINGUISTICS_CHAMBER, + settings.GROUP_CHAIR, ] def get_context_data(self, **kwargs): @@ -74,7 +75,7 @@ def get_context_data(self, **kwargs): class DecisionOpenView(BaseDecisionListView): - group_required = settings.GROUP_SECRETARY + group_required = (settings.GROUP_SECRETARY, settings.GROUP_CHAIR) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -90,7 +91,7 @@ class CommitteeMembersWorkloadView( GroupRequiredMixin, CommitteeMixin, generic.FormView ): template_name = "reviews/committee_members_workload.html" - group_required = [settings.GROUP_SECRETARY] + group_required = (settings.GROUP_SECRETARY, settings.GROUP_CHAIR) form_class = StartEndDateForm def __init__(self, **kwargs): @@ -192,7 +193,7 @@ class SupervisorDecisionOpenView(BaseDecisionListView): This page displays all proposals to be reviewed by supervisors. """ - group_required = settings.GROUP_SECRETARY + group_required = (settings.GROUP_SECRETARY, settings.GROUP_CHAIR) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -208,9 +209,7 @@ def get_context_data(self, **kwargs): class BaseReviewListView(GroupRequiredMixin, CommitteeMixin, generic.TemplateView): template_name = "reviews/ufl_list.html" - group_required = [ - settings.GROUP_SECRETARY, - ] + group_required = (settings.GROUP_SECRETARY, settings.GROUP_CHAIR) def get_context_data(self, **kwargs): context = super().get_context_data() @@ -221,7 +220,7 @@ def get_context_data(self, **kwargs): class ToConcludeProposalView(BaseReviewListView): - group_required = settings.GROUP_SECRETARY + group_required = (settings.GROUP_SECRETARY, settings.GROUP_CHAIR) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -233,7 +232,7 @@ def get_context_data(self, **kwargs): class InRevisionReviewsView(BaseReviewListView): - group_required = [settings.GROUP_SECRETARY] + group_required = (settings.GROUP_SECRETARY, settings.GROUP_CHAIR) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -258,7 +257,7 @@ def get_context_data(self, **kwargs): def get_group_required(self): # Depending on committee kwarg we test for the correct group - group_required = [settings.GROUP_SECRETARY] + group_required = [settings.GROUP_SECRETARY, settings.GROUP_CHAIR] if self.committee.name == "AK": group_required += [settings.GROUP_GENERAL_CHAMBER] @@ -280,7 +279,7 @@ def get_context_data(self, **kwargs): def get_group_required(self): # Depending on committee kwarg we test for the correct group - group_required = [settings.GROUP_SECRETARY] + group_required = [settings.GROUP_SECRETARY, settings.GROUP_CHAIR] if self.committee.name == "AK": group_required += [settings.GROUP_GENERAL_CHAMBER] @@ -303,6 +302,7 @@ def get_group_required(self): obj = self.get_object() group_required = [ settings.GROUP_SECRETARY, + settings.GROUP_CHAIR, obj.proposal.reviewing_committee.name, ]