This commit is contained in:
parent
d26aa997f3
commit
c7091e9ed4
@ -33,7 +33,6 @@ select immutable( 'public'
|
||||
, 'usr_session'
|
||||
, array[ 'id'
|
||||
, 'key'
|
||||
, 'expires_at'
|
||||
, 'usr'
|
||||
, 'location'
|
||||
, 'device'
|
||||
@ -41,7 +40,7 @@ select immutable( 'public'
|
||||
]
|
||||
);
|
||||
|
||||
create function public.usr_session_touch(session public.usr_session_key)
|
||||
create function public.usr_session_touch(touch_key public.usr_session_key)
|
||||
returns public.usr
|
||||
language plpgsql
|
||||
volatile
|
||||
@ -51,9 +50,9 @@ declare
|
||||
session_usr public.usr;
|
||||
new_exp timestamp;
|
||||
begin
|
||||
select s
|
||||
select s.*
|
||||
from public.usr_session s
|
||||
where s.key = session
|
||||
where s.key = touch_key
|
||||
into session;
|
||||
|
||||
if session is null then
|
||||
@ -70,8 +69,8 @@ begin
|
||||
new_exp := now() + interval '1 hour';
|
||||
end if;
|
||||
|
||||
update public.usr_session s
|
||||
set s.expires_at = new_exp
|
||||
update public.usr_session as s
|
||||
set expires_at = new_exp
|
||||
where s.id = session.id;
|
||||
|
||||
select u.*
|
||||
@ -151,7 +150,7 @@ begin
|
||||
insert into public.usr_session
|
||||
(key, expires_at, usr, remembered, location, device, ip)
|
||||
values
|
||||
(key, expires_at, usr.id, remember, location, device, ip);
|
||||
(key, expires_at, usr.id, coalesce(remember, false), location, device, ip);
|
||||
|
||||
return key;
|
||||
end;
|
||||
|
@ -41,6 +41,20 @@ begin
|
||||
end;
|
||||
$$;
|
||||
|
||||
create function public.usr_groups(of_usr human_uuid.huid)
|
||||
returns setof public.grp
|
||||
stable
|
||||
language plpgsql
|
||||
as $$
|
||||
begin
|
||||
return query select g.*
|
||||
from public.usr u
|
||||
inner join public.grp_usr gu on gu.usr = u.id
|
||||
inner join public.grp g on g.id = gu.grp
|
||||
where u.uid = of_usr;
|
||||
end;
|
||||
$$;
|
||||
|
||||
create function public.grp_members_admins()
|
||||
returns setof public.usr
|
||||
stable
|
||||
|
@ -4,19 +4,23 @@ create function public.do_usr_create_default_grp()
|
||||
language plpgsql
|
||||
as $$
|
||||
declare
|
||||
new_grp int;
|
||||
name public.grp_tag := grp_tag_of_string('usr_' || new.uid);
|
||||
new_grp public.grp;
|
||||
begin
|
||||
insert into public.grp (tag)
|
||||
values (grp_tag_of_string('usr_' || new.uid))
|
||||
returning id into new_grp;
|
||||
insert into public.grp
|
||||
(tag)
|
||||
values
|
||||
(name)
|
||||
returning * into new_grp;
|
||||
|
||||
perform public.grp_add_member(to_grp => new_grp, add_usr => new.id);
|
||||
perform public.grp_add_member(to_grp => new_grp.id, add_usr => new.id);
|
||||
|
||||
update public.perm
|
||||
set owner_user = (public.usr_root()).id
|
||||
set owner_user = NEW.id
|
||||
, owner_group = (public.grp_admins()).id
|
||||
where path = '/groups/' || new_grp || '/members'
|
||||
or path = '/groups/' || new_grp || '/tag';
|
||||
, owner_user_mode = 'r' :: public.perm_mode
|
||||
where path = '/groups/' || (new_grp.uid :: text) || '/members'
|
||||
or path = '/groups/' || (new_grp.uid :: text) || '/name';
|
||||
|
||||
return null;
|
||||
end;
|
||||
|
@ -40,7 +40,7 @@ begin
|
||||
(path, owner_user, owner_group, owner_user_mode, owner_group_mode, everyone_mode)
|
||||
values
|
||||
('/groups/' || human_uuid.huid_to_string(NEW.uid) || '/members', (public.get_acting_usr()).id, NEW.id, 'w', 'w', '-')
|
||||
, ('/groups/' || human_uuid.huid_to_string(NEW.uid) || '/tag', (public.get_acting_usr()).id, NEW.id, 'w', 'w', 'r')
|
||||
, ('/groups/' || human_uuid.huid_to_string(NEW.uid) || '/name', (public.get_acting_usr()).id, NEW.id, 'w', 'w', 'r')
|
||||
;
|
||||
|
||||
return new;
|
||||
|
Loading…
Reference in New Issue
Block a user