From 5923df0e0b7674b61a51d73aa3abd43dda654cf1 Mon Sep 17 00:00:00 2001 From: Alex Manning Date: Tue, 10 Jan 2023 14:51:10 +0000 Subject: [PATCH] Do not include revoked grantes when showing users list of managers. --- jasmin_services/views/service_details.py | 47 ++++++++++++++---------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/jasmin_services/views/service_details.py b/jasmin_services/views/service_details.py index ee73851..346fb4c 100644 --- a/jasmin_services/views/service_details.py +++ b/jasmin_services/views/service_details.py @@ -19,26 +19,6 @@ def service_details(request, service): Displays details for a service, including details of current access and requests. """ - # Get all the current managers and deputies of a services so that - # we can display this information to users of the service. - managers = ( - Grant.objects.filter( - access__role__service=service, - expires__gt=date.today(), - ) - .filter_active() - .filter(access__role__name="MANAGER") - ) - managers = [x.access.user for x in managers] - deputies = ( - Grant.objects.filter( - access__role__service=service, - expires__gt=date.today(), - ) - .filter_active() - .filter(access__role__name="DEPUTY") - ) - deputies = [x.access.user for x in deputies] # Get the active grants and requests for the service as a whole all_grants = Grant.objects.filter( @@ -92,6 +72,33 @@ def service_details(request, service): continue roles.append(role) + if grants: + # Get all the current managers and deputies of a services so that + # we can display this information to users of the service. + managers = ( + Grant.objects.filter( + access__role__service=service, + expires__gt=date.today(), + revoked=False, + ) + .filter_active() + .filter(access__role__name="MANAGER") + ) + managers = [x.access.user for x in managers] + deputies = ( + Grant.objects.filter( + access__role__service=service, + expires__gt=date.today(), + revoked=False, + ) + .filter_active() + .filter(access__role__name="DEPUTY") + ) + deputies = [x.access.user for x in deputies] + else: + managers = [] + deputies = [] + templates = [ f"jasmin_services/{service.category.name}/{service.name}/service_details.html", f"jasmin_services/{service.category.name}/service_details.html",