43 lines
838 B
PL/PgSQL
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;
|
|
$$;
|