db/schema/0302_default_grps.sql

29 lines
681 B
MySQL
Raw Normal View History

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);
update public.perm
2023-07-16 02:03:16 +00:00
set owner_user = (public.usr_root()).id
, owner_group = (public.grp_admins()).id
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();