feat(orders): support active status and update RLS
Some checks failed
Staging Build / build (push) Has been cancelled
Some checks failed
Staging Build / build (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
-- 1. Order Status Constraint anpassen
|
||||
ALTER TABLE public.orders DROP CONSTRAINT IF EXISTS orders_status_check;
|
||||
ALTER TABLE public.orders ADD CONSTRAINT orders_status_check
|
||||
CHECK (status IN ('pending', 'pending_approval', 'in_review', 'approved', 'active', 'completed', 'cancelled', 'rejected'));
|
||||
|
||||
-- 2. Helper-Funktion für RLS anlegen
|
||||
CREATE OR REPLACE FUNCTION public.get_auth_company_id()
|
||||
RETURNS UUID AS $$
|
||||
SELECT company_id FROM public.users WHERE id = auth.uid() LIMIT 1;
|
||||
$$ LANGUAGE sql STABLE SECURITY DEFINER;
|
||||
|
||||
-- 3. RLS-Policies aktualisieren
|
||||
DROP POLICY IF EXISTS "Partner sehen nur eigene Firmenbestellungen" ON public.orders;
|
||||
CREATE POLICY "Partner sehen nur eigene Firmenbestellungen" ON public.orders
|
||||
FOR SELECT USING (company_id = public.get_auth_company_id() OR public.is_admin(auth.uid()));
|
||||
|
||||
DROP POLICY IF EXISTS "Partner sehen nur eigene Endkunden" ON public.end_customers;
|
||||
CREATE POLICY "Partner sehen nur eigene Endkunden" ON public.end_customers
|
||||
FOR SELECT USING (partner_id = public.get_auth_company_id() OR public.is_admin(auth.uid()));
|
||||
Reference in New Issue
Block a user