2022-09-06 19:43:15 +02:00
|
|
|
--liquibase formatted sql
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-contact-rbac-OBJECT:1 endDelimiter:--//
|
2022-09-06 19:43:15 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-13 13:27:52 +02:00
|
|
|
call generateRelatedRbacObject('hs_office_contact');
|
2022-09-06 19:43:15 +02:00
|
|
|
--//
|
|
|
|
|
2022-09-13 10:58:54 +02:00
|
|
|
|
2022-09-06 19:43:15 +02:00
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-contact-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--//
|
2022-09-06 19:43:15 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-16 15:25:58 +02:00
|
|
|
call generateRbacRoleDescriptors('hsOfficeContact', 'hs_office_contact');
|
2022-09-06 19:43:15 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-contact-rbac-ROLES-CREATION:1 endDelimiter:--//
|
2022-09-06 19:43:15 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
Creates the roles and their assignments for a new contact for the AFTER INSERT TRIGGER.
|
|
|
|
*/
|
|
|
|
|
2022-09-14 09:24:19 +02:00
|
|
|
create or replace function createRbacRolesForHsOfficeContact()
|
2022-09-06 19:43:15 +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(
|
|
|
|
hsOfficeContactOwner(NEW),
|
2024-03-11 12:30:43 +01:00
|
|
|
permissions => array['DELETE'],
|
2022-10-12 15:48:56 +02:00
|
|
|
incomingSuperRoles => array[globalAdmin()],
|
|
|
|
userUuids => array[currentUserUuid()],
|
|
|
|
grantedByRole => globalAdmin()
|
2022-09-06 19:43:15 +02:00
|
|
|
);
|
|
|
|
|
2022-10-12 15:48:56 +02:00
|
|
|
perform createRoleWithGrants(
|
2022-09-13 13:27:52 +02:00
|
|
|
hsOfficeContactAdmin(NEW),
|
2024-03-11 12:30:43 +01:00
|
|
|
permissions => array['UPDATE'],
|
2022-10-12 15:48:56 +02:00
|
|
|
incomingSuperRoles => array[hsOfficeContactOwner(NEW)]
|
2022-09-09 17:43:43 +02:00
|
|
|
);
|
|
|
|
|
2022-10-12 15:48:56 +02:00
|
|
|
perform createRoleWithGrants(
|
2024-02-08 17:36:49 +01:00
|
|
|
hsOfficeContactReferrer(NEW),
|
2024-03-11 12:30:43 +01:00
|
|
|
permissions => array['SELECT'],
|
2024-02-08 17:36:49 +01:00
|
|
|
incomingSuperRoles => array[hsOfficeContactAdmin(NEW)]
|
2022-09-06 19:43:15 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
return NEW;
|
|
|
|
end; $$;
|
|
|
|
|
|
|
|
/*
|
|
|
|
An AFTER INSERT TRIGGER which creates the role structure for a new customer.
|
|
|
|
*/
|
|
|
|
|
2022-09-14 09:24:19 +02:00
|
|
|
create trigger createRbacRolesForHsOfficeContact_Trigger
|
2022-09-06 19:43:15 +02:00
|
|
|
after insert
|
2022-09-13 13:27:52 +02:00
|
|
|
on hs_office_contact
|
2022-09-06 19:43:15 +02:00
|
|
|
for each row
|
2022-09-14 09:24:19 +02:00
|
|
|
execute procedure createRbacRolesForHsOfficeContact();
|
2022-09-06 19:43:15 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-contact-rbac-IDENTITY-VIEW:1 endDelimiter:--//
|
2022-09-06 19:43:15 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
2024-03-11 12:30:43 +01:00
|
|
|
call generateRbacIdentityViewFromProjection('hs_office_contact', $idName$
|
2022-09-16 16:14:39 +02:00
|
|
|
target.label
|
|
|
|
$idName$);
|
2022-09-06 19:43:15 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-contact-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
|
2022-09-06 19:43:15 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-09-19 20:43:14 +02:00
|
|
|
call generateRbacRestrictedView('hs_office_contact', 'target.label',
|
|
|
|
$updates$
|
|
|
|
label = new.label,
|
|
|
|
postalAddress = new.postalAddress,
|
|
|
|
emailAddresses = new.emailAddresses,
|
|
|
|
phoneNumbers = new.phoneNumbers
|
|
|
|
$updates$);
|
2022-09-06 19:43:15 +02:00
|
|
|
--/
|
|
|
|
|
2022-09-19 20:43:14 +02:00
|
|
|
|
2022-09-06 19:43:15 +02:00
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
--changeset hs-office-contact-rbac-NEW-CONTACT:1 endDelimiter:--//
|
2022-09-06 19:43:15 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
/*
|
2022-09-07 14:04:45 +02:00
|
|
|
Creates a global permission for new-contact and assigns it to the hostsharing admins role.
|
2022-09-06 19:43:15 +02:00
|
|
|
*/
|
|
|
|
do language plpgsql $$
|
|
|
|
declare
|
|
|
|
addCustomerPermissions uuid[];
|
|
|
|
globalObjectUuid uuid;
|
2024-01-23 15:11:23 +01:00
|
|
|
globalAdminRoleUuid uuid;
|
2022-09-06 19:43:15 +02:00
|
|
|
begin
|
2022-09-07 14:04:45 +02:00
|
|
|
call defineContext('granting global new-contact permission to global admin role', null, null, null);
|
2022-09-06 19:43:15 +02:00
|
|
|
|
|
|
|
globalAdminRoleUuid := findRoleId(globalAdmin());
|
|
|
|
globalObjectUuid := (select uuid from global);
|
2022-09-07 14:04:45 +02:00
|
|
|
addCustomerPermissions := createPermissions(globalObjectUuid, array ['new-contact']);
|
2022-09-06 19:43:15 +02:00
|
|
|
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 addHsOfficeContactNotAllowedForCurrentSubjects()
|
2022-09-06 19:43:15 +02:00
|
|
|
returns trigger
|
|
|
|
language PLPGSQL
|
|
|
|
as $$
|
|
|
|
begin
|
2022-09-07 14:04:45 +02:00
|
|
|
raise exception '[403] new-contact not permitted for %',
|
2022-09-06 19:43:15 +02:00
|
|
|
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_contact_insert_trigger
|
2022-09-06 19:43:15 +02:00
|
|
|
before insert
|
2022-09-13 13:27:52 +02:00
|
|
|
on hs_office_contact
|
2022-09-06 19:43:15 +02:00
|
|
|
for each row
|
|
|
|
-- TODO.spec: who is allowed to create new contacts
|
|
|
|
when ( not hasAssumedRole() )
|
2022-09-13 13:27:52 +02:00
|
|
|
execute procedure addHsOfficeContactNotAllowedForCurrentSubjects();
|
2022-09-06 19:43:15 +02:00
|
|
|
--//
|
|
|
|
|