Skip to content

Commit 4cfc1bf

Browse files
export_import - Fix access permission
1 parent c2feb9b commit 4cfc1bf

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/bundle/Controller/Admin/JobController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Ibexa\Contracts\AdminUi\Controller\Controller;
1313
use Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface;
1414
use Ibexa\Contracts\Core\Repository\PermissionResolver;
15+
use Ibexa\Core\Base\Exceptions\UnauthorizedException;
1516
use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute;
1617
use JMS\TranslationBundle\Annotation\Ignore;
1718
use JMS\TranslationBundle\Model\Message;
@@ -57,6 +58,10 @@ public function __construct(
5758

5859
public function list(Request $request): Response
5960
{
61+
if (!$this->permissionResolver->hasAccess('import_export', 'workflow.list')) {
62+
throw new UnauthorizedException('import_export', 'workflow.list', []);
63+
}
64+
6065
$page = $request->query->get('page') ?? 1;
6166

6267
$pagerfanta = new Pagerfanta(
@@ -81,6 +86,10 @@ function (int $offset, int $length): array {
8186

8287
public function create(Request $request): Response
8388
{
89+
if (!$this->permissionResolver->hasAccess('import_export', 'workflow.create')) {
90+
throw new UnauthorizedException('import_export', 'workflow.create', []);
91+
}
92+
8493
$job = Instantiator::instantiate(Job::class);
8594
$this->jobCreateFlow->bind($job);
8695

@@ -123,6 +132,10 @@ public function create(Request $request): Response
123132

124133
public function view(Job $job): Response
125134
{
135+
if (!$this->permissionResolver->hasAccess('import_export', 'job.views')) {
136+
throw new UnauthorizedException('import_export', 'job.views', []);
137+
}
138+
126139
return $this->render('@ibexadesign/import_export/job/view.html.twig', [
127140
'job' => $job,
128141
]);

src/bundle/Resources/config/menu.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
services:
22
AlmaviaCX\Bundle\IbexaImportExport\AdminUi\Menu\Event\MenuListener:
3+
arguments:
4+
$permissionResolver: '@Ibexa\Contracts\Core\Repository\PermissionResolver'
35
tags:
46
- { name: kernel.event_subscriber }
57

src/bundle/Resources/config/policies.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import_export:
2+
workflow.list: ~
23
workflow.create: ~
34
workflow.edit: ~
45
workflow.delete: ~

src/lib/AdminUi/Menu/Event/MenuListener.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66

77
use Ibexa\AdminUi\Menu\Event\ConfigureMenuEvent;
88
use Ibexa\AdminUi\Menu\MainMenuBuilder;
9+
use Ibexa\Contracts\Core\Repository\PermissionResolver;
10+
use Ibexa\Core\Base\Exceptions\UnauthorizedException;
911
use JMS\TranslationBundle\Model\Message;
1012
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
1113
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1214

1315
class MenuListener implements EventSubscriberInterface, TranslationContainerInterface
1416
{
17+
public function __construct(protected PermissionResolver $permissionResolver)
18+
{
19+
}
20+
1521
public static function getSubscribedEvents(): array
1622
{
1723
return [
@@ -21,6 +27,10 @@ public static function getSubscribedEvents(): array
2127

2228
public function onMenuConfigure(ConfigureMenuEvent $event): void
2329
{
30+
if (!$this->permissionResolver->hasAccess('import_export', 'workflow.list')) {
31+
return;
32+
}
33+
2434
$menu = $event->getMenu();
2535

2636
$contentMenu = $menu->getChild(MainMenuBuilder::ITEM_CONTENT);

0 commit comments

Comments
 (0)