diff --git a/src/bundle/AdrienDupuisEzPlatformAdminBundle.php b/src/bundle/AdrienDupuisEzPlatformAdminBundle.php index 7f19a1c..c922309 100644 --- a/src/bundle/AdrienDupuisEzPlatformAdminBundle.php +++ b/src/bundle/AdrienDupuisEzPlatformAdminBundle.php @@ -3,7 +3,15 @@ namespace AdrienDupuis\EzPlatformAdminBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; +use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension; +use Symfony\Component\DependencyInjection\ContainerBuilder; class AdrienDupuisEzPlatformAdminBundle extends Bundle { + public function build(ContainerBuilder $container): void + { + /** @var EzPublishCoreExtension */ + $extension = $container->getExtension('ezpublish'); + $extension->addPolicyProvider(new Security\PolicyProvider()); + } } diff --git a/src/bundle/Controller/ContentUsageController.php b/src/bundle/Controller/ContentUsageController.php index b6c05f3..0a0f794 100644 --- a/src/bundle/Controller/ContentUsageController.php +++ b/src/bundle/Controller/ContentUsageController.php @@ -7,6 +7,7 @@ use eZ\Publish\API\Repository\Exceptions\NotFoundException; use eZ\Publish\API\Repository\Values\ContentType\ContentType; use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; +use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute; use EzSystems\EzPlatformAdminUiBundle\Controller\Controller; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -40,6 +41,12 @@ public function mainAction(): Response return $this->render('@ezdesign/content_usage/main.html.twig'); } + public function performAccessCheck() + { + parent::performAccessCheck(); + $this->denyAccessUnlessGranted(new Attribute('ad_admin', 'content_usage')); + } + /** * @throws NotFoundHttpException */ diff --git a/src/bundle/Controller/IdentificationController.php b/src/bundle/Controller/IdentificationController.php index 4fdf9d8..a1c1ee0 100644 --- a/src/bundle/Controller/IdentificationController.php +++ b/src/bundle/Controller/IdentificationController.php @@ -4,6 +4,7 @@ use AdrienDupuis\EzPlatformAdminBundle\Form\Type\IdentificationType; use AdrienDupuis\EzPlatformAdminBundle\Service\ContentUsageService; +use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute; use EzSystems\EzPlatformAdminUiBundle\Controller\Controller; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\Request; @@ -51,4 +52,10 @@ public function identificationAction(Request $request): Response ], ]); } + + public function performAccessCheck() + { + parent::performAccessCheck(); + $this->denyAccessUnlessGranted(new Attribute('ad_admin', 'identification')); + } } diff --git a/src/bundle/Resources/config/services/_default.yaml b/src/bundle/Resources/config/services/_default.yaml index 0fff016..969e3b1 100644 --- a/src/bundle/Resources/config/services/_default.yaml +++ b/src/bundle/Resources/config/services/_default.yaml @@ -12,3 +12,4 @@ services: tags: [controller.service_arguments] calls: - [setContainer, ['@service_container']] + - [performAccessCheck, []] diff --git a/src/bundle/Resources/translations/forms.en.yaml b/src/bundle/Resources/translations/forms.en.yaml new file mode 100644 index 0000000..99bfdeb --- /dev/null +++ b/src/bundle/Resources/translations/forms.en.yaml @@ -0,0 +1,4 @@ +role.policy.ad_admin: A.D.'s Admin +role.policy.ad_admin.all_functions: Admin / All functions +role.policy.ad_admin.content_usage: Admin / Content Usage +role.policy.ad_admin.identification: Admin / Identification diff --git a/src/bundle/Resources/translations/forms.fr.yaml b/src/bundle/Resources/translations/forms.fr.yaml new file mode 100644 index 0000000..d16f305 --- /dev/null +++ b/src/bundle/Resources/translations/forms.fr.yaml @@ -0,0 +1,2 @@ +role.policy.ad_admin.all_functions: Admin / Toutes les fonctions +role.policy.ad_admin.content_usage: Admin / Utilisation des contenus diff --git a/src/bundle/Security/PolicyProvider.php b/src/bundle/Security/PolicyProvider.php new file mode 100644 index 0000000..f8a0366 --- /dev/null +++ b/src/bundle/Security/PolicyProvider.php @@ -0,0 +1,19 @@ +addConfig([ + 'ad_admin' => [ + 'content_usage' => null, + 'identification' => null, + ], + ]); + } +}