سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 20:45 UTC
test: require all production Slice B migration archives
davoodmehraban89 committed
Sep 30, 2026 at 06:57 UTC
502e557a28a195ed073c2a3fb648208a423f6be6
1 file changed
+6
-6
scripts/slice-b-rbac-check.mjs
+6
-6
@@ -1,10 +1,10 @@
1
import fs from 'node:fs';
2
import path from 'node:path';
3
-const root=process.cwd(),migrationsDir=path.join(root,'supabase','migrations');
4
-const files=fs.readdirSync(migrationsDir).filter(x=>(x.includes('organization_membership_rbac_foundation')||x.includes('office_shared_rbac_and_referrals'))&&x.endsWith('.sql'));
5
-if(files.length!==2)throw new Error(`expected two archived Slice B migrations, found ${files.length}`);
6
-const sql=files.map(f=>fs.readFileSync(path.join(migrationsDir,f),'utf8')).join('\n');
7
-const must=['create table public.organizations','create table public.organization_units','create table public.organization_members','create table public.member_module_permissions','create table public.organization_audit','add column if not exists organization_id uuid','private.current_organization_ids','private.has_org_capability','private.record_in_member_scope','private.record_confidentiality_allowed',"capabilities <@ array['read','create','edit','delete','approve','register','refer','archive','configure']::text[]","scope_type in ('own','unit','branch','company','organization')",'alter table public.organizations enable row level security','alter table public.organization_members enable row level security','alter table public.member_module_permissions enable row level security','alter table public.organization_audit enable row level security','grant select on public.organizations to authenticated','grant select on public.organization_members to authenticated','grant select on public.member_module_permissions to authenticated','create or replace function public.finora_sync_records','p_organization_id uuid','create or replace function public.office_refer_correspondence','create or replace function public.organization_set_member_permission','create or replace function public.organization_add_member','organization_audit_immutable','correspondence_referrals_immutable','private.can_access_office_storage','revoke all on function private.',"set search_path='' ".trim()];
3
+const root=process.cwd(),migrationsDir=path.join(root,'supabase','migrations'),migrationFiles=fs.readdirSync(migrationsDir).filter(x=>x.endsWith('.sql'));
4
+const requiredFiles=['20260930031853_organization_membership_rbac_foundation.sql','20260930031942_office_shared_rbac_and_referrals.sql','20260930032615_slice_b_rbac_fk_indexes.sql','20260930032654_harden_legacy_office_storage_member_writes.sql'];
5
+for(const f of requiredFiles)if(!migrationFiles.includes(f))throw new Error(`missing archived production migration: ${f}`);
6
+const sql=requiredFiles.map(f=>fs.readFileSync(path.join(migrationsDir,f),'utf8')).join('\n');
7
+const must=['create table public.organizations','create table public.organization_units','create table public.organization_members','create table public.member_module_permissions','create table public.organization_audit','add column if not exists organization_id uuid','private.current_organization_ids','private.has_org_capability','private.record_in_member_scope','private.record_confidentiality_allowed',"capabilities <@ array['read','create','edit','delete','approve','register','refer','archive','configure']::text[]","scope_type in ('own','unit','branch','company','organization')",'alter table public.organizations enable row level security','alter table public.organization_members enable row level security','alter table public.member_module_permissions enable row level security','alter table public.organization_audit enable row level security','grant select on public.organizations to authenticated','grant select on public.organization_members to authenticated','grant select on public.member_module_permissions to authenticated','create or replace function public.finora_sync_records','p_organization_id uuid','create or replace function public.office_refer_correspondence','create or replace function public.organization_set_member_permission','create or replace function public.organization_add_member','organization_audit_immutable','correspondence_referrals_immutable','private.can_access_office_storage','private.is_org_owner(org_id)','organization_audit_actor_user_idx','revoke all on function private.',"set search_path='' ".trim()];
8
for(const token of must)if(!sql.includes(token))throw new Error(`missing Slice B invariant: ${token}`);
9
if(/drop\s+table\s+public\.records/i.test(sql))throw new Error('Slice B must not destructively replace records');
10
if(/user_metadata/i.test(sql))throw new Error('authorization must not trust user_metadata');
@@ -12,4 +12,4 @@ const org=fs.readFileSync(path.join(root,'js','organization-rbac.js'),'utf8'),of
12
for(const token of ['organizationId','modulePermissions','commercialModules','hasFinoraCapability','p_organization_id:currentUser.organizationId','organization_set_member_permission','organization_add_member'])if(!org.includes(token))throw new Error(`missing organization client invariant: ${token}`);
13
for(const token of ["cap('configure')","cap('create')","cap('register')","cap('refer')",'office_refer_correspondence',"currentUser.organizationId+'/'+currentUser.id+'/'+correspondenceId"])if(!office.includes(token))throw new Error(`missing office capability invariant: ${token}`);
14
if(!boot.includes('organization-rbac.js')||!boot.includes('office-rbac.js'))throw new Error('Slice B extensions are not loaded by bootstrap');
15
-console.log(`Slice B tenant/RBAC invariants PASS (${files.join(', ')})`);
15
+console.log(`Slice B tenant/RBAC invariants PASS (${requiredFiles.join(', ')})`);