@@ -10,6 +10,11 @@ final class InternalRequisitions
|
||||
{
|
||||
public function __construct(private RequisitionPort $port) {}
|
||||
|
||||
public static function supportsAdditionalLevels(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $record
|
||||
* @return array<string,mixed>|null
|
||||
@@ -58,6 +63,17 @@ final class InternalRequisitions
|
||||
$roles[] = 'finance';
|
||||
}
|
||||
|
||||
$additional = $policy['additional_levels'] ?? [];
|
||||
if (! is_array($additional) || count($additional) > 5) {
|
||||
throw new RequisitionFailure('Plano de aprovação inválido; máximo de oito níveis no circuito.', 422);
|
||||
}
|
||||
foreach (array_keys($additional) as $role) {
|
||||
if (! is_string($role) || ! preg_match('/^configured_[1-5]$/D', $role)) {
|
||||
throw new RequisitionFailure('Identificador de nível configurado inválido.', 422);
|
||||
}
|
||||
$roles[] = $role;
|
||||
}
|
||||
|
||||
return $roles;
|
||||
}
|
||||
|
||||
@@ -126,6 +142,9 @@ final class InternalRequisitions
|
||||
}
|
||||
$role = $step['role'];
|
||||
$this->port->authorize('step:'.$role, $record);
|
||||
if (! empty($record['approval_snapshot']['additional_levels']) && ($key === null || $version === null)) {
|
||||
throw new RequisitionFailure('A decisão deste plano exige a versão e a chave da operação; actualize a etapa antes de confirmar.', 422);
|
||||
}
|
||||
$status = $input['decision'] === 'rejected' ? 'rejected' : (count(array_filter($record['steps'], fn ($s) => $s['decision'] === 'pending')) > 1 ? 'pending' : 'approved');
|
||||
$result = $this->port->decided($record, $step, $input['decision'], $input['comment'] ?? null, $status);
|
||||
if ($status === 'rejected') {
|
||||
|
||||
Reference in New Issue
Block a user