2022-09-07 20:24:35 +02:00
|
|
|
--liquibase formatted sql
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-person-rbac-OBJECT:1 endDelimiter:--//
|
2022-09-07 20:24:35 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-13 13:27:52 +02:00
|
|
|
call generateRelatedRbacObject('hs_office_person');
|
2022-09-07 20:24:35 +02:00
|
|
|
--//
|
|
|
|
|
2022-09-13 10:58:54 +02:00
|
|
|
|
2022-09-07 20:24:35 +02:00
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-person-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--//
|
2022-09-07 20:24:35 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-16 15:25:58 +02:00
|
|
|
call generateRbacRoleDescriptors('hsOfficePerson', 'hs_office_person');
|
2022-09-07 20:24:35 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-person-rbac-ROLES-CREATION:1 endDelimiter:--//
|
2022-09-07 20:24:35 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Creates the roles and their assignments for a new person for the AFTER INSERT TRIGGER.
|
|
|
|
*/
|
2022-09-13 13:27:52 +02:00
|
|
|
create or replace function createRbacRolesForHsOfficePerson()
|
2022-09-07 20:24:35 +02:00
|
|
|
returns trigger
|
|
|
|
language plpgsql
|
|
|
|
strict as $$
|
|
|
|
begin
|
|
|
|
if TG_OP <> 'INSERT' then
|
|
|
|
raise exception 'invalid usage of TRIGGER AFTER INSERT';
|
|
|
|
end if;
|
|
|
|
|
2022-10-12 15:48:56 +02:00
|
|
|
perform createRoleWithGrants(
|
2022-09-13 13:27:52 +02:00
|
|
|
hsOfficePersonOwner(NEW),
|
2022-10-12 15:48:56 +02:00
|
|
|
permissions => array['*'],
|
|
|
|
incomingSuperRoles => array[globalAdmin()],
|
|
|
|
userUuids => array[currentUserUuid()],
|
|
|
|
grantedByRole => globalAdmin()
|
2022-09-07 20:24:35 +02:00
|
|
|
);
|
|
|
|
|
2022-10-12 15:48:56 +02:00
|
|
|
perform createRoleWithGrants(
|
2022-09-13 13:27:52 +02:00
|
|
|
hsOfficePersonAdmin(NEW),
|
2022-10-12 15:48:56 +02:00
|
|
|
permissions => array['edit'],
|
|
|
|
incomingSuperRoles => array[hsOfficePersonOwner(NEW)]
|
2022-09-09 17:43:43 +02:00
|
|
|
);
|
|
|
|
|
2022-10-12 15:48:56 +02:00
|
|
|
perform createRoleWithGrants(
|
2022-09-13 13:27:52 +02:00
|
|
|
hsOfficePersonTenant(NEW),
|
2022-10-12 15:48:56 +02:00
|
|
|
incomingSuperRoles => array[hsOfficePersonAdmin(NEW)]
|
|
|
|
);
|
|
|
|
|
|
|
|
perform createRoleWithGrants(
|
|
|
|
hsOfficePersonGuest(NEW),
|
|
|
|
permissions => array['view'],
|
|
|
|
incomingSuperRoles => array[hsOfficePersonTenant(NEW)]
|
2022-09-07 20:24:35 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
return NEW;
|
|
|
|
end; $$;
|
|
|
|
|
|
|
|
/*
|
|
|
|
An AFTER INSERT TRIGGER which creates the role structure for a new customer.
|
|
|
|
*/
|
|
|
|
|
2022-09-13 13:27:52 +02:00
|
|
|
create trigger createRbacRolesForHsOfficePerson_Trigger
|
2022-09-07 20:24:35 +02:00
|
|
|
after insert
|
2022-09-13 13:27:52 +02:00
|
|
|
on hs_office_person
|
2022-09-07 20:24:35 +02:00
|
|
|
for each row
|
2022-09-13 13:27:52 +02:00
|
|
|
execute procedure createRbacRolesForHsOfficePerson();
|
2022-09-07 20:24:35 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-person-rbac-IDENTITY-VIEW:1 endDelimiter:--//
|
2022-09-07 20:24:35 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-16 16:14:39 +02:00
|
|
|
call generateRbacIdentityView('hs_office_person', $idName$
|
|
|
|
concat(target.tradeName, target.familyName, target.givenName)
|
|
|
|
$idName$);
|
2022-09-07 20:24:35 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-person-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
|
2022-09-07 20:24:35 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-19 20:43:14 +02:00
|
|
|
call generateRbacRestrictedView('hs_office_person', 'concat(target.tradeName, target.familyName, target.givenName)',
|
|
|
|
$updates$
|
|
|
|
personType = new.personType,
|
|
|
|
tradeName = new.tradeName,
|
|
|
|
givenName = new.givenName,
|
|
|
|
familyName = new.familyName
|
|
|
|
$updates$);
|
2022-09-07 20:24:35 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-person-rbac-NEW-PERSON:1 endDelimiter:--//
|
2022-09-07 20:24:35 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Creates a global permission for new-person and assigns it to the hostsharing admins role.
|
|
|
|
*/
|
|
|
|
do language plpgsql $$
|
|
|
|
declare
|
2022-09-12 16:27:17 +02:00
|
|
|
addCustomerPermissions uuid[];
|
|
|
|
globalObjectUuid uuid;
|
|
|
|
globalAdminRoleUuid uuid ;
|
2022-09-07 20:24:35 +02:00
|
|
|
begin
|
|
|
|
call defineContext('granting global new-person permission to global admin role', null, null, null);
|
|
|
|
|
|
|
|
globalAdminRoleUuid := findRoleId(globalAdmin());
|
|
|
|
globalObjectUuid := (select uuid from global);
|
|
|
|
addCustomerPermissions := createPermissions(globalObjectUuid, array ['new-person']);
|
|
|
|
call grantPermissionsToRole(globalAdminRoleUuid, addCustomerPermissions);
|
|
|
|
end;
|
|
|
|
$$;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Used by the trigger to prevent the add-customer to current user respectively assumed roles.
|
|
|
|
*/
|
2022-09-13 13:27:52 +02:00
|
|
|
create or replace function addHsOfficePersonNotAllowedForCurrentSubjects()
|
2022-09-07 20:24:35 +02:00
|
|
|
returns trigger
|
|
|
|
language PLPGSQL
|
|
|
|
as $$
|
|
|
|
begin
|
|
|
|
raise exception '[403] new-person not permitted for %',
|
|
|
|
array_to_string(currentSubjects(), ';', 'null');
|
|
|
|
end; $$;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Checks if the user or assumed roles are allowed to create a new customer.
|
|
|
|
*/
|
2022-09-13 13:27:52 +02:00
|
|
|
create trigger hs_office_person_insert_trigger
|
2022-09-07 20:24:35 +02:00
|
|
|
before insert
|
2022-09-13 13:27:52 +02:00
|
|
|
on hs_office_person
|
2022-09-07 20:24:35 +02:00
|
|
|
for each row
|
|
|
|
-- TODO.spec: who is allowed to create new persons
|
|
|
|
when ( not hasAssumedRole() )
|
2022-09-13 13:27:52 +02:00
|
|
|
execute procedure addHsOfficePersonNotAllowedForCurrentSubjects();
|
2022-09-07 20:24:35 +02:00
|
|
|
--//
|
|
|
|
|