From aad2e076fea8b2096831b3b242869f23f106c86f Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Fri, 21 Jul 2023 13:19:59 -0500 Subject: [PATCH] fix: acting_usr fns --- schema/0101_acting_usr.sql | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/schema/0101_acting_usr.sql b/schema/0101_acting_usr.sql index a448105..bdb9f9e 100644 --- a/schema/0101_acting_usr.sql +++ b/schema/0101_acting_usr.sql @@ -4,7 +4,19 @@ create function public.set_acting_usr(uid text) volatile as $$ begin - set session "dnim.usr_uid" = uid; + if uid is not null and uid != '' then + perform set_config('dnim.usr_uid', uid, false); + end if; +end; +$$; + +create function public.unset_acting_usr() + returns void + language plpgsql + volatile + as $$ +begin + perform set_config('dnim.usr_uid', '', false); end; $$; @@ -14,18 +26,17 @@ create function public.get_acting_usr() volatile as $$ declare - uid text; acting_usr public.usr; begin if nullif(current_setting('dnim.usr_uid', true), '') is null then acting_usr := public.usr_root(); - else + else select u.* from public.usr u where u.uid = human_uuid.huid_of_string(current_setting('dnim.usr_uid', true)) into acting_usr; end if; - return acting_usr; + return coalesce(acting_usr, public.usr_root()); end; $$;