espace-paie-odentas/scripts/verify-rls-virements-cotisations.sql

86 lines
3.1 KiB
SQL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Vérification RLS pour VIREMENTS-SALAIRES et COTISATIONS
-- Tables critiques: salary_transfers, monthly_contributions, contribution_notifications
-- 1⃣ VÉRIFICATION RLS ACTIVÉE
SELECT
schemaname,
tablename,
rowsecurity AS rls_enabled
FROM pg_tables
WHERE tablename IN ('salary_transfers', 'monthly_contributions', 'contribution_notifications')
ORDER BY tablename;
-- 2⃣ POLITIQUES RLS EXISTANTES
SELECT
schemaname,
tablename,
policyname,
permissive,
roles,
cmd,
qual,
with_check
FROM pg_policies
WHERE tablename IN ('salary_transfers', 'monthly_contributions', 'contribution_notifications')
ORDER BY tablename, cmd, policyname;
-- 3⃣ INDEX SUR org_id
SELECT
schemaname,
tablename,
indexname,
indexdef
FROM pg_indexes
WHERE tablename IN ('salary_transfers', 'monthly_contributions', 'contribution_notifications')
AND indexdef ILIKE '%org_id%'
ORDER BY tablename, indexname;
-- ================================================================================
-- RÉSULTATS DE VÉRIFICATION (16 octobre 2025)
-- ================================================================================
-- 1⃣ RLS ACTIVÉ
-- contribution_notifications : ❌ false → CORRECTION REQUISE
-- monthly_contributions : ✅ true
-- salary_transfers : ✅ true
-- 2⃣ POLITIQUES RLS
-- monthly_contributions (4 politiques) :
-- - SELECT : is_member_of_org(org_id) ✅ CONFORME
-- - INSERT : is_member_of_org(org_id) ✅ CONFORME
-- - UPDATE : is_member_of_org(org_id) ✅ CONFORME
-- - DELETE : is_member_of_org(org_id) ✅ CONFORME
--
-- salary_transfers (4 politiques) :
-- - SELECT : is_staff() OR is_member_of_org() ✅ CONFORME
-- - INSERT : is_staff() ✅ CONFORME (staff only)
-- - UPDATE : is_staff() ✅ CONFORME (staff only)
-- - DELETE : is_staff() ✅ CONFORME (staff only)
--
-- contribution_notifications :
-- - Aucune politique (RLS désactivé) ❌ À CRÉER
-- 3⃣ INDEX org_id
-- contribution_notifications : ✅ 1 index unique (org_id, period_label)
-- monthly_contributions : ✅ 3 index (dont 2 sur org_id simple)
-- salary_transfers : ✅ 1 index unique composite (org_id, period_month, mode, callsheet_url)
-- ================================================================================
-- CONCLUSION
-- ================================================================================
-- 🟢 EXCELLENT : salary_transfers et monthly_contributions
-- - RLS activé avec politiques robustes
-- - Index performants en place
-- - Isolation par organisation garantie
--
-- ✅ CORRIGÉ (16 octobre 2025) : contribution_notifications
-- - RLS activé ✅
-- - 4 politiques staff-only créées ✅
-- * select_staff_only (SELECT)
-- * insert_staff_only (INSERT)
-- * update_staff_only (UPDATE)
-- * delete_staff_only (DELETE)
-- - Index unique (org_id, period_label) présent ✅
--
-- 🟢 STATUT FINAL : EXCELLENT
-- Toutes les tables critiques sont maintenant protégées par RLS avec politiques appropriées.