commit14
This commit is contained in:
@@ -10,6 +10,9 @@ use Illuminate\Support\Facades\Schema;
|
||||
class OrganizationAccess
|
||||
{
|
||||
public const PERMISSIONS = [
|
||||
'warehouse_return_read' => 'Consultar devoluções de excedentes de entregas internas',
|
||||
'warehouse_return_prepare' => 'Declarar excedente não consumido de entrega interna própria',
|
||||
'warehouse_return_confirm' => 'Conferir ou recusar recepção independente do excedente no armazém (exige função de armazém)',
|
||||
'warehouse_request_review' => 'Autorizar ou rejeitar requisições internas ao armazém do departamento, de forma independente',
|
||||
'warehouse_request_deliver' => 'Entregar material de requisições internas autorizadas (exige função de armazém)',
|
||||
'warehouse_request_prepare' => 'Preparar requisições próprias ao armazém com destino de utilização',
|
||||
@@ -70,6 +73,18 @@ class OrganizationAccess
|
||||
if (! $this->active($user->tenant_id)) {
|
||||
return $user->purchasing_role === null || $user->purchasing_role === PurchasingRole::Configured ? [] : [$user->purchasing_role->value];
|
||||
}
|
||||
|
||||
return $this->configuredPermissions($user, $context);
|
||||
}
|
||||
|
||||
/** Project the saved profiles without activating them or granting authority.
|
||||
* @return list<string>
|
||||
*/
|
||||
public function configuredPermissions(User $user, ?string $context = null): array
|
||||
{
|
||||
if ($user->tenant_id === null || ! Schema::hasTable('organization_profiles') || ! Schema::hasTable('organization_memberships')) {
|
||||
return [];
|
||||
}
|
||||
$contextKey = $context;
|
||||
if ($contextKey === null && app()->bound('request') && request()->hasSession() && WorkContext::area(request()->path()) !== null && app(WorkContext::class)->enforced($user)) {
|
||||
$contextKey = app(WorkContext::class)->active(request());
|
||||
@@ -108,6 +123,15 @@ class OrganizationAccess
|
||||
if (! $this->active($user->tenant_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->configuredMaintenanceOnly($user);
|
||||
}
|
||||
|
||||
public function configuredMaintenanceOnly(User $user): bool
|
||||
{
|
||||
if ($user->tenant_id === null || ! Schema::hasTable('organization_memberships')) {
|
||||
return false;
|
||||
}
|
||||
$valid = DB::table('organization_memberships')->where('tenant_id', $user->tenant_id)->where('user_id', $user->id)->where(fn ($q) => $q->whereNull('expires_at')->orWhere('expires_at', '>', now()));
|
||||
|
||||
return (clone $valid)->where('maintenance', true)->exists() && ! (clone $valid)->where('maintenance', false)->exists();
|
||||
|
||||
Reference in New Issue
Block a user