سامانه صدور فاکتور و حسابداری
security(phase1a): deny unauthorized organization reversals before reading original voucher
davoodmehraban89 committed
Oct 16, 2026 at 17:05 UTC
13bae899e2a206b4e28f641eaa090831d795ac37
1 file changed
+4
supabase/migrations/20261016102000_phase1a_journal_rpc_surface.sql
+4
@@ -133,6 +133,10 @@ DECLARE original public.records%rowtype; v_actor uuid:=auth.uid();l record;
133
v_src text;v_lines jsonb;v_result jsonb;v_sum_d numeric:=0;v_sum_c numeric:=0;
134
v_alloc jsonb;v_seen integer;v_used integer:=0;
135
BEGIN
136
+ IF v_actor IS NULL OR NOT EXISTS(SELECT 1 FROM public.organization_members
137
+ WHERE organization_id=p_organization_id AND user_id=v_actor AND status='active') THEN
138
+ RAISE EXCEPTION 'FINORA_ORG_FORBIDDEN' USING ERRCODE='42501';
139
+ END IF;
140
IF coalesce(length(trim(p_reason)),0)<4 OR p_original_id=p_reversal_id THEN
141
RAISE EXCEPTION 'FINORA_REVERSAL_REASON_REQUIRED' USING ERRCODE='23514';END IF;
142
SELECT * INTO original FROM public.records