Sessoes 1-6 acumuladas: hardening B2, defesa em camadas, +192 testes

Repositorio estava ha ~5 sessoes sem commit. Consolida tudo desde d088a89.

Ver commit.md na raiz para descricao completa por sessao.

# Numeros
- A# auditoria abertos: 0/30
- V# verificacoes abertos: 5/52 (todos adiados com plano)
- T# testes escritos: 10/10
- Vitest: 192/192
- SQL integration: 33/33
- E2E (Playwright, novo): 5/5
- Migrations: 17 (10 novas Sessao 6)
- Areas auditadas: 7 (+documentos com 10 V#)

# Highlights Sessao 6 (hoje)
- V#34/V#41 Opcao B2: tenant_features com plano + override (RPC SECURITY DEFINER, tela /saas/tenant-features)
- A#20 rev2 self-hosted: defesa em 5 camadas (honeypot + rate limit + math captcha condicional + paranoid mode + dashboard /saas/security)
- Documentos hardening (V#43-V#49): tenant scoping em storage policies (vazamento entre clinicas eliminado), RPC validate_share_token, signatures policy granular
- SaaS Twilio Config (/saas/twilio-config): UI editavel para SID/webhook/cotacao; AUTH_TOKEN permanece em env var
- T#9 + T#10: useAgendaEvents.spec.js + Playwright E2E (descobriu bug no front que foi corrigido)

# Sessoes anteriores (1-5) consolidadas
- Sessao 1: auth/router/session, normalizeRole extraido
- Sessao 2: agenda - composables/services consolidados
- Sessao 3: pacientes - tenant_id em todas queries
- Sessao 4: security review pagina publica - 14/15 vulnerabilidades corrigidas
- Sessao 5: SaaS - P0 (A#30: 7 tabelas com RLS off corrigidas)

# .gitignore ajustado
- supabase/* + !supabase/functions/ (mantem 10 edge functions, ignora .temp/migrations gerados pelo CLI)
- database-novo/backups/ (regeneravel via db.cjs backup)
- test-results/ + playwright-report/
- .claude/settings.local.json (config local com senha de dev removida do tracking)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Leonardo
2026-04-19 15:42:46 -03:00
parent d088a89fb7
commit 7c20b518d4
175 changed files with 37325 additions and 37968 deletions
+42 -14
View File
@@ -33,6 +33,7 @@ const saving = ref(false);
const isEdit = ref(false);
const q = ref('');
const showInactive = ref(false);
const form = ref({
id: null,
@@ -86,8 +87,10 @@ const filteredRows = computed(() => {
const term = String(q.value || '')
.trim()
.toLowerCase();
if (!term) return rows.value;
return (rows.value || []).filter((r) => {
let list = rows.value || [];
if (!showInactive.value) list = list.filter((r) => r.is_active !== false);
if (!term) return list;
return list.filter((r) => {
return [r.key, r.name, r.descricao].some((s) =>
String(s || '')
.toLowerCase()
@@ -99,7 +102,7 @@ const filteredRows = computed(() => {
async function fetchAll() {
loading.value = true;
try {
const { data, error } = await supabase.from('features').select('id, key, name, descricao, created_at').order('key', { ascending: true });
const { data, error } = await supabase.from('features').select('id, key, name, descricao, created_at, is_active').order('key', { ascending: true });
if (error) throw error;
rows.value = data || [];
@@ -192,26 +195,40 @@ async function save() {
function askDelete(row) {
confirm.require({
message: `Excluir o recurso "${row.key}"?`,
header: 'Confirmar exclusão',
message: `Depreciar o recurso "${row.key}"? Tenants que já têm o recurso continuam com ele; só some do catálogo.`,
header: 'Depreciar recurso',
icon: 'pi pi-exclamation-triangle',
acceptClass: 'p-button-danger',
accept: () => doDelete(row)
accept: () => doSoftDelete(row, false)
});
}
async function doDelete(row) {
function askReactivate(row) {
confirm.require({
message: `Reativar o recurso "${row.key}"? Volta ao catálogo e fica disponível para novos planos.`,
header: 'Reativar recurso',
icon: 'pi pi-check',
acceptClass: 'p-button-success',
accept: () => doSoftDelete(row, true)
});
}
async function doSoftDelete(row, reactivate) {
try {
const { error } = await supabase.from('features').delete().eq('id', row.id);
const { error } = await supabase.from('features').update({ is_active: !!reactivate }).eq('id', row.id);
if (error) throw error;
toast.add({ severity: 'success', summary: 'Ok', detail: 'Recurso excluído.', life: 2500 });
toast.add({
severity: 'success',
summary: 'Ok',
detail: reactivate ? 'Recurso reativado.' : 'Recurso depreciado.',
life: 2500
});
await fetchAll();
} catch (e) {
const hint = isFkViolation(e) ? 'Este recurso está vinculado a planos ou módulos. Remova o vínculo antes de excluir.' : '';
toast.add({
severity: 'error',
summary: 'Erro',
detail: hint ? `${e?.message}${hint}` : e?.message || String(e),
detail: e?.message || String(e),
life: 5200
});
}
@@ -288,7 +305,7 @@ onBeforeUnmount(() => {
<!-- content -->
<div class="px-3 md:px-4 pb-8 flex flex-col gap-4">
<!-- Search -->
<div>
<div class="flex items-center gap-3 flex-wrap">
<FloatLabel variant="on" class="w-full md:w-[380px]">
<IconField class="w-full">
<InputIcon class="pi pi-search" />
@@ -296,6 +313,10 @@ onBeforeUnmount(() => {
</IconField>
<label for="features_search">Buscar por key, nome ou descrição</label>
</FloatLabel>
<label class="inline-flex items-center gap-2 text-[0.95rem] text-[var(--text-color-secondary)] cursor-pointer">
<input type="checkbox" v-model="showInactive" class="accent-current" />
Mostrar depreciados
</label>
</div>
<DataTable :value="filteredRows" dataKey="id" :loading="loading" stripedRows responsiveLayout="scroll">
@@ -330,11 +351,18 @@ onBeforeUnmount(() => {
<Column field="created_at" header="Criado em" sortable style="width: 13rem" />
<Column header="Ações" style="width: 10rem">
<Column header="Status" style="width: 8rem">
<template #body="{ data }">
<Tag :value="data.is_active === false ? 'depreciado' : 'ativo'" :severity="data.is_active === false ? 'warn' : 'success'" />
</template>
</Column>
<Column header="Ações" style="width: 12rem">
<template #body="{ data }">
<div class="flex gap-2 justify-end">
<Button icon="pi pi-pencil" severity="secondary" outlined @click="openEdit(data)" />
<Button icon="pi pi-trash" severity="danger" outlined @click="askDelete(data)" />
<Button v-if="data.is_active !== false" icon="pi pi-trash" severity="danger" outlined @click="askDelete(data)" v-tooltip.top="'Depreciar'" />
<Button v-else icon="pi pi-replay" severity="success" outlined @click="askReactivate(data)" v-tooltip.top="'Reativar'" />
</div>
</template>
</Column>