2023-07-14 22:13:34 +00:00
|
|
|
create function public.do_usr_create_default_grp()
|
|
|
|
returns trigger
|
|
|
|
volatile
|
|
|
|
language plpgsql
|
|
|
|
as $$
|
|
|
|
declare
|
|
|
|
new_grp int;
|
|
|
|
begin
|
|
|
|
insert into public.grp (tag)
|
|
|
|
values (grp_tag_of_string('usr_' || new.uid))
|
|
|
|
returning id into new_grp;
|
|
|
|
|
|
|
|
perform public.grp_add_member(to_grp => new_grp, add_usr => new.id);
|
|
|
|
|
2023-07-15 22:22:40 +00:00
|
|
|
update public.perm
|
2023-07-16 02:03:16 +00:00
|
|
|
set owner_user = (public.usr_root()).id
|
|
|
|
, owner_group = (public.grp_admins()).id
|
2023-07-15 22:22:40 +00:00
|
|
|
where path = '/groups/' || new_grp || '/members'
|
|
|
|
or path = '/groups/' || new_grp || '/tag';
|
|
|
|
|
2023-07-14 22:13:34 +00:00
|
|
|
return null;
|
|
|
|
end;
|
|
|
|
$$;
|
|
|
|
|
|
|
|
create trigger usr_create_default_grp
|
|
|
|
after insert on public.usr
|
|
|
|
for each row
|
|
|
|
execute function public.do_usr_create_default_grp();
|