Files
breadcrumb-the-shire/modules/helpdesk/lib/Module/Helpdesk/Providers/HelpdeskLayoutProvider.php

40 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace MintyPHP\Module\Helpdesk\Providers;
use MintyPHP\App\AppContainer;
use MintyPHP\App\Module\Contracts\LayoutContextProvider;
use MintyPHP\Service\Access\AuthorizationService;
final class HelpdeskLayoutProvider implements LayoutContextProvider
{
public function provide(array $session, AppContainer $container): array
{
$userId = (int) ($session['user']['id'] ?? 0);
if ($userId <= 0) {
return ['helpdesk.nav' => ['can_manage_settings' => false]];
}
try {
$authorizationService = $container->get(AuthorizationService::class);
$actorContext = ['actor_user_id' => $userId];
$canManageSettings = $authorizationService->authorize('helpdesk.settings.manage', $actorContext)->isAllowed();
$canViewTeam = $authorizationService->authorize('helpdesk.team-workload.view', $actorContext)->isAllowed();
$canViewRiskRadar = $authorizationService->authorize('helpdesk.risk-radar.view', $actorContext)->isAllowed();
$canManageSoftwareProducts = $authorizationService->authorize('helpdesk.software-products.manage', $actorContext)->isAllowed();
} catch (\Throwable) {
$canManageSettings = false;
$canViewTeam = false;
$canViewRiskRadar = false;
$canManageSoftwareProducts = false;
}
return ['helpdesk.nav' => [
'can_manage_settings' => $canManageSettings,
'can_view_team' => $canViewTeam,
'can_view_risk_radar' => $canViewRiskRadar,
'can_manage_software_products' => $canManageSoftwareProducts,
]];
}
}