From 8895c00a2de79460dd81c188804a8e5ae0403169 Mon Sep 17 00:00:00 2001 From: Nattfarinn Date: Thu, 21 Dec 2017 11:32:41 +0100 Subject: [PATCH] EZP-28635: Make sure policies without limitationTypes are not editable --- src/bundle/Controller/PolicyController.php | 12 +++++++++++- .../Resources/views/admin/policy/list.html.twig | 3 +-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bundle/Controller/PolicyController.php b/src/bundle/Controller/PolicyController.php index 7b276d0b72..7b0472b9f5 100644 --- a/src/bundle/Controller/PolicyController.php +++ b/src/bundle/Controller/PolicyController.php @@ -102,12 +102,22 @@ public function listAction(Role $role, string $routeName, int $policyPage = 1): /** @var Policy[] $policies */ $policies = $pagerfanta->getCurrentPageResults(); + $isEditable = []; + foreach ($policies as $policy) { + $limitationTypes = $policy->module + ? $this->roleService->getLimitationTypesByModuleFunction($policy->module, $policy->function) + : []; + + $isEditable[$policy->id] = !empty($limitationTypes); + } + $deletePoliciesForm = $this->formFactory->deletePolicies( - new PoliciesDeleteData($role, $this->getPoliciesNumbers($policies)) + new PoliciesDeleteData($role, $this->getPoliciesNumbers($policies)) ); return $this->render('@EzPlatformAdminUi/admin/policy/list.html.twig', [ 'form_policies_delete' => $deletePoliciesForm->createView(), + 'is_editable' => $isEditable, 'role' => $role, 'pager' => $pagerfanta, 'route_name' => $routeName, diff --git a/src/bundle/Resources/views/admin/policy/list.html.twig b/src/bundle/Resources/views/admin/policy/list.html.twig index 88f670c7d6..315b5b09a7 100644 --- a/src/bundle/Resources/views/admin/policy/list.html.twig +++ b/src/bundle/Resources/views/admin/policy/list.html.twig @@ -66,9 +66,8 @@ {%- endif -%} - {% set unlimited = (policy.module == '*' and policy.function == '*') %} + href="{{ path('ezplatform.policy.update', { roleId: role.id, policyId: policy.id }) }}" class="btn btn-icon mx-3{{ not is_editable[policy.id] ? ' disabled' : '' }}">