@@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
@@ -64,6 +65,15 @@ class OpportunityManagement
|
||||
abort_unless($access->legacyWriteAllowed($actor), 403, 'O papel v1 não usa a criação legada para contornar o seu âmbito.');
|
||||
}
|
||||
abort_unless($this->installed(), 503, 'Instalação autenticada ainda necessária.');
|
||||
// Canonical common fields are authoritative. The editor may echo legacy
|
||||
// mirrors, but they must not impose a second, incompatible contract.
|
||||
if (is_array($input['canonical'] ?? null)) {
|
||||
foreach (['official_title' => 'title', 'executive_summary' => 'summary', 'demand_statement' => 'description', 'sector_id' => 'sector_id', 'promoter_type' => 'promoter_type'] as $source => $target) {
|
||||
if (array_key_exists($source, $input['canonical'])) {
|
||||
unset($input[$target]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = Validator::make($input, [
|
||||
'etag' => [$id ? 'required' : 'nullable', 'string', 'size:64'],
|
||||
'creation_key' => [$id ? 'nullable' : 'required', 'uuid'],
|
||||
@@ -115,6 +125,7 @@ class OpportunityManagement
|
||||
abort_if($record->trashed() || $record->status === 'archived', 409, 'Restaure antes de editar.');
|
||||
}
|
||||
$before = $record->getAttributes();
|
||||
$previousCanonical = $record->exists ? ($this->values($record)['canonical'] ?? []) : [];
|
||||
$changes = array_intersect_key($data, array_flip([...self::FIELDS, ...self::PRIVATE_DRAFT_FIELDS]));
|
||||
if (array_key_exists('canonical', $changes)) {
|
||||
$previous = $record->exists ? $this->values($record) : [];
|
||||
@@ -125,7 +136,10 @@ class OpportunityManagement
|
||||
// One entry of common data feeds the existing fields; a closed/public version stays untouched.
|
||||
foreach (['official_title' => 'title', 'executive_summary' => 'summary', 'demand_statement' => 'description', 'sector_id' => 'sector_id', 'promoter_type' => 'promoter_type'] as $source => $target) {
|
||||
if (array_key_exists($source, $changes['canonical'])) {
|
||||
$changes[$target] = $changes['canonical'][$source];
|
||||
$value = $changes['canonical'][$source];
|
||||
// Preserve the full text in canonical JSON; the legacy
|
||||
// summary column is only a bounded presentation mirror.
|
||||
$changes[$target] = $target === 'summary' && is_string($value) ? Str::limit($value, 499, '…') : $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,6 +170,9 @@ class OpportunityManagement
|
||||
$record->owner_user_id = $actor->id;
|
||||
$record->organization_id = $data['organization_id'] ?? null;
|
||||
$record->workflow_context = ['policy_version' => PortalProfileAccess::VERSION, 'contributors' => [$actor->id]];
|
||||
if (($internal=$access->internalAssignment($actor,$data['opportunity_category'] ?? '')) !== null) {
|
||||
$record->workflow_context=[...$record->workflow_context,'operator_organization_id'=>$internal->organization_id,'internal_assignment_id'=>$internal->id];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$record->management_version++;
|
||||
@@ -179,9 +196,11 @@ class OpportunityManagement
|
||||
}
|
||||
if ($record->owner_user_id !== null) {
|
||||
$context = $record->workflow_context ?? [];
|
||||
unset($context['approval'], $context['reviews']);
|
||||
unset($context['approval']);
|
||||
$context['content_revision'] = ($context['content_revision'] ?? 0) + 1;
|
||||
$context['contributors'] = array_values(array_unique([...($context['contributors'] ?? []), $actor->id]));
|
||||
$context['canonical_items'] = app(OpportunityCanonicalMetadata::class)->mutate(
|
||||
$previousCanonical, $this->values($record)['canonical'] ?? [], $context['canonical_items'] ?? [], $actor, $data['reason']);
|
||||
$record->workflow_context = $context;
|
||||
}
|
||||
$record->save();
|
||||
|
||||
Reference in New Issue
Block a user