37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Utilities;
|
|
|
|
use App\Models\Auth\User;
|
|
|
|
final class CourierProfilePermissions
|
|
{
|
|
public const SETTING_KEY = 'system.courier_profile_edit_user_ids';
|
|
|
|
public static function grantedUserIds(): array
|
|
{
|
|
$ids = setting(self::SETTING_KEY, []);
|
|
if (is_string($ids)) {
|
|
$ids = json_decode($ids, true) ?: [];
|
|
}
|
|
|
|
return array_values(array_unique(array_map('intval', is_array($ids) ? $ids : [])));
|
|
}
|
|
|
|
public static function canEdit(?User $actor = null): bool
|
|
{
|
|
$actor ??= user();
|
|
if (! $actor || ! $actor->enabled
|
|
|| ! in_array((int) $actor->id, self::grantedUserIds(), true)
|
|
|| ! $actor->companies()->where('companies.id', company_id())->exists()) {
|
|
return false;
|
|
}
|
|
|
|
$section = collect(SidebarPermissions::navigationFor($actor))->firstWhere('slug', 'courier-payables');
|
|
|
|
return collect($section['pages'] ?? [])
|
|
->flatMap(fn (array $page): array => [$page, ...($page['children'] ?? [])])
|
|
->contains('slug', 'courier-information');
|
|
}
|
|
}
|