from pathlib import Path import hashlib,json qa=Path('C:/Users/macbook/.config/investmoz/promotor-contexto-QA-20261015/source');out=Path(__file__).resolve().parent path=qa/'app/Services/PortalProfileAccess.php';s=path.read_text('utf-8') old=""" if (! $this->mfa($actor)) { return false; } return DB::table('portal_security_approvals')""" new=""" // Normal Promotor authority comes from its existing scope, not from the // Superutilizador membership. Other/extraneous actions retain elevation. if (in_array($action, ['view', 'edit'], true) && $recordId !== null) { $record = Opportunity::withTrashed()->find($recordId); if ($record && $record->owner_user_id !== null && $this->promoterRecordScope($actor, $record)) { return true; } } if (! $this->mfa($actor)) { return false; } return DB::table('portal_security_approvals')""" assert s.count(old)==1;s=s.replace(old,new) old="return $included && $this->available() && $this->scoped($actor, 'promoter', $organization, $type) && $this->operational($actor, 'create');" new="""// This is creation as an authorized Promotor, never an exceptional SU act. return $included && $this->available() && $this->scoped($actor, 'promoter', $organization, $type) && ! $this->has($actor, 'auditor');""" assert s.count(old)==1;s=s.replace(old,new) old=" $query->whereIn('id', $ids);" new=""" $query->where(function ($eligible) use ($ids, $actor) { $eligible->whereIn('id', $ids); if ($this->has($actor, 'auditor')) { return; } foreach ($this->grants($actor, 'promoter') as $grant) { $internal = $grant->source === 'internal-portal-designation'; if (($internal && app(PortalInternalDesignation::class)->organization($grant->organization_id) === null) || (! $internal && ! $this->represents($actor, $grant->organization_id))) { continue; } $eligible->orWhere(function ($normal) use ($actor, $grant, $internal) { $normal->whereNotNull('owner_user_id')->whereIn('opportunity_category', json_decode($grant->opportunity_types, true)); if ($internal) { $normal->where(fn ($q) => $q->where('owner_user_id', $actor->id)->orWhereJsonContains('workflow_context->contributors', $actor->id)) ->where('workflow_context->operator_organization_id', $grant->organization_id); } elseif ($grant->organization_id !== null) { $normal->where('organization_id', $grant->organization_id); } else { $normal->whereNull('organization_id')->where('owner_user_id', $actor->id); } }); } });""" assert s.count(old)==1;s=s.replace(old,new);path.write_text(s,'utf-8') path=qa/'app/Http/Controllers/PortalProfileController.php';s=path.read_text('utf-8') old='public function edit(Request $request, PortalProfileAccess $access, ?int $id = null): Response' new='public function edit(Request $request, PortalProfileAccess $access, ?int $id = null): Response|\\Symfony\\Component\\HttpFoundation\\Response' assert s.count(old)==1;s=s.replace(old,new) old=" abort_unless($access->navigation($request->user())['contexts'] ?? [], 403);" new=""" if (! ($access->navigation($request->user())['contexts'] ?? [])) { $reason = $access->has($request->user(), 'auditor') ? 'O papel de Auditor permite consulta e impede a criação de oportunidades.' : 'Esta conta não dispõe de um contexto ativo de Promotor para uma organização e modalidade autorizadas. Confirme a vigência, o âmbito e os tipos atribuídos na gestão de perfis. A elevação excecional de Superutilizador não substitui a autorização de Promotor.'; if ($request->expectsJson()) { abort(403, $reason); } return response()->view('profiles.creation-unavailable', ['reason' => $reason], 403); }""" assert s.count(old)==1;s=s.replace(old,new);path.write_text(s,'utf-8') view=qa/'resources/views/profiles/creation-unavailable.blade.php';view.parent.mkdir(parents=True,exist_ok=True);assert not view.exists() view.write_text(''' Criação de oportunidade indisponível — InvesteMoz

InvesteMoz · 403

Criação de oportunidade indisponível

{{ $reason }}

Nenhum rascunho foi criado. A sessão mantém as permissões já atribuídas.

''','utf-8') paths=['app/Services/PortalProfileAccess.php','app/Http/Controllers/PortalProfileController.php','resources/views/profiles/creation-unavailable.blade.php'] (out/'DELTA-QA.json').write_text(json.dumps({'paths':paths,'source_count':3,'build_changed':False,'migrations':0,'role_changes':0,'active_changed':False},indent=2)+'\n','utf-8');print(json.dumps({'QA_sources_changed':3,'build_changed':False,'active_changes':0}))