This commit is contained in:
2026-08-07 20:48:32 +00:00
parent 9442d03f63
commit 6c63218a6b
@@ -19,6 +19,21 @@
-- disciplinary_history, custody_agreement and primary_physician, which they -- disciplinary_history, custody_agreement and primary_physician, which they
-- have no business reading. So the name is resolved on its own instead, and -- have no business reading. So the name is resolved on its own instead, and
-- student row access is left exactly as it was. -- student row access is left exactly as it was.
-- True for callers that bypass RLS outright: the service role used by
-- server-side code, and a direct superuser psql session (role unset).
--
-- This MUST read the `role` GUC rather than current_user. Inside a
-- SECURITY DEFINER function current_user is the function's owner, so
-- pg_has_role(current_user, 'service_role', ...) is true for every caller and
-- silently turns an entitlement check into a no-op.
CREATE OR REPLACE FUNCTION public.is_service_context()
RETURNS BOOLEAN
LANGUAGE sql STABLE AS $$
SELECT COALESCE(current_setting('role', true), 'none') IN ('service_role', 'none');
$$;
GRANT EXECUTE ON FUNCTION public.is_service_context() TO authenticated;
CREATE OR REPLACE FUNCTION public.student_display_name(_student UUID) CREATE OR REPLACE FUNCTION public.student_display_name(_student UUID)
RETURNS TEXT RETURNS TEXT
LANGUAGE sql STABLE SECURITY DEFINER SET search_path = public AS $$ LANGUAGE sql STABLE SECURITY DEFINER SET search_path = public AS $$