references and on delete cascade

This commit is contained in:
Michael Hoennig 2024-02-12 16:18:20 +01:00
parent db76a57807
commit 607a6c9424
3 changed files with 7 additions and 3 deletions

View File

@ -41,6 +41,8 @@ begin
assumedRoles := coalesce(assumedRoles, ''); assumedRoles := coalesce(assumedRoles, '');
execute format('set local hsadminng.assumedRoles to %L', assumedRoles); execute format('set local hsadminng.assumedRoles to %L', assumedRoles);
SET CONSTRAINTS ALL DEFERRED;
call contextDefined(currentTask, currentRequest, currentUser, assumedRoles); call contextDefined(currentTask, currentRequest, currentUser, assumedRoles);
end; $$; end; $$;
--// --//

View File

@ -172,7 +172,6 @@ create or replace function deleteRelatedRbacObject()
strict as $$ strict as $$
begin begin
if TG_OP = 'DELETE' then if TG_OP = 'DELETE' then
-- TODO: delete related grants? or via cascade?
delete from RbacObject where rbacobject.uuid = old.uuid; delete from RbacObject where rbacobject.uuid = old.uuid;
else else
raise exception 'invalid usage of TRIGGER BEFORE DELETE'; raise exception 'invalid usage of TRIGGER BEFORE DELETE';
@ -453,7 +452,7 @@ $$;
create table RbacGrants create table RbacGrants
( (
uuid uuid primary key default uuid_generate_v4(), uuid uuid primary key default uuid_generate_v4(),
grantedByTriggerOf uuid, -- TODO: references RbacObject (uuid) initially deferred, grantedByTriggerOf uuid references RbacObject (uuid) on delete cascade initially deferred ,
grantedByRoleUuid uuid references RbacRole (uuid), grantedByRoleUuid uuid references RbacRole (uuid),
ascendantUuid uuid references RbacReference (uuid), ascendantUuid uuid references RbacReference (uuid),
descendantUuid uuid references RbacReference (uuid), descendantUuid uuid references RbacReference (uuid),

View File

@ -29,9 +29,12 @@ create or replace function currentTriggerObjectUuid()
returns uuid returns uuid
stable -- leakproof stable -- leakproof
language plpgsql as $$ language plpgsql as $$
declare
currentObjectUuid uuid;
begin begin
begin begin
return current_setting('hsadminng.currentUserUuid')::uuid; currentObjectUuid = current_setting('hsadminng.currentObjectUuid')::uuid;
return currentObjectUuid;
exception exception
when others then when others then
return null::uuid; return null::uuid;