mirror of
https://github.com/marcogll/AnchorOS.git
synced 2026-03-15 10:24:26 +00:00
✅ COMENTARIOS AUDITABLES IMPLEMENTADOS: - 80+ archivos con JSDoc completo para auditoría manual - APIs críticas con validaciones business/security/performance - Componentes con reglas de negocio documentadas - Funciones core con edge cases y validaciones ✅ CALENDARIO MULTI-COLUMNA FUNCIONAL (95%): - Drag & drop con reprogramación automática - Filtros por sucursal/staff, tiempo real - Indicadores de conflictos y disponibilidad - APIs completas con validaciones de colisión ✅ GESTIÓN OPERATIVA COMPLETA: - CRUD staff: APIs + componente con validaciones - CRUD recursos: APIs + componente con disponibilidad - Autenticación completa con middleware seguro - Auditoría completa en todas las operaciones ✅ DOCUMENTACIÓN ACTUALIZADA: - TASKS.md: FASE 4 95% completado - README.md: Estado actual y funcionalidades - API.md: 40+ endpoints documentados ✅ SEGURIDAD Y VALIDACIONES: - RLS policies documentadas en comentarios - Business rules validadas manualmente - Performance optimizations anotadas - Error handling completo Próximos: Nómina/POS/CRM avanzado (FASE 4 final)
42 lines
1.3 KiB
PL/PgSQL
42 lines
1.3 KiB
PL/PgSQL
-- Fix RLS policy recursion issue
|
|
--
|
|
-- Solution: Create SECURITY DEFINER function to get user's location
|
|
-- This bypasses RLS when checking user's own data
|
|
|
|
-- Create a function that returns the current user's staff location
|
|
CREATE OR REPLACE FUNCTION get_current_user_location_id()
|
|
RETURNS uuid
|
|
LANGUAGE sql
|
|
SECURITY DEFINER
|
|
SET search_path = public
|
|
AS $$
|
|
SELECT location_id FROM staff WHERE user_id = auth.uid() LIMIT 1;
|
|
$$;
|
|
|
|
-- Drop problematic policies
|
|
DROP POLICY IF EXISTS "staff_select_own" ON staff;
|
|
DROP POLICY IF EXISTS "staff_select_same_location" ON staff;
|
|
DROP POLICY IF EXISTS "staff_select_artist_view_artists" ON staff;
|
|
|
|
-- Create self-query policy - simplest approach without functions
|
|
CREATE POLICY "staff_select_self" ON staff
|
|
FOR SELECT
|
|
USING (user_id = auth.uid());
|
|
|
|
-- Recreate the same_location policy using the function
|
|
CREATE POLICY "staff_select_same_location" ON staff
|
|
FOR SELECT
|
|
USING (
|
|
is_staff_or_higher() AND
|
|
location_id = get_current_user_location_id()
|
|
);
|
|
|
|
-- Recreate the artist_view_artists policy using the function
|
|
CREATE POLICY "staff_select_artist_view_artists" ON staff
|
|
FOR SELECT
|
|
USING (
|
|
is_artist() AND
|
|
location_id = get_current_user_location_id() AND
|
|
staff.role = 'artist'
|
|
);
|