misc(all): cleanup comments, update documentation, tidy up code

This commit is contained in:
2026-03-27 21:56:00 +01:00
parent 41747a79a0
commit 145f50749b
26 changed files with 131 additions and 451 deletions
+1 -12
View File
@@ -1,10 +1,5 @@
-- =============================================================================
-- RLS HELPER FUNCTIONS
-- =============================================================================
-- Helper functions for Row-Level Security policies
-- Compatible with PostgREST
-- Row-Level Security helpers, compatible with PostgREST
-- Get current user ID from session variable
CREATE OR REPLACE FUNCTION morbac.current_user_id()
RETURNS UUID
LANGUAGE plpgsql
@@ -13,7 +8,6 @@ AS $$
DECLARE
v_user_id TEXT;
BEGIN
-- Read from morbac.user_id GUC (set via SET morbac.user_id = '...' or PostgREST header mapping)
v_user_id := current_setting('morbac.user_id', TRUE);
IF v_user_id IS NULL OR v_user_id = '' THEN
@@ -30,7 +24,6 @@ $$;
COMMENT ON FUNCTION morbac.current_user_id() IS
'Returns current user ID from morbac.user_id session variable';
-- Get current organization ID from session variable
CREATE OR REPLACE FUNCTION morbac.current_org_id()
RETURNS UUID
LANGUAGE plpgsql
@@ -39,7 +32,6 @@ AS $$
DECLARE
v_org_id TEXT;
BEGIN
-- Read from morbac.org_id GUC (set via SET morbac.org_id = '...' or PostgREST header mapping)
v_org_id := current_setting('morbac.org_id', TRUE);
IF v_org_id IS NULL OR v_org_id = '' THEN
@@ -56,7 +48,6 @@ $$;
COMMENT ON FUNCTION morbac.current_org_id() IS
'Returns current organization ID from morbac.org_id session variable';
-- RLS check function
CREATE OR REPLACE FUNCTION morbac.rls_check(
p_activity TEXT,
p_view TEXT
@@ -72,12 +63,10 @@ BEGIN
v_user_id := morbac.current_user_id();
v_org_id := morbac.current_org_id();
-- If no user or org context, deny
IF v_user_id IS NULL OR v_org_id IS NULL THEN
RETURN FALSE;
END IF;
-- Call cached authorization decision function (default behavior)
RETURN morbac.is_allowed(v_user_id, v_org_id, p_activity, p_view);
END;
$$;