GeoNetAgent, LDAPWeb, server-audit, server-connection
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 lines
1.4 KiB

<?php
namespace App\Services;
use App\Models\GroupPermission;
use Illuminate\Support\Facades\Cache;
class PermissionService
{
private const CACHE_TTL = 300;
public function permissionsForGroups(array $groups): array
{
if (empty($groups)) {
return [];
}
$cacheKey = 'group_perms:' . md5(implode(',', $groups));
return Cache::remember($cacheKey, self::CACHE_TTL, function () use ($groups) {
return GroupPermission::permissionsForGroups($groups);
});
}
public function hasPermission(array $groups, string $permission): bool
{
return in_array($permission, $this->permissionsForGroups($groups), true);
}
public function allPermissions(): array
{
return [
'profile.view',
'profile.edit',
'dashboard.view',
'cmdb.view',
'cmdb.manage',
'cmdb.assign_owner',
'monitoring.view',
'ticketing.view',
'ticketing.create',
'ticketing.manage',
'mail.view',
'asset_mgmt.view',
'asset_mgmt.manage',
'geonet_agent.view',
'admin.users',
'admin.groups',
'admin.permissions',
];
}
public function flushCacheForGroups(array $groups): void
{
$cacheKey = 'group_perms:' . md5(implode(',', $groups));
Cache::forget($cacheKey);
}
}