Skip to content

Commit df3a37c

Browse files
Add billing record policies
1 parent 6f873ab commit df3a37c

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/integrations/supabase/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ export type Database = {
598598
Args: { activity_type?: string; user_id?: string }
599599
Returns: boolean
600600
}
601+
log_billing_access: {
602+
Args: { access_type: string; record_id: string }
603+
Returns: undefined
604+
}
601605
log_security_event: {
602606
Args: { details?: Json; event_type: string; user_id?: string }
603607
Returns: undefined
@@ -606,6 +610,10 @@ export type Database = {
606610
Args: { campaign_id: string; requesting_user_id?: string }
607611
Returns: boolean
608612
}
613+
validate_billing_record_ownership: {
614+
Args: { record_id: string }
615+
Returns: boolean
616+
}
609617
validate_campaign_ownership: {
610618
Args: { campaign_id: string; user_id?: string }
611619
Returns: boolean
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-- Add security monitoring functions for billing records
2+
3+
-- Create security audit function for billing record access
4+
CREATE OR REPLACE FUNCTION public.log_billing_access(record_id uuid, access_type text)
5+
RETURNS void
6+
LANGUAGE plpgsql
7+
SECURITY DEFINER
8+
SET search_path = public
9+
AS $$
10+
BEGIN
11+
-- Log financial data access for security monitoring
12+
PERFORM public.log_security_event(
13+
'billing_record_access',
14+
auth.uid(),
15+
jsonb_build_object(
16+
'record_id', record_id,
17+
'access_type', access_type,
18+
'timestamp', now()
19+
)
20+
);
21+
END;
22+
$$;
23+
24+
-- Create function to validate billing record ownership before sensitive operations
25+
CREATE OR REPLACE FUNCTION public.validate_billing_record_ownership(record_id uuid)
26+
RETURNS boolean
27+
LANGUAGE plpgsql
28+
SECURITY DEFINER
29+
SET search_path = public
30+
AS $$
31+
DECLARE
32+
record_owner uuid;
33+
BEGIN
34+
SELECT user_id INTO record_owner
35+
FROM billing_records
36+
WHERE id = record_id;
37+
38+
RETURN (record_owner = auth.uid());
39+
END;
40+
$$;

0 commit comments

Comments
 (0)