feat(offers): implement phase four private details and confidentiality in QA

This commit is contained in:
2026-11-14 17:28:12 +02:00
parent 7691cab3bc
commit e431de8b42
29 changed files with 2356 additions and 12 deletions
+14 -1
View File
@@ -61,7 +61,11 @@ class VerifiedDocumentBinary
if ($table === 'opportunity_images') {
$query->orWhereRaw("payload->'derivatives' @> ?::jsonb", [json_encode([['document_id' => $document->id]], JSON_THROW_ON_ERROR)]);
}
$links = $links->concat($query->get(['opportunity_id', 'deleted_at', 'payload']));
$rows = $query->get(['opportunity_id', 'deleted_at', 'payload']);
foreach ($rows as $link) {
$link->resource_kind = $table;
}
$links = $links->concat($rows);
}
$privateOrigin = in_array($document->source_system ?? null, ['opportunity-resources', 'opportunity-image-derivatives'], true);
if (! $privateOrigin) {
@@ -72,6 +76,15 @@ class VerifiedDocumentBinary
}
$actor = request()->user();
abort_unless($actor instanceof User, 403, 'Anexo privado: é necessário acesso autorizado à oportunidade.');
foreach ($links as $link) {
$offer = Opportunity::withTrashed()->whereKey($link->opportunity_id)->first();
if ($offer?->isPrivateOfferPreparation() && $link->resource_kind === 'opportunity_documents') {
$allowed = $link->deleted_at === null && ! $offer->trashed() && app(PrivateOfferConfidentiality::class)->internal($actor, $offer);
app(PortalProfileAccess::class)->audit($actor, $allowed ? 'offer_proof_access_authorized' : 'offer_proof_access_denied',
['record_id' => $offer->id, 'document_id' => $document->id, 'record_version' => $offer->management_version, 'sha256' => trim($document->sha256)]);
abort_unless($allowed, 403, 'Comprovativo reservado à validação interna autorizada.');
}
}
foreach ($links as $link) {
$opportunity = Opportunity::whereKey($link->opportunity_id)->first();
if ($link->deleted_at === null && $opportunity && $opportunity->status !== 'archived'