@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / c711f37
Fork 0

سامانه صدور فاکتور و حسابداری

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 18:15 UTC

test: extend disposable C8 runtime harness

davoodmehraban89 committed Oct 1, 2026 at 21:22 UTC c711f37851e582ddfa7cbd51d852c6b79cb624f4
1 file changed +27 -1
supabase/tests/office_c8_bootstrap.sql renamed
+27 -1
@@ -1,5 +1,5 @@
1 +-- Minimal zero-cost PostgreSQL harness for C8 migration tests.
2 +-- Test-only scaffolding: production authorization helpers are not replaced.
3 create extension if not exists pgcrypto;
4 create schema if not exists auth;
5 create schema if not exists private;
@@ -8,6 +8,15 @@ do $$ begin create role authenticated nologin; exception when duplicate_object t
8
9 create table if not exists public.profiles(id uuid primary key);
10 create table if not exists public.organizations(id uuid primary key, owner_user_id uuid references public.profiles(id));
11 +create table if not exists public.records(
12 + organization_id uuid not null references public.organizations(id) on delete restrict,
13 + owner_id uuid not null references public.profiles(id) on delete restrict,
14 + collection text not null,
15 + id text not null,
16 + data jsonb not null,
17 + updated_at timestamptz not null default now(),
18 + primary key(organization_id,collection,id)
19 +);
20
21 create or replace function auth.uid() returns uuid
22 language sql stable set search_path=''
@@ -15,13 +24,18 @@ as $$ select nullif(current_setting('request.jwt.claim.sub',true),'')::uuid $$;
24
25 create or replace function private.current_organization_ids() returns setof uuid
26 language sql stable security definer set search_path=''
18 -as $$ select nullif(current_setting('request.jwt.claim.org',true),'')::uuid where (select auth.uid()) is not null $$;
27 +as $$
28 + select nullif(current_setting('request.jwt.claim.org',true),'')::uuid
29 + where (select auth.uid()) is not null
30 + and coalesce(nullif(current_setting('request.jwt.claim.member_active',true),''),'true')='true'
31 +$$;
32
33 create or replace function private.organization_has_module_entitlement(p_organization_id uuid,p_module_key text,p_require_active boolean default false)
34 returns boolean language sql stable security definer set search_path=''
35 as $$
36 select p_module_key='office_automation'
37 and p_organization_id=nullif(current_setting('request.jwt.claim.org',true),'')::uuid
38 + and coalesce(nullif(current_setting('request.jwt.claim.entitled',true),''),'true')='true'
39 and (not p_require_active or coalesce(nullif(current_setting('request.jwt.claim.write',true),''),'true')='true')
40 $$;
41
@@ -32,3 +46,13 @@ as $$
46 and p_organization_id=nullif(current_setting('request.jwt.claim.org',true),'')::uuid
47 and p_capability=any(string_to_array(coalesce(current_setting('request.jwt.claim.capabilities',true),''),','))
48 $$;
49 +
50 +create or replace function private.can_access_record(p_organization_id uuid,p_collection text,p_owner_id uuid,p_data jsonb,p_capability text)
51 +returns boolean language sql stable security definer set search_path=''
52 +as $$
53 + select p_collection='correspondence'
54 + and p_organization_id in (select private.current_organization_ids())
55 + and private.organization_has_module_entitlement(p_organization_id,'office_automation',false)
56 + and private.has_org_capability(p_organization_id,'office_automation',p_capability)
57 + and coalesce(nullif(current_setting('request.jwt.claim.readable',true),''),'true')='true'
58 +$$;