Delimitar a v1 ao núcleo de compras com interruptores por módulo

Decisão de 30/11/2026: a v1 é só o núcleo (requisições, aprovações, cotações,
adjudicação e ordens, fornecedores, recepções, stock básico, facturas,
pagamentos externos, orçamentos, empresa, conflitos, auditoria, relatórios).

- config/modules.php: pessoas, armazem_avancado e fornecimento, desligados
  por omissão (SGC_MODULE_*), sem apagar código.
- EnsureModuleEnabled: rotas de módulos desligados respondem 404.
- Menus escondem as entradas desses módulos (disabledModulePaths partilhado);
  contextos people.* deixam de ser oferecidos; /avaliar sem ligações mortas.
- Testes: suite corre com os módulos ligados; ProductModulesTest e
  product-modules.test.tsx verificam núcleo disponível e módulos desligados.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 23:23:50 +02:00
co-authored by Claude Opus 5.5
parent 2f2f40b47e
commit f9558d4563
13 changed files with 358 additions and 20 deletions
+66
View File
@@ -0,0 +1,66 @@
<?php
use App\Enums\PurchasingRole;
use App\Models\Department;
use App\Models\Tenant;
use App\Models\User;
use App\Services\ProductModules;
use App\Services\WorkContext;
use Inertia\Testing\AssertableInertia as Assert;
// Âmbito da v1: só o núcleo de compras. Os módulos laterais desligam-se sem afectar o núcleo.
beforeEach(function () {
config(['modules.enabled' => ['pessoas' => false, 'armazem_avancado' => false, 'fornecimento' => false]]);
$tenant = Tenant::query()->create(['name' => 'Empresa do núcleo']);
$department = Department::query()->create(['tenant_id' => $tenant->id, 'name' => 'Operações']);
$this->admin = User::factory()->create(['tenant_id' => $tenant->id, 'department_id' => $department->id, 'purchasing_role' => PurchasingRole::Admin]);
});
test('core purchasing pages stay available with every lateral module off', function (string $path) {
$this->actingAs($this->admin)->get($path)->assertOk();
})->with([
'/dashboard', '/requisicoes', '/fornecedores', '/cotacoes', '/ordens', '/recepcoes',
'/stock', '/stock/operacoes', '/facturas', '/pagamentos', '/orcamentos', '/regras-investimento',
'/empresa', '/conflitos', '/relatorios',
]);
test('lateral module routes answer as missing when their module is off', function (string $path) {
$this->actingAs($this->admin)->get($path)->assertNotFound();
})->with([
'pessoas' => '/pessoas',
'pessoas: relatórios' => '/pessoas/relatorios',
'pessoas: portal público' => '/candidaturas/1',
'armazém: requisições internas' => '/stock/requisicoes',
'armazém: reposição automática' => '/stock/reposicao',
'armazém: lotes' => '/stock/lotes',
'fornecimento: planeado' => '/compras/fornecimento',
'fornecimento: equipamentos' => '/equipamentos',
'fornecimento: projectos e imobilizado' => '/projectos-imobilizado',
]);
test('a module switched on serves its routes again', function () {
config(['modules.enabled.fornecimento' => true]);
expect(app(ProductModules::class)->enabled('fornecimento'))->toBeTrue();
$this->actingAs($this->admin)->get('/equipamentos')->assertStatus(200);
});
test('menus receive the paths of disabled modules and keep the core ones', function () {
$this->actingAs($this->admin)->get('/dashboard')->assertOk()->assertInertia(fn (Assert $page) => $page
->where('modules', ['pessoas' => false, 'armazem_avancado' => false, 'fornecimento' => false])
->where('disabledModulePaths', fn ($paths) => collect($paths)->contains('/pessoas')
&& collect($paths)->contains('/stock/requisicoes')
&& collect($paths)->contains('/equipamentos')
&& ! collect($paths)->contains('/stock')
&& ! collect($paths)->contains('/requisicoes')
&& ! collect($paths)->contains('/compras')));
});
test('people work contexts are not offered while the people module is off', function () {
config(['work_context.composition' => 'sgc', 'work_context.entitlements' => [$this->admin->tenant_id => array_keys(WorkContext::OPTIONS)]]);
expect(app(WorkContext::class)->purchased($this->admin))->not->toContain('people.internal')->not->toContain('people.third_party')
->toContain('procurement.internal');
config(['modules.enabled.pessoas' => true]);
expect(app(WorkContext::class)->purchased($this->admin))->toContain('people.internal');
});
+44
View File
@@ -0,0 +1,44 @@
import { expect, test } from 'vitest';
import {
isModulePathDisabled,
procurementNavigation,
} from '@/lib/procurement-navigation';
const disabled = ['/pessoas', '/stock/requisicoes', '/compras/fornecimento'];
test('only paths served by disabled modules are hidden', () => {
expect(isModulePathDisabled('/pessoas', disabled)).toBe(true);
expect(isModulePathDisabled('/pessoas/relatorios', disabled)).toBe(true);
expect(
isModulePathDisabled('/compras/fornecimento?view=imports', disabled),
).toBe(true);
expect(isModulePathDisabled('/stock', disabled)).toBe(false);
expect(isModulePathDisabled('/stock/operacoes', disabled)).toBe(false);
expect(isModulePathDisabled('/pessoasx', disabled)).toBe(false);
expect(isModulePathDisabled('/requisicoes', [])).toBe(false);
});
test('navigation drops entries of disabled modules and keeps the core', () => {
const paths = (hidden: string[]) =>
procurementNavigation(
['admin'],
false,
undefined,
false,
false,
false,
false,
{},
hidden,
)
.flatMap((group) => group.entries)
.map((entry) => entry.path.split('?')[0]);
const all = paths([]);
const core = paths(disabled);
expect(all).toContain('/compras/fornecimento');
expect(core).not.toContain('/compras/fornecimento');
expect(core.some((path) => path.startsWith('/pessoas'))).toBe(false);
expect(core).toContain('/requisicoes');
expect(core).toContain('/stock');
});