oportunidades 6
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-10 21:17:46 +02:00
parent 01405cbf8a
commit 20971d523f
126 changed files with 44362 additions and 3496 deletions
+49 -13
View File
@@ -1,13 +1,21 @@
<?php
use App\Http\Middleware\EnsurePortalProfiles;
use App\Models\User;
use App\Services\OpportunityResourceInstallation;
use App\Services\PortalProfileAccess;
use App\Services\PortalSuperusers;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Http\Request;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Vite;
use Inertia\Inertia;
use Laravel\Fortify\Features;
use Laravel\Fortify\Fortify;
$root = dirname(__DIR__);
require_once $root.'/tools/portal-qa-environment.php';
@@ -23,19 +31,28 @@ $app = require $root.'/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
config(['investor-path.enabled' => true]);
config(['geometry-import.enabled' => true]);
config(['portal.interface_language' => 'pt-MZ']);
$identity = portalQaAssertTarget($target);
if (PHP_SAPI !== 'cli' && is_file($dir.'/portal-audit/qa-recovery-maintenance.json')) {
http_response_code(503);
header('Retry-After: 60');
header('Cache-Control: no-store');
header('X-Investmoz-QA-Target: '.$identity->database.':'.$identity->port);
echo 'QA temporariamente em recuperação técnica. Nenhuma alteração no ambiente ativo.';
return;
}
config(['portal.qa_synthetic_accounts_only' => true]);
require_once $root.'/tools/portal-qa-account-selection.php';
// Only expose the non-secret identity; passwords, TOTP secrets and recovery codes remain private.
\Laravel\Fortify\Fortify::loginView(fn (Request $request) => \Inertia\Inertia::render('auth/login', [
'canResetPassword' => \Laravel\Fortify\Features::enabled(\Laravel\Fortify\Features::resetPasswords()),
Fortify::loginView(fn (Request $request) => Inertia::render('auth/login', [
'canResetPassword' => Features::enabled(Features::resetPasswords()),
'status' => $request->session()->get('status'),
'qaAccount' => ['id' => 18, 'email' => User::findOrFail(18)->email],
]));
\Laravel\Fortify\Fortify::twoFactorChallengeView(function (Request $request) {
Fortify::twoFactorChallengeView(function (Request $request) {
$actor = User::findOrFail($request->session()->get('login.id'));
return \Inertia\Inertia::render('auth/two-factor-challenge', ['qaAccount' => ['id' => $actor->id, 'email' => $actor->email]]);
return Inertia::render('auth/two-factor-challenge', ['qaAccount' => ['id' => $actor->id, 'email' => $actor->email]]);
});
config(['portal.managers' => ['opportunity-manager@example.invalid', 'geo-manager-qa@example.invalid'], 'suitecrm.enabled' => false, 'investmoz_ai.enabled' => false]);
$sessions = $dir.'/qa-opportunity-resources-sessions';
@@ -45,33 +62,52 @@ if (! is_dir($sessions)) {
config(['session.files' => $sessions]);
config(['portal.opportunity_dashboard_access_enabled' => true, 'portal.qa_build_directory' => 'build-qa-opportunities']);
config(['portal.opportunity_specialized_drafts_enabled' => true]);
config(['portal.opportunity_modular_profiles_qa_enabled' => true]);
// Explicit synthetic acceptance subtype, never an approval/classification of a real opportunity.
config(['portal.opportunity_other_qa_subtypes.qa-test-subtype' => ['approved' => true, 'version' => 'synthetic-acceptance-v1',
'decision_reference' => 'Synthetic QA acceptance fixture only; real subtypes require functional approval',
'gates' => ['technical_review', 'legal_territorial_review']]]);
config(['portal.profile_access_enabled' => true]);
config(['portal.legacy_content_qa_enabled' => true]);
// QA-only bootstrap ceremony: fixed synthetic identities, normal authenticated MFA.
Illuminate\Support\Facades\Route::middleware(['web', 'auth', 'verified', \App\Http\Middleware\EnsurePortalProfiles::class])->post('/qa-auditoria/perfis/inicializar', function (Request $request) use ($dir) {
Route::middleware(['web', 'auth', 'verified', EnsurePortalProfiles::class])->post('/qa-auditoria/perfis/inicializar', function (Request $request) use ($dir) {
$actors = json_decode(file_get_contents($dir.'/portal-audit/profiles-v1-actors-private.json'), true, 512, JSON_THROW_ON_ERROR);
abort_unless($request->user()->id === $actors['bootstrap']['id'], 403);
config(['portal_profiles.bootstrap_authorized' => true]);
try {
app(\App\Services\PortalSuperusers::class)->initialize(User::findOrFail($actors['super_first']['id']), User::findOrFail($actors['super_second']['id']), $request->user());
app(PortalSuperusers::class)->initialize(User::findOrFail($actors['super_first']['id']), User::findOrFail($actors['super_second']['id']), $request->user());
} finally {
config(['portal_profiles.bootstrap_authorized' => false]);
}
return response()->json(['initialized' => true, 'holders' => [$actors['super_first']['id'], $actors['super_second']['id']]]);
});
// Read-only report derived from the sole audit matrix, accessible only on QA.
function authorizeQaAuditReader(Request $request): void
{
$access = app(\App\Services\PortalProfileAccess::class);
abort_unless($request->user()->can('manage-portal') || $access->has($request->user(), 'auditor') || ($access->superuser($request->user()) && $access->mfa($request->user())), 403);
$access = app(PortalProfileAccess::class);
$allowed = $request->user()->can('manage-portal') || $access->has($request->user(), 'auditor') || ($access->superuser($request->user()) && $access->mfa($request->user()));
if (! $allowed && ! $request->expectsJson()) {
if ($request->headers->has('X-Inertia')) {
// Render the refused destination as a full page instead of trapping login in an error modal.
abort(Inertia::location($request->url()));
}
// Refuse the administrative report without discarding an authenticated investor session.
// Keep a usable destination when Fortify returns to a previously requested report.
abort(response('<!doctype html><html lang="pt-MZ"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Acesso reservado — InvestMoz QA</title></head><body style="font:16px/1.6 system-ui;max-width:44rem;margin:auto;padding:24px"><main><h1>Relatório reservado à gestão e auditoria</h1><p>A sua sessão está autenticada. Este perfil não tem autorização para consultar o relatório administrativo.</p><p><a href="/dashboard">Abrir o painel</a></p><p><a href="/investimentos">Continuar os meus investimentos</a></p></main></body></html>', 403)->header('Cache-Control', 'private, no-store'));
}
abort_unless($allowed, 403);
}
Illuminate\Support\Facades\Route::middleware(['web', 'auth', 'verified'])->get('/qa-auditoria/pedidos-abertos', function (Request $request) use ($dir) {
Route::middleware(['web', 'auth', 'verified'])->get('/qa-auditoria/pedidos-abertos', function (Request $request) use ($dir) {
authorizeQaAuditReader($request);
return response()->file($dir.'/portal-audit/pedidos-abertos.html', ['Cache-Control' => 'private, no-store']);
});
foreach (['relatorio-executivo', 'backlog', 'perfis-v1-reconciliacao', 'roteiro-manual-perfis-v1'] as $reportName) {
Illuminate\Support\Facades\Route::middleware(['web', 'auth', 'verified'])->get('/qa-auditoria/'.$reportName, function (Request $request) use ($root, $reportName) {
foreach (['relatorio-executivo', 'backlog', 'perfis-v1-reconciliacao', 'roteiro-manual-perfis-v1', 'legado-piloto-qa'] as $reportName) {
Route::middleware(['web', 'auth', 'verified'])->get('/qa-auditoria/'.$reportName, function (Request $request) use ($root, $reportName) {
authorizeQaAuditReader($request);
$content = file_get_contents($root.'/docs/investmoz/v2/auditoria-portal/'.$reportName.'.md');
return response('<!doctype html><html lang="pt"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>InvestMoz — '.$reportName.'</title><style>body{font:16px/1.55 system-ui;max-width:1100px;margin:auto;padding:24px}pre{white-space:pre-wrap;overflow-wrap:anywhere;font:inherit}</style><pre>'.htmlspecialchars($content, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8').'</pre></html>')->header('Cache-Control', 'private, no-store');
});
}
@@ -145,10 +181,10 @@ header('X-Investmoz-QA-Target: '.$identity->database.':'.$identity->port);
header('X-Investmoz-QA-Key-Fingerprint: '.hash('sha256', app('encrypter')->getKey()));
header('X-Investmoz-QA-Config-Cache: bypassed');
require_once $root.'/tools/portal-qa-auth-trace.php';
$httpKernel = $app->make(\Illuminate\Contracts\Http\Kernel::class);
$httpKernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$httpKernel->prependMiddleware(PortalQaAuthTrace::class);
$httpKernel->appendMiddlewareToGroup('web', PortalQaSessionTrace::class);
$httpKernel->addToMiddlewarePriorityAfter(\Illuminate\Session\Middleware\StartSession::class, PortalQaSessionTrace::class);
$httpKernel->addToMiddlewarePriorityAfter(StartSession::class, PortalQaSessionTrace::class);
$httpKernel->appendMiddlewareToGroup('web', PortalQaAccountSelection::class);
$httpKernel->addToMiddlewarePriorityAfter(PortalQaSessionTrace::class, PortalQaAccountSelection::class);
$app->handleRequest(Request::capture());