Files
Investidor-V2/outputs/investmoz-audit-current-20261012/patch-B8-land-context.py
T
nala ba1c0340ea
tests / ci (push) Canceled after 0s
oportunidades 8
2026-10-14 08:25:30 +02:00

69 lines
7.6 KiB
Python

from pathlib import Path
import json,hashlib
OUT=Path(__file__).resolve().parent;ROOT=OUT.parents[1];QA=ROOT/'storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';backup=QA/'storage/app/private/option-B8-before';proof={'active_writes':0,'schema_changes':0,'optional_explicit_context_only':True,'delta':[]}
changes={
'app/Http/Requests/StoreLandAssistanceCaseRequest.php':[
("array:support_kind,request_description,project_reference,applicant_category", "array:support_kind,request_description,project_reference,investor_path_case_id,applicant_category"),
(" 'payload.project_reference' => ['nullable', 'string', 'max:160'],", " 'payload.project_reference' => ['nullable', 'string', 'max:160'],\n 'payload.investor_path_case_id' => ['nullable', 'uuid'],"),
(" $payload = $this->input('payload', []);", """ $payload = $this->input('payload', []);
$context = is_array($payload) ? ($payload['investor_path_case_id'] ?? null) : null;
if ($context !== null) {
$case = is_string($context) && \\Illuminate\\Support\\Str::isUuid($context)
? \\Illuminate\\Support\\Facades\\DB::table('desk_cases')->where('id', $context)->first() : null;
if (! config('investor-path.enabled') || ! $case || (int) $case->user_id !== $this->user()->id
|| $case->closed_at || ! $case->journey_id
|| ! \\Illuminate\\Support\\Facades\\DB::table('investor_journeys')->where('id', $case->journey_id)->whereNotNull('path_definition_id')->whereNull('deleted_at')->exists()) {
$validator->errors()->add('payload.investor_path_case_id', 'Use um dossier do seu percurso disponível para preparação. O acesso direto a Terra e DUAT continua disponível.');
}
}
if ($this->route('id')) {
$previous = \\App\\Models\\LandAssistanceCase::whereKey($this->route('id'))->where('user_id', $this->user()->id)->first();
$bound = $previous?->payload['investor_path_case_id'] ?? null;
if ($bound !== null && $context !== $bound) {
$validator->errors()->add('payload.investor_path_case_id', 'Preserve o vínculo deste pedido ao dossier original.');
}
}""")],
'app/Http/Controllers/LandAssistanceController.php':[
(" public function create(Request $request): Response\n {\n return Inertia::render", " public function create(Request $request): Response\n {\n $context = $request->validate(['context' => ['nullable', 'uuid']])['context'] ?? null;\n $dossier = null;\n if ($context !== null) {\n $case = app(\\App\\Services\\VirtualDesk::class)->case($request->user(), $context);\n abort_unless(config('investor-path.enabled') && (int) $case->user_id === $request->user()->id && ! $case->closed_at && $case->journey_id\n && DB::table('investor_journeys')->where('id', $case->journey_id)->whereNotNull('path_definition_id')->whereNull('deleted_at')->exists(), 403);\n $dossier = ['id' => $case->id, 'title' => $case->title, 'url' => '/investimentos/'.$case->id];\n }\n return Inertia::render"),
(" 'case' => null,", " 'case' => null,\n 'returnDossier' => $dossier,"),
(" 'case' => $case->only(['id', 'reference', 'version', 'status', 'payload']),", " 'case' => $case->only(['id', 'reference', 'version', 'status', 'payload']),\n 'returnDossier' => $this->dossierContext($case),"),
(" 'declaredOrigin' => $countries->describe($payload['declared_origin_country_code'] ?? null), 'territoryPaths' => $paths];", " 'declaredOrigin' => $countries->describe($payload['declared_origin_country_code'] ?? null), 'territoryPaths' => $paths, 'returnDossier' => $this->dossierContext($case)];"),
(" public function manage(Request $request): Response", """ private function dossierContext(LandAssistanceCase $case): ?array
{
$id = $case->payload['investor_path_case_id'] ?? null;
$actor = request()->user();
if (! $actor || (int) $case->user_id !== $actor->id || ! is_string($id) || ! Str::isUuid($id) || ! config('investor-path.enabled')) {
return null;
}
$dossier = DB::table('desk_cases')->where('id', $id)->where('user_id', $actor->id)->first();
return $dossier ? ['id' => $dossier->id, 'title' => $dossier->title, 'url' => '/investimentos/'.$dossier->id] : null;
}
public function manage(Request $request): Response""")],
'app/Services/InvestorPath.php':[
(" return ['case' => ['id' => $id, 'title' => $case->title, 'version' => $case->version, 'closed' => $case->closed_at !== null],", """ $landCase = (int) $case->user_id === $actor->id
? \\App\\Models\\LandAssistanceCase::where('user_id', $actor->id)->latest('updated_at')->get()
->first(fn ($land) => ($land->payload['investor_path_case_id'] ?? null) === $id) : null;
return ['case' => ['id' => $id, 'title' => $case->title, 'version' => $case->version, 'closed' => $case->closed_at !== null],"""),
("'partners' => '/parcerias/painel?context='.$id]];", "'partners' => '/parcerias/painel?context='.$id,\n 'land' => (int) $case->user_id === $actor->id ? ($landCase ? '/investidor/terra-duat/'.$landCase->id : '/investidor/terra-duat/novo?context='.$id) : null]];")],
'resources/js/pages/land-assistance/form.tsx':[
(" countries,\n}: {", " countries,\n returnDossier,\n}: {"),
(" countries: Country[];", " countries: Country[];\n returnDossier?: { id: string; title: string; url: string } | null;"),
("() => existing?.payload ?? emptyPayload(user)", "() => existing?.payload ?? { ...emptyPayload(user), ...(returnDossier ? { investor_path_case_id: returnDossier.id } : {}) }"),
(' <header className="space-y-2">', ' <header className="space-y-2">\n {returnDossier && <Link className="underline" href={returnDossier.url}>Voltar ao dossier: {returnDossier.title}</Link>}')],
'resources/js/pages/land-assistance/case.tsx':[
(" management: boolean;", " management: boolean;\n returnDossier?: { id: string; title: string; url: string } | null;"),
(" territoryPaths,\n}: Props", " territoryPaths,\n returnDossier,\n}: Props"),
(' <header className="space-y-2">', ' <header className="space-y-2">\n {returnDossier && <Link className="underline" href={returnDossier.url}>Voltar ao dossier: {returnDossier.title}</Link>}')],
'resources/js/pages/investor-path/show.tsx':[(" territory: 'Território e mapas',", " territory: 'Território e mapas',\n land: 'Preparar Terra e DUAT',")]
}
for rel,replacements in changes.items():
p=QA/rel;before=p.read_bytes();b=backup/p.name
if not b.exists():b.write_bytes(before)
t=before.decode('utf-8-sig').replace('\r\n','\n')
for old,new in replacements:
assert t.count(old)==1,(rel,old[:70],t.count(old));t=t.replace(old,new)
p.write_text(t,encoding='utf-8',newline='');proof['delta'].append({'path':rel,'before_sha256':hashlib.sha256(before).hexdigest(),'QA_sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'active_sha256':hashlib.sha256((ROOT/rel).read_bytes()).hexdigest()})
(OUT/'option-B8-land-context-delta.json').write_text(json.dumps(proof,indent=2)+'\n',encoding='utf-8');print(json.dumps({'files':len(proof['delta']),'active_writes':0,'schema_changes':0}))