This commit is contained in:
2026-11-02 20:27:11 +02:00
parent b44378b899
commit badaada043
300 changed files with 17458 additions and 1056 deletions
+19 -1
View File
@@ -25,6 +25,24 @@ class SupplyPlanning
return $actor->hasFunctions($functions) && ! app(OrganizationAccess::class)->maintenanceOnly($actor);
}
public function independentReviewer(User $actor, SupplyRecord $record): bool
{
return $actor->tenant_id === $record->tenant_id && $this->allows($actor, 'supply_review')
&& ! in_array($actor->id, $record->snapshot['contributors'] ?? [$record->created_by], true);
}
/** Eligibility to confer, not a promise that changed sources permit approval. */
public function canReview(User $actor, SupplyRecord $record, string $action = 'approve'): bool
{
if (! in_array($record->kind, ['agreement', 'policy'], true) || ! in_array($action, ['approve', 'return', 'suspend'], true)
|| ! $this->independentReviewer($actor, $record)) {
return false;
}
$latest = $this->latest($record->kind)->where('record_key', $record->record_key)->first();
return $latest?->id === $record->id && ($action === 'suspend' ? $record->state === 'approved' : in_array($record->state, ['draft', 'returned'], true));
}
/** @return Builder<SupplyRecord> */
public function latest(string $kind)
{
@@ -115,7 +133,7 @@ class SupplyPlanning
$data = $old->data;
if ($kind !== 'import') {
$this->check(in_array($action, ['approve', 'return', 'suspend'], true), 'action', 'Acção incompatível com este registo.');
$this->check(! in_array($actor->id, $old->snapshot['contributors'] ?? [$old->created_by], true), 'action', 'A conferência exige uma pessoa que não tenha preparado esta versão ou as anteriores.');
$this->check($this->independentReviewer($actor, $old), 'action', 'A conferência exige uma pessoa que não tenha preparado esta versão ou as anteriores.');
$this->check($action === 'suspend' ? $old->state === 'approved' : in_array($old->state, ['draft', 'returned'], true), 'action', 'Estado incompatível.');
$state = ['approve' => 'approved', 'return' => 'returned', 'suspend' => 'suspended'][$action];
} else {