44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ZenovaReportAccess
|
|
{
|
|
public const ROLE_IDS = [
|
|
'1650360764-424692c0-654a-4af2-zenova-64ce55c66088', // HO
|
|
'1787808155-9945ee91-7a22-4be6-b184-733610e66ddc', // Admin
|
|
];
|
|
|
|
public static function canView(): bool
|
|
{
|
|
$user = Auth::user();
|
|
if (!$user || ($user->domain ?? '') !== 'zenova') {
|
|
return false;
|
|
}
|
|
|
|
return count(array_intersect(self::roleIds($user->roles ?? []), self::ROLE_IDS)) > 0;
|
|
}
|
|
|
|
private static function roleIds($roles): array
|
|
{
|
|
if (is_string($roles)) {
|
|
$decoded = json_decode($roles, true);
|
|
$roles = is_array($decoded) ? $decoded : [];
|
|
}
|
|
if (!is_array($roles)) {
|
|
return [];
|
|
}
|
|
|
|
$ids = [];
|
|
foreach ($roles as $role) {
|
|
if (is_scalar($role) && (string) $role !== '') {
|
|
$ids[] = (string) $role;
|
|
}
|
|
}
|
|
|
|
return $ids;
|
|
}
|
|
}
|