2026-04-02 17:48:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Module\Helpdesk;
|
|
|
|
|
|
|
|
|
|
use MintyPHP\Service\Access\AuthorizationDecision;
|
|
|
|
|
use MintyPHP\Service\Access\AuthorizationPolicyInterface;
|
|
|
|
|
use MintyPHP\Service\Access\PermissionService;
|
|
|
|
|
|
|
|
|
|
final class HelpdeskAuthorizationPolicy implements AuthorizationPolicyInterface
|
|
|
|
|
{
|
|
|
|
|
public const ABILITY_ACCESS = 'helpdesk.access';
|
|
|
|
|
public const ABILITY_SETTINGS_MANAGE = 'helpdesk.settings.manage';
|
2026-04-05 18:46:54 +02:00
|
|
|
public const ABILITY_TEAM_WORKLOAD = 'helpdesk.team-workload.view';
|
2026-04-02 17:48:27 +02:00
|
|
|
|
|
|
|
|
public const PERMISSION_ACCESS = 'helpdesk.access';
|
|
|
|
|
public const PERMISSION_SETTINGS_MANAGE = 'helpdesk.settings.manage';
|
2026-04-05 18:46:54 +02:00
|
|
|
public const PERMISSION_TEAM_WORKLOAD = 'helpdesk.team-workload.view';
|
2026-04-02 17:48:27 +02:00
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly PermissionService $permissionService
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function supports(string $ability): bool
|
|
|
|
|
{
|
2026-04-05 18:46:54 +02:00
|
|
|
return in_array($ability, [self::ABILITY_ACCESS, self::ABILITY_SETTINGS_MANAGE, self::ABILITY_TEAM_WORKLOAD], true);
|
2026-04-02 17:48:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function authorize(string $ability, array $context = []): AuthorizationDecision
|
|
|
|
|
{
|
|
|
|
|
$actorUserId = (int) ($context['actor_user_id'] ?? 0);
|
|
|
|
|
if ($actorUserId <= 0) {
|
|
|
|
|
return AuthorizationDecision::deny(403, 'forbidden');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$permissionKey = match ($ability) {
|
|
|
|
|
self::ABILITY_ACCESS => self::PERMISSION_ACCESS,
|
|
|
|
|
self::ABILITY_SETTINGS_MANAGE => self::PERMISSION_SETTINGS_MANAGE,
|
2026-04-05 18:46:54 +02:00
|
|
|
self::ABILITY_TEAM_WORKLOAD => self::PERMISSION_TEAM_WORKLOAD,
|
2026-04-02 17:48:27 +02:00
|
|
|
default => null,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if ($permissionKey === null) {
|
|
|
|
|
return AuthorizationDecision::deny(403, 'forbidden');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$this->permissionService->userHas($actorUserId, $permissionKey)) {
|
|
|
|
|
return AuthorizationDecision::deny(403, 'forbidden');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AuthorizationDecision::allow();
|
|
|
|
|
}
|
|
|
|
|
}
|