Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add policies #16

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/bundle/AdrienDupuisEzPlatformAdminBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
7 changes: 7 additions & 0 deletions src/bundle/Controller/ContentUsageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
7 changes: 7 additions & 0 deletions src/bundle/Controller/IdentificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,4 +52,10 @@ public function identificationAction(Request $request): Response
],
]);
}

public function performAccessCheck()
{
parent::performAccessCheck();
$this->denyAccessUnlessGranted(new Attribute('ad_admin', 'identification'));
}
}
1 change: 1 addition & 0 deletions src/bundle/Resources/config/services/_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ services:
tags: [controller.service_arguments]
calls:
- [setContainer, ['@service_container']]
- [performAccessCheck, []]
4 changes: 4 additions & 0 deletions src/bundle/Resources/translations/forms.en.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/bundle/Resources/translations/forms.fr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
role.policy.ad_admin.all_functions: Admin / Toutes les fonctions
role.policy.ad_admin.content_usage: Admin / Utilisation des contenus
19 changes: 19 additions & 0 deletions src/bundle/Security/PolicyProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace AdrienDupuis\EzPlatformAdminBundle\Security;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigBuilderInterface;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Security\PolicyProvider\PolicyProviderInterface;

class PolicyProvider implements PolicyProviderInterface
{
public function addPolicies(ConfigBuilderInterface $configBuilder)
{
$configBuilder->addConfig([
'ad_admin' => [
'content_usage' => null,
'identification' => null,
],
]);
}
}