-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathCustomLimitationController.php
More file actions
59 lines (48 loc) · 1.83 KB
/
CustomLimitationController.php
File metadata and controls
59 lines (48 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php declare(strict_types=1);
namespace App\Controller;
use App\Security\Limitation\CustomLimitationValue;
use Ibexa\Contracts\AdminUi\Controller\Controller;
use Ibexa\Contracts\AdminUi\Permission\PermissionCheckerInterface;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\User\Controller\AuthenticatedRememberedCheckTrait;
use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class CustomLimitationController extends Controller
{
use AuthenticatedRememberedCheckTrait {
AuthenticatedRememberedCheckTrait::performAccessCheck as public traitPerformAccessCheck;
}
public function __construct(
// ...,
private readonly PermissionResolver $permissionResolver,
private readonly PermissionCheckerInterface $permissionChecker
) {
}
// Controller actions...
public function customAction(Request $request): Response
{
// ...
if ($this->getCustomLimitationValue()) {
// Action only for user having the custom limitation checked
}
return new Response('<html><body>...</body></html>');
}
private function getCustomLimitationValue(): bool
{
$hasAccess = $this->permissionResolver->hasAccess('custom_module', 'custom_function_2');
if (is_bool($hasAccess)) {
return $hasAccess;
}
$customLimitationValues = $this->permissionChecker->getRestrictions(
$hasAccess,
CustomLimitationValue::class
);
return $customLimitationValues['value'] ?? false;
}
public function performAccessCheck(): void
{
$this->traitPerformAccessCheck();
$this->denyAccessUnlessGranted(new Attribute('custom_module', 'custom_function_2'));
}
}