db/schema/0101_acting_usr.sql
Orion Kindel aad2e076fe
All checks were successful
gen-migrations / gen-migrations (push) Successful in 19s
fix: acting_usr fns
2023-07-21 13:20:08 -05:00

43 lines
838 B
PL/PgSQL

create function public.set_acting_usr(uid text)
returns void
language plpgsql
volatile
as $$
begin
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;
$$;
create function public.get_acting_usr()
returns public.usr
language plpgsql
volatile
as $$
declare
acting_usr public.usr;
begin
if nullif(current_setting('dnim.usr_uid', true), '') is null then
acting_usr := public.usr_root();
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 coalesce(acting_usr, public.usr_root());
end;
$$;