35 lines
649 B
MySQL
35 lines
649 B
MySQL
|
create function public.set_acting_usr(uid text)
|
||
|
returns void
|
||
|
language plpgsql
|
||
|
volatile
|
||
|
as $$
|
||
|
begin
|
||
|
set session "dnim.usr_uid" = uid;
|
||
|
end;
|
||
|
$$;
|
||
|
|
||
|
create function public.get_acting_usr()
|
||
|
returns public.usr
|
||
|
language plpgsql
|
||
|
volatile
|
||
|
as $$
|
||
|
declare
|
||
|
uid text;
|
||
|
acting_usr public.usr;
|
||
|
begin
|
||
|
if nullif(current_setting('dnim.usr_uid', true), '') is null then
|
||
|
select u.*
|
||
|
from public.usr u
|
||
|
where u.tag = public.usr_tag_of_string('root')
|
||
|
into acting_usr;
|
||
|
else
|
||
|
select u.*
|
||
|
from public.usr u
|
||
|
where u.uid = current_setting('dnim.usr_uid', true) :: uuid
|
||
|
into acting_usr;
|
||
|
end if;
|
||
|
|
||
|
return acting_usr;
|
||
|
end;
|
||
|
$$;
|