feat: consolidar desenvolvimentos do portal InvestMoz

This commit is contained in:
2026-11-03 23:32:32 +02:00
parent 1da273f1f3
commit 36c8cadb49
345 changed files with 110714 additions and 2799 deletions
+14 -10
View File
@@ -2,7 +2,6 @@
namespace App\Services;
use App\Jobs\ScanDocumentForMalware;
use App\Models\Opportunity;
use App\Models\User;
use Illuminate\Http\Exceptions\HttpResponseException;
@@ -69,13 +68,14 @@ class OpportunityResources
}
$stored = null;
$documentId = null;
$scanContext = null;
if ($file) {
[$stored, $documentId] = $this->store($kind, $file);
} elseif (! $id && $kind !== 'locations') {
throw ValidationException::withMessages(['file' => 'Selecione o ficheiro original.']);
}
try {
$result = DB::transaction(function () use ($actor, $opportunityId, $kind, $table, $data, $payload, $file, $id, $stored, $documentId) {
$result = DB::transaction(function () use ($actor, $opportunityId, $kind, $table, $data, $payload, $file, $id, $stored, $documentId, &$scanContext) {
$opportunity = $this->lock($opportunityId, $data['etag']);
app(PortalProfileAccess::class)->authorize($actor, 'edit', $opportunity);
$record = $id ? DB::table($table)->where('id', $id)->where('opportunity_id', $opportunityId)->lockForUpdate()->first() : null;
@@ -136,22 +136,21 @@ class OpportunityResources
$this->audit($actor, $kind, $record, $after, $data['reason'], 'saved');
$opportunity->management_version++;
$opportunity->save();
if ($documentId !== null) {
$scanContext = app(OpportunityTechnicalIncidents::class)->scanContext($actor, $opportunity);
}
return $after;
});
} catch (\Throwable $error) {
if ($stored) {
Storage::disk('local')->delete($stored);
app(OpportunityResourceFileCleanup::class)->afterFailure([$stored], $error);
}
throw $error;
}
if ($documentId) {
try {
ScanDocumentForMalware::dispatch($documentId)->afterCommit();
} catch (\Throwable) {
DB::table('documents')->where('id', $documentId)->where('malware_scan_status', '!=', 'clean')->update(['status' => 'quarantined', 'malware_scan_status' => 'failed', 'malware_failure_reason' => 'queue_dispatch_failed', 'updated_at' => now()]);
}
app(OpportunityScanDispatch::class)->dispatch($documentId, $scanContext);
}
return $result;
@@ -286,8 +285,13 @@ class OpportunityResources
}
}
$id = (string) Str::uuid();
$key = $file->storeAs('opportunity-resources', $id, 'local');
abort_unless(is_string($key), 500, 'Falha ao guardar original privado.');
try {
$key = $file->storeAs('opportunity-resources', $id, 'local');
abort_unless(is_string($key), 500, 'Falha ao guardar original privado.');
} catch (\Throwable $error) {
app(OpportunityResourceFileCleanup::class)->afterFailure(['opportunity-resources/'.$id], $error);
throw $error;
}
return [$key, $id];
}