2022-10-13 13:35:50 +02:00
|
|
|
--liquibase formatted sql
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-10-13 18:53:38 +02:00
|
|
|
--changeset hs-office-sepamandate-rbac-OBJECT:1 endDelimiter:--//
|
2022-10-13 13:35:50 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-10-13 18:53:38 +02:00
|
|
|
call generateRelatedRbacObject('hs_office_sepamandate');
|
2022-10-13 13:35:50 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-10-13 18:53:38 +02:00
|
|
|
--changeset hs-office-sepamandate-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--//
|
2022-10-13 13:35:50 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-10-13 18:53:38 +02:00
|
|
|
call generateRbacRoleDescriptors('hsOfficeSepaMandate', 'hs_office_sepamandate');
|
2022-10-13 13:35:50 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-10-13 18:53:38 +02:00
|
|
|
--changeset hs-office-sepamandate-rbac-ROLES-CREATION:1 endDelimiter:--//
|
2022-10-13 13:35:50 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
Creates and updates the roles and their assignments for sepaMandate entities.
|
|
|
|
*/
|
|
|
|
|
|
|
|
create or replace function hsOfficeSepaMandateRbacRolesTrigger()
|
|
|
|
returns trigger
|
|
|
|
language plpgsql
|
|
|
|
strict as $$
|
|
|
|
declare
|
|
|
|
newHsOfficeDebitor hs_office_debitor;
|
|
|
|
newHsOfficeBankAccount hs_office_bankAccount;
|
|
|
|
begin
|
|
|
|
|
|
|
|
select * from hs_office_debitor as p where p.uuid = NEW.debitorUuid into newHsOfficeDebitor;
|
|
|
|
select * from hs_office_bankAccount as c where c.uuid = NEW.bankAccountUuid into newHsOfficeBankAccount;
|
|
|
|
|
|
|
|
if TG_OP = 'INSERT' then
|
|
|
|
|
|
|
|
-- === ATTENTION: code generated from related Mermaid flowchart: ===
|
|
|
|
|
|
|
|
perform createRoleWithGrants(
|
|
|
|
hsOfficeSepaMandateOwner(NEW),
|
|
|
|
permissions => array['*'],
|
|
|
|
incomingSuperRoles => array[globalAdmin()]
|
|
|
|
);
|
|
|
|
|
|
|
|
perform createRoleWithGrants(
|
|
|
|
hsOfficeSepaMandateAdmin(NEW),
|
|
|
|
permissions => array['edit'],
|
|
|
|
incomingSuperRoles => array[hsOfficeSepaMandateOwner(NEW)],
|
|
|
|
outgoingSubRoles => array[hsOfficeBankAccountTenant(newHsOfficeBankAccount)]
|
|
|
|
);
|
|
|
|
|
|
|
|
perform createRoleWithGrants(
|
|
|
|
hsOfficeSepaMandateAgent(NEW),
|
|
|
|
incomingSuperRoles => array[hsOfficeSepaMandateAdmin(NEW), hsOfficeDebitorAdmin(newHsOfficeDebitor), hsOfficeBankAccountAdmin(newHsOfficeBankAccount)],
|
|
|
|
outgoingSubRoles => array[hsOfficeDebitorTenant(newHsOfficeDebitor)]
|
|
|
|
);
|
|
|
|
|
|
|
|
perform createRoleWithGrants(
|
|
|
|
hsOfficeSepaMandateTenant(NEW),
|
|
|
|
incomingSuperRoles => array[hsOfficeSepaMandateAgent(NEW)],
|
|
|
|
outgoingSubRoles => array[hsOfficeDebitorGuest(newHsOfficeDebitor), hsOfficeBankAccountGuest(newHsOfficeBankAccount)]
|
|
|
|
);
|
|
|
|
|
|
|
|
perform createRoleWithGrants(
|
|
|
|
hsOfficeSepaMandateGuest(NEW),
|
|
|
|
permissions => array['view'],
|
|
|
|
incomingSuperRoles => array[hsOfficeSepaMandateTenant(NEW)]
|
|
|
|
);
|
|
|
|
|
|
|
|
-- === END of code generated from Mermaid flowchart. ===
|
|
|
|
|
|
|
|
else
|
|
|
|
raise exception 'invalid usage of TRIGGER';
|
|
|
|
end if;
|
|
|
|
|
|
|
|
return NEW;
|
|
|
|
end; $$;
|
|
|
|
|
|
|
|
/*
|
|
|
|
An AFTER INSERT TRIGGER which creates the role structure for a new customer.
|
|
|
|
*/
|
|
|
|
create trigger createRbacRolesForHsOfficeSepaMandate_Trigger
|
|
|
|
after insert
|
2022-10-13 18:53:38 +02:00
|
|
|
on hs_office_sepamandate
|
2022-10-13 13:35:50 +02:00
|
|
|
for each row
|
|
|
|
execute procedure hsOfficeSepaMandateRbacRolesTrigger();
|
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-10-13 18:53:38 +02:00
|
|
|
--changeset hs-office-sepamandate-rbac-IDENTITY-VIEW:1 endDelimiter:--//
|
2022-10-13 13:35:50 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-10-13 18:53:38 +02:00
|
|
|
call generateRbacIdentityView('hs_office_sepamandate', idNameExpression => 'target.reference');
|
2022-10-13 13:35:50 +02:00
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-10-13 18:53:38 +02:00
|
|
|
--changeset hs-office-sepamandate-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
|
2022-10-13 13:35:50 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
2022-10-13 18:53:38 +02:00
|
|
|
call generateRbacRestrictedView('hs_office_sepamandate',
|
2022-10-13 13:35:50 +02:00
|
|
|
orderby => 'target.reference',
|
|
|
|
columnUpdates => $updates$
|
|
|
|
validity = new.validity
|
|
|
|
$updates$);
|
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-10-13 18:53:38 +02:00
|
|
|
--changeset hs-office-sepamandate-rbac-NEW-SepaMandate:1 endDelimiter:--//
|
2022-10-13 13:35:50 +02:00
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Creates a global permission for new-sepaMandate and assigns it to the hostsharing admins role.
|
|
|
|
*/
|
|
|
|
do language plpgsql $$
|
|
|
|
declare
|
|
|
|
addCustomerPermissions uuid[];
|
|
|
|
globalObjectUuid uuid;
|
|
|
|
globalAdminRoleUuid uuid ;
|
|
|
|
begin
|
|
|
|
call defineContext('granting global new-sepaMandate permission to global admin role', null, null, null);
|
|
|
|
|
|
|
|
globalAdminRoleUuid := findRoleId(globalAdmin());
|
|
|
|
globalObjectUuid := (select uuid from global);
|
|
|
|
addCustomerPermissions := createPermissions(globalObjectUuid, array ['new-sepamandate']);
|
|
|
|
call grantPermissionsToRole(globalAdminRoleUuid, addCustomerPermissions);
|
|
|
|
end;
|
|
|
|
$$;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Used by the trigger to prevent the add-customer to current user respectively assumed roles.
|
|
|
|
*/
|
|
|
|
create or replace function addHsOfficeSepaMandateNotAllowedForCurrentSubjects()
|
|
|
|
returns trigger
|
|
|
|
language PLPGSQL
|
|
|
|
as $$
|
|
|
|
begin
|
|
|
|
raise exception '[403] new-sepaMandate not permitted for %',
|
|
|
|
array_to_string(currentSubjects(), ';', 'null');
|
|
|
|
end; $$;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Checks if the user or assumed roles are allowed to create a new customer.
|
|
|
|
*/
|
2022-10-13 18:53:38 +02:00
|
|
|
create trigger hs_office_sepamandate_insert_trigger
|
2022-10-13 13:35:50 +02:00
|
|
|
before insert
|
2022-10-13 18:53:38 +02:00
|
|
|
on hs_office_sepamandate
|
2022-10-13 13:35:50 +02:00
|
|
|
for each row
|
|
|
|
-- TODO.spec: who is allowed to create new sepaMandates
|
|
|
|
when ( not hasAssumedRole() )
|
|
|
|
execute procedure addHsOfficeSepaMandateNotAllowedForCurrentSubjects();
|
|
|
|
--//
|
|
|
|
|