db/schema/0302_default_grps.sql

33 lines
793 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
2023-07-21 05:10:02 +00:00
name public.grp_tag := grp_tag_of_string('usr_' || new.uid);
new_grp public.grp;
2023-07-14 22:13:34 +00:00
begin
2023-07-21 05:10:02 +00:00
insert into public.grp
(tag)
values
(name)
returning * into new_grp;
2023-07-14 22:13:34 +00:00
2023-07-21 05:10:02 +00:00
perform public.grp_add_member(to_grp => new_grp.id, add_usr => new.id);
2023-07-14 22:13:34 +00:00
update public.perm
2023-07-21 05:10:02 +00:00
set owner_user = NEW.id
2023-07-16 02:03:16 +00:00
, owner_group = (public.grp_admins()).id
2023-07-21 05:10:02 +00:00
, owner_user_mode = 'r' :: public.perm_mode
where path = '/groups/' || (new_grp.uid :: text) || '/members'
or path = '/groups/' || (new_grp.uid :: text) || '/name';
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();