78 lines
5.9 KiB
Python
78 lines
5.9 KiB
Python
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('''<!doctype html>
|
|
<html lang="pt"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Criação de oportunidade indisponível — InvesteMoz</title>
|
|
<style>body{font-family:system-ui,sans-serif;line-height:1.6;margin:0;background:#f7faf9;color:#19352d}main{max-width:46rem;margin:8vh auto;padding:2rem;background:white;border:1px solid #dce7e2;border-radius:.6rem}h1{font-size:1.6rem}a{color:#116145}nav{display:flex;gap:1.2rem;flex-wrap:wrap;margin-top:1.5rem}</style></head>
|
|
<body><main><p>InvesteMoz · 403</p><h1>Criação de oportunidade indisponível</h1><p role="alert">{{ $reason }}</p><p>Nenhum rascunho foi criado. A sessão mantém as permissões já atribuídas.</p><nav aria-label="Próximos passos"><a href="/minhas-oportunidades">Voltar às oportunidades</a><a href="/perfil/promotor">Consultar o perfil de Promotor</a><a href="/apoio">Pedir apoio</a></nav></main></body></html>
|
|
''','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}))
|