introduce-separate-database-schemas-hs-booking-and-hosting (#106)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/106 Reviewed-by: Marc Sandlus <marc.sandlus@hostsharing.net>
This commit is contained in:
@@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_office.contact');
|
||||
-- ============================================================================
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-contact-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRoleDescriptors('hsOfficeContact', 'hs_office.contact');
|
||||
call rbac.generateRbacRoleDescriptors('hs_office.contact');
|
||||
--//
|
||||
|
||||
|
||||
@@ -35,22 +35,22 @@ begin
|
||||
call rbac.enterTriggerForObjectUuid(NEW.uuid);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeContactOWNER(NEW),
|
||||
hs_office.contact_OWNER(NEW),
|
||||
permissions => array['DELETE'],
|
||||
incomingSuperRoles => array[rbac.globalADMIN()],
|
||||
incomingSuperRoles => array[rbac.global_ADMIN()],
|
||||
subjectUuids => array[rbac.currentSubjectUuid()]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeContactADMIN(NEW),
|
||||
hs_office.contact_ADMIN(NEW),
|
||||
permissions => array['UPDATE'],
|
||||
incomingSuperRoles => array[hsOfficeContactOWNER(NEW)]
|
||||
incomingSuperRoles => array[hs_office.contact_OWNER(NEW)]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeContactREFERRER(NEW),
|
||||
hs_office.contact_REFERRER(NEW),
|
||||
permissions => array['SELECT'],
|
||||
incomingSuperRoles => array[hsOfficeContactADMIN(NEW)]
|
||||
incomingSuperRoles => array[hs_office.contact_ADMIN(NEW)]
|
||||
);
|
||||
|
||||
call rbac.leaveTriggerForObjectUuid(NEW.uuid);
|
||||
|
@@ -49,7 +49,7 @@ INSERT INTO hs_office.contact_legacy_id(uuid, contact_id)
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-contact-MIGRATION-insert-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
create or replace function insertContactLegacyIdMapping()
|
||||
create or replace function hs_office.contact_insert_legacy_id_mapping_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -64,17 +64,17 @@ begin
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger createContactLegacyIdMapping
|
||||
create trigger insert_legacy_id_mapping_tg
|
||||
after insert on hs_office.contact
|
||||
for each row
|
||||
execute procedure insertContactLegacyIdMapping();
|
||||
execute procedure hs_office.contact_insert_legacy_id_mapping_tf();
|
||||
--/
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-contact-MIGRATION-delete-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
create or replace function deleteContactLegacyIdMapping()
|
||||
create or replace function hs_office.contact_delete_legacy_id_mapping_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -89,8 +89,8 @@ begin
|
||||
return OLD;
|
||||
end; $$;
|
||||
|
||||
create trigger removeContactLegacyIdMapping
|
||||
create trigger delete_legacy_id_mapping_tf
|
||||
before delete on hs_office.contact
|
||||
for each row
|
||||
execute procedure deleteContactLegacyIdMapping();
|
||||
execute procedure hs_office.contact_delete_legacy_id_mapping_tf();
|
||||
--/
|
||||
|
@@ -8,7 +8,7 @@
|
||||
/*
|
||||
Creates a single contact test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficeContactTestData(contCaption varchar)
|
||||
create or replace procedure hs_office.contact_create_test_data(contCaption varchar)
|
||||
language plpgsql as $$
|
||||
declare
|
||||
postalAddr varchar;
|
||||
@@ -36,7 +36,7 @@ end; $$;
|
||||
/*
|
||||
Creates a range of test contact for mass data generation.
|
||||
*/
|
||||
create or replace procedure createHsOfficeContactTestData(
|
||||
create or replace procedure hs_office.contact_create_test_data(
|
||||
startCount integer, -- count of auto generated rows before the run
|
||||
endCount integer -- count of auto generated rows after the run
|
||||
)
|
||||
@@ -44,7 +44,7 @@ create or replace procedure createHsOfficeContactTestData(
|
||||
begin
|
||||
for t in startCount..endCount
|
||||
loop
|
||||
call createHsOfficeContactTestData(base.intToVarChar(t, 4) || '#' || t);
|
||||
call hs_office.contact_create_test_data(base.intToVarChar(t, 4) || '#' || t);
|
||||
commit;
|
||||
end loop;
|
||||
end; $$;
|
||||
@@ -58,18 +58,18 @@ end; $$;
|
||||
do language plpgsql $$
|
||||
begin
|
||||
-- TODO: use better names
|
||||
call createHsOfficeContactTestData('first contact');
|
||||
call createHsOfficeContactTestData('second contact');
|
||||
call createHsOfficeContactTestData('third contact');
|
||||
call createHsOfficeContactTestData('fourth contact');
|
||||
call createHsOfficeContactTestData('fifth contact');
|
||||
call createHsOfficeContactTestData('sixth contact');
|
||||
call createHsOfficeContactTestData('seventh contact');
|
||||
call createHsOfficeContactTestData('eighth contact');
|
||||
call createHsOfficeContactTestData('ninth contact');
|
||||
call createHsOfficeContactTestData('tenth contact');
|
||||
call createHsOfficeContactTestData('eleventh contact');
|
||||
call createHsOfficeContactTestData('twelfth contact');
|
||||
call hs_office.contact_create_test_data('first contact');
|
||||
call hs_office.contact_create_test_data('second contact');
|
||||
call hs_office.contact_create_test_data('third contact');
|
||||
call hs_office.contact_create_test_data('fourth contact');
|
||||
call hs_office.contact_create_test_data('fifth contact');
|
||||
call hs_office.contact_create_test_data('sixth contact');
|
||||
call hs_office.contact_create_test_data('seventh contact');
|
||||
call hs_office.contact_create_test_data('eighth contact');
|
||||
call hs_office.contact_create_test_data('ninth contact');
|
||||
call hs_office.contact_create_test_data('tenth contact');
|
||||
call hs_office.contact_create_test_data('eleventh contact');
|
||||
call hs_office.contact_create_test_data('twelfth contact');
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@@ -4,7 +4,7 @@
|
||||
--changeset michael.hoennig:hs-office-person-MAIN-TABLE endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TYPE HsOfficePersonType AS ENUM (
|
||||
CREATE TYPE hs_office.PersonType AS ENUM (
|
||||
'??', -- unknown
|
||||
'NP', -- natural person
|
||||
'LP', -- legal person
|
||||
@@ -12,13 +12,13 @@ CREATE TYPE HsOfficePersonType AS ENUM (
|
||||
'UF', -- unincorporated firm
|
||||
'PI'); -- public institution
|
||||
|
||||
CREATE CAST (character varying as HsOfficePersonType) WITH INOUT AS IMPLICIT;
|
||||
CREATE CAST (character varying as hs_office.PersonType) WITH INOUT AS IMPLICIT;
|
||||
|
||||
create table if not exists hs_office.person
|
||||
(
|
||||
uuid uuid unique references rbac.object (uuid) initially deferred,
|
||||
version int not null default 0,
|
||||
personType HsOfficePersonType not null,
|
||||
personType hs_office.PersonType not null,
|
||||
tradeName varchar(96),
|
||||
salutation varchar(30),
|
||||
title varchar(20),
|
||||
|
@@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_office.person');
|
||||
-- ============================================================================
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-person-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRoleDescriptors('hsOfficePerson', 'hs_office.person');
|
||||
call rbac.generateRbacRoleDescriptors('hs_office.person');
|
||||
--//
|
||||
|
||||
|
||||
@@ -35,22 +35,22 @@ begin
|
||||
call rbac.enterTriggerForObjectUuid(NEW.uuid);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficePersonOWNER(NEW),
|
||||
hs_office.person_OWNER(NEW),
|
||||
permissions => array['DELETE'],
|
||||
incomingSuperRoles => array[rbac.globalADMIN()],
|
||||
incomingSuperRoles => array[rbac.global_ADMIN()],
|
||||
subjectUuids => array[rbac.currentSubjectUuid()]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficePersonADMIN(NEW),
|
||||
hs_office.person_ADMIN(NEW),
|
||||
permissions => array['UPDATE'],
|
||||
incomingSuperRoles => array[hsOfficePersonOWNER(NEW)]
|
||||
incomingSuperRoles => array[hs_office.person_OWNER(NEW)]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficePersonREFERRER(NEW),
|
||||
hs_office.person_REFERRER(NEW),
|
||||
permissions => array['SELECT'],
|
||||
incomingSuperRoles => array[hsOfficePersonADMIN(NEW)]
|
||||
incomingSuperRoles => array[hs_office.person_ADMIN(NEW)]
|
||||
);
|
||||
|
||||
call rbac.leaveTriggerForObjectUuid(NEW.uuid);
|
||||
|
@@ -8,8 +8,8 @@
|
||||
/*
|
||||
Creates a single person test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficePersonTestData(
|
||||
newPersonType HsOfficePersonType,
|
||||
create or replace procedure hs_office.person_create_test_data(
|
||||
newPersonType hs_office.PersonType,
|
||||
newTradeName varchar,
|
||||
newFamilyName varchar = null,
|
||||
newGivenName varchar = null
|
||||
@@ -32,23 +32,6 @@ begin
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
/*
|
||||
Creates a range of test persons for mass data generation.
|
||||
*/
|
||||
create or replace procedure createTestPersonTestData(
|
||||
startCount integer, -- count of auto generated rows before the run
|
||||
endCount integer -- count of auto generated rows after the run
|
||||
)
|
||||
language plpgsql as $$
|
||||
begin
|
||||
for t in startCount..endCount
|
||||
loop
|
||||
call createHsOfficePersonTestData('LP', base.intToVarChar(t, 4));
|
||||
commit;
|
||||
end loop;
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-person-TEST-DATA-GENERATION –context=dev,tc endDelimiter:--//
|
||||
@@ -56,19 +39,19 @@ end; $$;
|
||||
|
||||
do language plpgsql $$
|
||||
begin
|
||||
call createHsOfficePersonTestData('LP', 'Hostsharing eG');
|
||||
call createHsOfficePersonTestData('LP', 'First GmbH');
|
||||
call createHsOfficePersonTestData('NP', null, 'Firby', 'Susan');
|
||||
call createHsOfficePersonTestData('NP', null, 'Smith', 'Peter');
|
||||
call createHsOfficePersonTestData('NP', null, 'Tucker', 'Jack');
|
||||
call createHsOfficePersonTestData('NP', null, 'Fouler', 'Ellie');
|
||||
call createHsOfficePersonTestData('LP', 'Second e.K.', 'Smith', 'Peter');
|
||||
call createHsOfficePersonTestData('IF', 'Third OHG');
|
||||
call createHsOfficePersonTestData('LP', 'Fourth eG');
|
||||
call createHsOfficePersonTestData('UF', 'Erben Bessler', 'Mel', 'Bessler');
|
||||
call createHsOfficePersonTestData('NP', null, 'Bessler', 'Anita');
|
||||
call createHsOfficePersonTestData('NP', null, 'Bessler', 'Bert');
|
||||
call createHsOfficePersonTestData('NP', null, 'Winkler', 'Paul');
|
||||
call hs_office.person_create_test_data('LP', 'Hostsharing eG');
|
||||
call hs_office.person_create_test_data('LP', 'First GmbH');
|
||||
call hs_office.person_create_test_data('NP', null, 'Firby', 'Susan');
|
||||
call hs_office.person_create_test_data('NP', null, 'Smith', 'Peter');
|
||||
call hs_office.person_create_test_data('NP', null, 'Tucker', 'Jack');
|
||||
call hs_office.person_create_test_data('NP', null, 'Fouler', 'Ellie');
|
||||
call hs_office.person_create_test_data('LP', 'Second e.K.', 'Smith', 'Peter');
|
||||
call hs_office.person_create_test_data('IF', 'Third OHG');
|
||||
call hs_office.person_create_test_data('LP', 'Fourth eG');
|
||||
call hs_office.person_create_test_data('UF', 'Erben Bessler', 'Mel', 'Bessler');
|
||||
call hs_office.person_create_test_data('NP', null, 'Bessler', 'Anita');
|
||||
call hs_office.person_create_test_data('NP', null, 'Bessler', 'Bert');
|
||||
call hs_office.person_create_test_data('NP', null, 'Winkler', 'Paul');
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@@ -4,7 +4,7 @@
|
||||
--changeset michael.hoennig:hs-office-relation-MAIN-TABLE endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TYPE HsOfficeRelationType AS ENUM (
|
||||
CREATE TYPE hs_office.RelationType AS ENUM (
|
||||
'UNKNOWN',
|
||||
'PARTNER',
|
||||
'EX_PARTNER',
|
||||
@@ -14,7 +14,7 @@ CREATE TYPE HsOfficeRelationType AS ENUM (
|
||||
'OPERATIONS',
|
||||
'SUBSCRIBER');
|
||||
|
||||
CREATE CAST (character varying as HsOfficeRelationType) WITH INOUT AS IMPLICIT;
|
||||
CREATE CAST (character varying as hs_office.RelationType) WITH INOUT AS IMPLICIT;
|
||||
|
||||
create table if not exists hs_office.relation
|
||||
(
|
||||
@@ -23,7 +23,7 @@ create table if not exists hs_office.relation
|
||||
anchorUuid uuid not null references hs_office.person(uuid),
|
||||
holderUuid uuid not null references hs_office.person(uuid),
|
||||
contactUuid uuid references hs_office.contact(uuid),
|
||||
type HsOfficeRelationType not null,
|
||||
type hs_office.RelationType not null,
|
||||
mark varchar(24)
|
||||
);
|
||||
--//
|
||||
|
@@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_office.relation');
|
||||
-- ============================================================================
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-relation-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRoleDescriptors('hsOfficeRelation', 'hs_office.relation');
|
||||
call rbac.generateRbacRoleDescriptors('hs_office.relation');
|
||||
--//
|
||||
|
||||
|
||||
@@ -48,42 +48,42 @@ begin
|
||||
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeRelationOWNER(NEW),
|
||||
hs_office.relation_OWNER(NEW),
|
||||
permissions => array['DELETE'],
|
||||
incomingSuperRoles => array[rbac.globalADMIN()],
|
||||
incomingSuperRoles => array[rbac.global_ADMIN()],
|
||||
subjectUuids => array[rbac.currentSubjectUuid()]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeRelationADMIN(NEW),
|
||||
hs_office.relation_ADMIN(NEW),
|
||||
permissions => array['UPDATE'],
|
||||
incomingSuperRoles => array[hsOfficeRelationOWNER(NEW)]
|
||||
incomingSuperRoles => array[hs_office.relation_OWNER(NEW)]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeRelationAGENT(NEW),
|
||||
incomingSuperRoles => array[hsOfficeRelationADMIN(NEW)]
|
||||
hs_office.relation_AGENT(NEW),
|
||||
incomingSuperRoles => array[hs_office.relation_ADMIN(NEW)]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeRelationTENANT(NEW),
|
||||
hs_office.relation_TENANT(NEW),
|
||||
permissions => array['SELECT'],
|
||||
incomingSuperRoles => array[
|
||||
hsOfficeContactADMIN(newContact),
|
||||
hsOfficeRelationAGENT(NEW)],
|
||||
hs_office.contact_ADMIN(newContact),
|
||||
hs_office.relation_AGENT(NEW)],
|
||||
outgoingSubRoles => array[
|
||||
hsOfficeContactREFERRER(newContact),
|
||||
hsOfficePersonREFERRER(newAnchorPerson),
|
||||
hsOfficePersonREFERRER(newHolderPerson)]
|
||||
hs_office.contact_REFERRER(newContact),
|
||||
hs_office.person_REFERRER(newAnchorPerson),
|
||||
hs_office.person_REFERRER(newHolderPerson)]
|
||||
);
|
||||
|
||||
IF NEW.type = 'REPRESENTATIVE' THEN
|
||||
call rbac.grantRoleToRole(hsOfficePersonOWNER(newAnchorPerson), hsOfficeRelationADMIN(NEW));
|
||||
call rbac.grantRoleToRole(hsOfficeRelationAGENT(NEW), hsOfficePersonADMIN(newAnchorPerson));
|
||||
call rbac.grantRoleToRole(hsOfficeRelationOWNER(NEW), hsOfficePersonADMIN(newHolderPerson));
|
||||
call rbac.grantRoleToRole(hs_office.person_OWNER(newAnchorPerson), hs_office.relation_ADMIN(NEW));
|
||||
call rbac.grantRoleToRole(hs_office.relation_AGENT(NEW), hs_office.person_ADMIN(newAnchorPerson));
|
||||
call rbac.grantRoleToRole(hs_office.relation_OWNER(NEW), hs_office.person_ADMIN(newHolderPerson));
|
||||
ELSE
|
||||
call rbac.grantRoleToRole(hsOfficeRelationAGENT(NEW), hsOfficePersonADMIN(newHolderPerson));
|
||||
call rbac.grantRoleToRole(hsOfficeRelationOWNER(NEW), hsOfficePersonADMIN(newAnchorPerson));
|
||||
call rbac.grantRoleToRole(hs_office.relation_AGENT(NEW), hs_office.person_ADMIN(newHolderPerson));
|
||||
call rbac.grantRoleToRole(hs_office.relation_OWNER(NEW), hs_office.person_ADMIN(newAnchorPerson));
|
||||
END IF;
|
||||
|
||||
call rbac.leaveTriggerForObjectUuid(NEW.uuid);
|
||||
@@ -170,7 +170,7 @@ do language plpgsql $$
|
||||
LOOP
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(row.uuid, 'INSERT', 'hs_office.relation'),
|
||||
hsOfficePersonADMIN(row));
|
||||
hs_office.person_ADMIN(row));
|
||||
END LOOP;
|
||||
end;
|
||||
$$;
|
||||
@@ -178,7 +178,7 @@ $$;
|
||||
/**
|
||||
Grants hs_office.relation INSERT permission to specified role of new person rows.
|
||||
*/
|
||||
create or replace function hs_office.new_relation_grants_insert_to_person_tf()
|
||||
create or replace function hs_office.relation_grants_insert_to_person_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -186,16 +186,16 @@ begin
|
||||
-- unconditional for all rows in that table
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.relation'),
|
||||
hsOfficePersonADMIN(NEW));
|
||||
hs_office.person_ADMIN(NEW));
|
||||
-- end.
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger z_new_relation_grants_after_insert_tg
|
||||
-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger relation_z_grants_after_insert_tg
|
||||
after insert on hs_office.person
|
||||
for each row
|
||||
execute procedure hs_office.new_relation_grants_insert_to_person_tf();
|
||||
execute procedure hs_office.relation_grants_insert_to_person_tf();
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
|
@@ -8,9 +8,9 @@
|
||||
/*
|
||||
Creates a single relation test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficeRelationTestData(
|
||||
create or replace procedure hs_office.relation_create_test_data(
|
||||
holderPersonName varchar,
|
||||
relationType HsOfficeRelationType,
|
||||
relationType hs_office.RelationType,
|
||||
anchorPersonName varchar,
|
||||
contactCaption varchar,
|
||||
mark varchar default null)
|
||||
@@ -58,7 +58,7 @@ end; $$;
|
||||
/*
|
||||
Creates a range of test relation for mass data generation.
|
||||
*/
|
||||
create or replace procedure createHsOfficeRelationTestData(
|
||||
create or replace procedure hs_office.relation_create_test_data(
|
||||
startCount integer, -- count of auto generated rows before the run
|
||||
endCount integer -- count of auto generated rows after the run
|
||||
)
|
||||
@@ -72,7 +72,7 @@ begin
|
||||
select p.* from hs_office.person p where tradeName = base.intToVarChar(t, 4) into person;
|
||||
select c.* from hs_office.contact c where c.caption = base.intToVarChar(t, 4) || '#' || t into contact;
|
||||
|
||||
call createHsOfficeRelationTestData(person.uuid, contact.uuid, 'REPRESENTATIVE');
|
||||
call hs_office.relation_create_test_data(person.uuid, contact.uuid, 'REPRESENTATIVE');
|
||||
commit;
|
||||
end loop;
|
||||
end; $$;
|
||||
@@ -87,25 +87,25 @@ do language plpgsql $$
|
||||
begin
|
||||
call base.defineContext('creating relation test-data', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN');
|
||||
|
||||
call createHsOfficeRelationTestData('First GmbH', 'PARTNER', 'Hostsharing eG', 'first contact');
|
||||
call createHsOfficeRelationTestData('Firby', 'REPRESENTATIVE', 'First GmbH', 'first contact');
|
||||
call createHsOfficeRelationTestData('First GmbH', 'DEBITOR', 'First GmbH', 'first contact');
|
||||
call hs_office.relation_create_test_data('First GmbH', 'PARTNER', 'Hostsharing eG', 'first contact');
|
||||
call hs_office.relation_create_test_data('Firby', 'REPRESENTATIVE', 'First GmbH', 'first contact');
|
||||
call hs_office.relation_create_test_data('First GmbH', 'DEBITOR', 'First GmbH', 'first contact');
|
||||
|
||||
call createHsOfficeRelationTestData('Second e.K.', 'PARTNER', 'Hostsharing eG', 'second contact');
|
||||
call createHsOfficeRelationTestData('Smith', 'REPRESENTATIVE', 'Second e.K.', 'second contact');
|
||||
call createHsOfficeRelationTestData('Second e.K.', 'DEBITOR', 'Second e.K.', 'second contact');
|
||||
call hs_office.relation_create_test_data('Second e.K.', 'PARTNER', 'Hostsharing eG', 'second contact');
|
||||
call hs_office.relation_create_test_data('Smith', 'REPRESENTATIVE', 'Second e.K.', 'second contact');
|
||||
call hs_office.relation_create_test_data('Second e.K.', 'DEBITOR', 'Second e.K.', 'second contact');
|
||||
|
||||
call createHsOfficeRelationTestData('Third OHG', 'PARTNER', 'Hostsharing eG', 'third contact');
|
||||
call createHsOfficeRelationTestData('Tucker', 'REPRESENTATIVE', 'Third OHG', 'third contact');
|
||||
call createHsOfficeRelationTestData('Third OHG', 'DEBITOR', 'Third OHG', 'third contact');
|
||||
call hs_office.relation_create_test_data('Third OHG', 'PARTNER', 'Hostsharing eG', 'third contact');
|
||||
call hs_office.relation_create_test_data('Tucker', 'REPRESENTATIVE', 'Third OHG', 'third contact');
|
||||
call hs_office.relation_create_test_data('Third OHG', 'DEBITOR', 'Third OHG', 'third contact');
|
||||
|
||||
call createHsOfficeRelationTestData('Fourth eG', 'PARTNER', 'Hostsharing eG', 'fourth contact');
|
||||
call createHsOfficeRelationTestData('Fouler', 'REPRESENTATIVE', 'Third OHG', 'third contact');
|
||||
call createHsOfficeRelationTestData('Third OHG', 'DEBITOR', 'Third OHG', 'third contact');
|
||||
call hs_office.relation_create_test_data('Fourth eG', 'PARTNER', 'Hostsharing eG', 'fourth contact');
|
||||
call hs_office.relation_create_test_data('Fouler', 'REPRESENTATIVE', 'Third OHG', 'third contact');
|
||||
call hs_office.relation_create_test_data('Third OHG', 'DEBITOR', 'Third OHG', 'third contact');
|
||||
|
||||
call createHsOfficeRelationTestData('Smith', 'PARTNER', 'Hostsharing eG', 'sixth contact');
|
||||
call createHsOfficeRelationTestData('Smith', 'DEBITOR', 'Smith', 'third contact');
|
||||
call createHsOfficeRelationTestData('Smith', 'SUBSCRIBER', 'Third OHG', 'third contact', 'members-announce');
|
||||
call hs_office.relation_create_test_data('Smith', 'PARTNER', 'Hostsharing eG', 'sixth contact');
|
||||
call hs_office.relation_create_test_data('Smith', 'DEBITOR', 'Smith', 'third contact');
|
||||
call hs_office.relation_create_test_data('Smith', 'SUBSCRIBER', 'Third OHG', 'third contact', 'members-announce');
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_office.partner');
|
||||
-- ============================================================================
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-partner-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRoleDescriptors('hsOfficePartner', 'hs_office.partner');
|
||||
call rbac.generateRbacRoleDescriptors('hs_office.partner');
|
||||
--//
|
||||
|
||||
|
||||
@@ -42,12 +42,12 @@ begin
|
||||
SELECT * FROM hs_office.partner_details WHERE uuid = NEW.detailsUuid INTO newPartnerDetails;
|
||||
assert newPartnerDetails.uuid is not null, format('newPartnerDetails must not be null for NEW.detailsUuid = %s', NEW.detailsUuid);
|
||||
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'DELETE'), hsOfficeRelationOWNER(newPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'SELECT'), hsOfficeRelationTENANT(newPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'UPDATE'), hsOfficeRelationADMIN(newPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'DELETE'), hsOfficeRelationOWNER(newPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'SELECT'), hsOfficeRelationAGENT(newPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'UPDATE'), hsOfficeRelationAGENT(newPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'DELETE'), hs_office.relation_OWNER(newPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'SELECT'), hs_office.relation_TENANT(newPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'UPDATE'), hs_office.relation_ADMIN(newPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'DELETE'), hs_office.relation_OWNER(newPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'SELECT'), hs_office.relation_AGENT(newPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'UPDATE'), hs_office.relation_AGENT(newPartnerRel));
|
||||
|
||||
call rbac.leaveTriggerForObjectUuid(NEW.uuid);
|
||||
end; $$;
|
||||
@@ -110,23 +110,23 @@ begin
|
||||
|
||||
if NEW.partnerRelUuid <> OLD.partnerRelUuid then
|
||||
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(OLD.uuid, 'DELETE'), hsOfficeRelationOWNER(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'DELETE'), hsOfficeRelationOWNER(newPartnerRel));
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(OLD.uuid, 'DELETE'), hs_office.relation_OWNER(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'DELETE'), hs_office.relation_OWNER(newPartnerRel));
|
||||
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(OLD.uuid, 'UPDATE'), hsOfficeRelationADMIN(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'UPDATE'), hsOfficeRelationADMIN(newPartnerRel));
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(OLD.uuid, 'UPDATE'), hs_office.relation_ADMIN(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'UPDATE'), hs_office.relation_ADMIN(newPartnerRel));
|
||||
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(OLD.uuid, 'SELECT'), hsOfficeRelationTENANT(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'SELECT'), hsOfficeRelationTENANT(newPartnerRel));
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(OLD.uuid, 'SELECT'), hs_office.relation_TENANT(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'SELECT'), hs_office.relation_TENANT(newPartnerRel));
|
||||
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(oldPartnerDetails.uuid, 'DELETE'), hsOfficeRelationOWNER(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'DELETE'), hsOfficeRelationOWNER(newPartnerRel));
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(oldPartnerDetails.uuid, 'DELETE'), hs_office.relation_OWNER(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'DELETE'), hs_office.relation_OWNER(newPartnerRel));
|
||||
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(oldPartnerDetails.uuid, 'UPDATE'), hsOfficeRelationAGENT(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'UPDATE'), hsOfficeRelationAGENT(newPartnerRel));
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(oldPartnerDetails.uuid, 'UPDATE'), hs_office.relation_AGENT(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'UPDATE'), hs_office.relation_AGENT(newPartnerRel));
|
||||
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(oldPartnerDetails.uuid, 'SELECT'), hsOfficeRelationAGENT(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'SELECT'), hsOfficeRelationAGENT(newPartnerRel));
|
||||
call rbac.revokePermissionFromRole(rbac.getPermissionId(oldPartnerDetails.uuid, 'SELECT'), hs_office.relation_AGENT(oldPartnerRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(newPartnerDetails.uuid, 'SELECT'), hs_office.relation_AGENT(newPartnerRel));
|
||||
|
||||
end if;
|
||||
|
||||
@@ -173,7 +173,7 @@ do language plpgsql $$
|
||||
LOOP
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(row.uuid, 'INSERT', 'hs_office.partner'),
|
||||
rbac.globalADMIN());
|
||||
rbac.global_ADMIN());
|
||||
END LOOP;
|
||||
end;
|
||||
$$;
|
||||
@@ -181,7 +181,7 @@ $$;
|
||||
/**
|
||||
Grants hs_office.partner INSERT permission to specified role of new global rows.
|
||||
*/
|
||||
create or replace function hs_office.new_partner_grants_insert_to_global_tf()
|
||||
create or replace function hs_office.partner_grants_insert_to_global_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -189,16 +189,16 @@ begin
|
||||
-- unconditional for all rows in that table
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.partner'),
|
||||
rbac.globalADMIN());
|
||||
rbac.global_ADMIN());
|
||||
-- end.
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger z_new_partner_grants_after_insert_tg
|
||||
-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger partner_z_grants_after_insert_tg
|
||||
after insert on rbac.global
|
||||
for each row
|
||||
execute procedure hs_office.new_partner_grants_insert_to_global_tf();
|
||||
execute procedure hs_office.partner_grants_insert_to_global_tf();
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
|
@@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_office.partner_details');
|
||||
-- ============================================================================
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-partner-details-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRoleDescriptors('hsOfficePartnerDetails', 'hs_office.partner_details');
|
||||
call rbac.generateRbacRoleDescriptors('hs_office.partner_details');
|
||||
--//
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ do language plpgsql $$
|
||||
LOOP
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(row.uuid, 'INSERT', 'hs_office.partner_details'),
|
||||
rbac.globalADMIN());
|
||||
rbac.global_ADMIN());
|
||||
END LOOP;
|
||||
end;
|
||||
$$;
|
||||
@@ -85,7 +85,7 @@ $$;
|
||||
/**
|
||||
Grants hs_office.partner_details INSERT permission to specified role of new global rows.
|
||||
*/
|
||||
create or replace function hs_office.new_partner_details_grants_insert_to_global_tf()
|
||||
create or replace function hs_office.partner_details_grants_insert_to_global_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -93,16 +93,16 @@ begin
|
||||
-- unconditional for all rows in that table
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.partner_details'),
|
||||
rbac.globalADMIN());
|
||||
rbac.global_ADMIN());
|
||||
-- end.
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger z_new_partner_details_grants_after_insert_tg
|
||||
-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger partner_details_z_grants_after_insert_tg
|
||||
after insert on rbac.global
|
||||
for each row
|
||||
execute procedure hs_office.new_partner_details_grants_insert_to_global_tf();
|
||||
execute procedure hs_office.partner_details_grants_insert_to_global_tf();
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
|
@@ -48,7 +48,7 @@ INSERT INTO hs_office.partner_legacy_id(uuid, bp_id)
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-partner-MIGRATION-insert-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
create or replace function insertPartnerLegacyIdMapping()
|
||||
create or replace function hs_office.partner_insert_legacy_id_mapping_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -63,17 +63,17 @@ begin
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger createPartnerLegacyIdMapping
|
||||
create trigger insert_legacy_id_mapping_tf
|
||||
after insert on hs_office.partner
|
||||
for each row
|
||||
execute procedure insertPartnerLegacyIdMapping();
|
||||
execute procedure hs_office.partner_insert_legacy_id_mapping_tf();
|
||||
--/
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-partner-MIGRATION-delete-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
create or replace function deletePartnerLegacyIdMapping()
|
||||
create or replace function hs_office.partner_delete_legacy_id_mapping_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -88,8 +88,8 @@ begin
|
||||
return OLD;
|
||||
end; $$;
|
||||
|
||||
create trigger removePartnerLegacyIdMapping
|
||||
create trigger delete_legacy_id_mapping_tg
|
||||
before delete on hs_office.partner
|
||||
for each row
|
||||
execute procedure deletePartnerLegacyIdMapping();
|
||||
execute procedure hs_office.partner_delete_legacy_id_mapping_tf();
|
||||
--/
|
||||
|
@@ -8,7 +8,7 @@
|
||||
/*
|
||||
Creates a single partner test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficePartnerTestData(
|
||||
create or replace procedure hs_office.partner_create_test_data(
|
||||
mandantTradeName varchar,
|
||||
newPartnerNumber numeric(5),
|
||||
partnerPersonName varchar,
|
||||
@@ -73,11 +73,11 @@ do language plpgsql $$
|
||||
begin
|
||||
call base.defineContext('creating partner test-data ', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN');
|
||||
|
||||
call createHsOfficePartnerTestData('Hostsharing eG', 10001, 'First GmbH', 'first contact');
|
||||
call createHsOfficePartnerTestData('Hostsharing eG', 10002, 'Second e.K.', 'second contact');
|
||||
call createHsOfficePartnerTestData('Hostsharing eG', 10003, 'Third OHG', 'third contact');
|
||||
call createHsOfficePartnerTestData('Hostsharing eG', 10004, 'Fourth eG', 'fourth contact');
|
||||
call createHsOfficePartnerTestData('Hostsharing eG', 10010, 'Smith', 'fifth contact');
|
||||
call hs_office.partner_create_test_data('Hostsharing eG', 10001, 'First GmbH', 'first contact');
|
||||
call hs_office.partner_create_test_data('Hostsharing eG', 10002, 'Second e.K.', 'second contact');
|
||||
call hs_office.partner_create_test_data('Hostsharing eG', 10003, 'Third OHG', 'third contact');
|
||||
call hs_office.partner_create_test_data('Hostsharing eG', 10004, 'Fourth eG', 'fourth contact');
|
||||
call hs_office.partner_create_test_data('Hostsharing eG', 10010, 'Smith', 'fifth contact');
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_office.bankaccount');
|
||||
-- ============================================================================
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-bankaccount-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRoleDescriptors('hsOfficeBankAccount', 'hs_office.bankaccount');
|
||||
call rbac.generateRbacRoleDescriptors('hs_office.bankaccount');
|
||||
--//
|
||||
|
||||
|
||||
@@ -35,22 +35,22 @@ begin
|
||||
call rbac.enterTriggerForObjectUuid(NEW.uuid);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeBankAccountOWNER(NEW),
|
||||
hs_office.bankaccount_OWNER(NEW),
|
||||
permissions => array['DELETE'],
|
||||
incomingSuperRoles => array[rbac.globalADMIN()],
|
||||
incomingSuperRoles => array[rbac.global_ADMIN()],
|
||||
subjectUuids => array[rbac.currentSubjectUuid()]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeBankAccountADMIN(NEW),
|
||||
hs_office.bankaccount_ADMIN(NEW),
|
||||
permissions => array['UPDATE'],
|
||||
incomingSuperRoles => array[hsOfficeBankAccountOWNER(NEW)]
|
||||
incomingSuperRoles => array[hs_office.bankaccount_OWNER(NEW)]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeBankAccountREFERRER(NEW),
|
||||
hs_office.bankaccount_REFERRER(NEW),
|
||||
permissions => array['SELECT'],
|
||||
incomingSuperRoles => array[hsOfficeBankAccountADMIN(NEW)]
|
||||
incomingSuperRoles => array[hs_office.bankaccount_ADMIN(NEW)]
|
||||
);
|
||||
|
||||
call rbac.leaveTriggerForObjectUuid(NEW.uuid);
|
||||
|
@@ -8,7 +8,7 @@
|
||||
/*
|
||||
Creates a single bankaccount test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficeBankAccountTestData(givenHolder varchar, givenIBAN varchar, givenBIC varchar)
|
||||
create or replace procedure hs_office.bankaccount_create_test_data(givenHolder varchar, givenIBAN varchar, givenBIC varchar)
|
||||
language plpgsql as $$
|
||||
declare
|
||||
emailAddr varchar;
|
||||
@@ -34,13 +34,13 @@ do language plpgsql $$
|
||||
call base.defineContext('creating bankaccount test-data');
|
||||
|
||||
-- IBANs+BICs taken from https://ibanvalidieren.de/beispiele.html
|
||||
call createHsOfficeBankAccountTestData('First GmbH', 'DE02120300000000202051', 'BYLADEM1001');
|
||||
call createHsOfficeBankAccountTestData('Peter Smith', 'DE02500105170137075030', 'INGDDEFF');
|
||||
call createHsOfficeBankAccountTestData('Second e.K.', 'DE02100500000054540402', 'BELADEBE');
|
||||
call createHsOfficeBankAccountTestData('Third OHG', 'DE02300209000106531065', 'CMCIDEDD');
|
||||
call createHsOfficeBankAccountTestData('Fourth eG', 'DE02200505501015871393', 'HASPDEHH');
|
||||
call createHsOfficeBankAccountTestData('Mel Bessler', 'DE02100100100006820101', 'PBNKDEFF');
|
||||
call createHsOfficeBankAccountTestData('Anita Bessler', 'DE02300606010002474689', 'DAAEDEDD');
|
||||
call createHsOfficeBankAccountTestData('Paul Winkler', 'DE02600501010002034304', 'SOLADEST600');
|
||||
call hs_office.bankaccount_create_test_data('First GmbH', 'DE02120300000000202051', 'BYLADEM1001');
|
||||
call hs_office.bankaccount_create_test_data('Peter Smith', 'DE02500105170137075030', 'INGDDEFF');
|
||||
call hs_office.bankaccount_create_test_data('Second e.K.', 'DE02100500000054540402', 'BELADEBE');
|
||||
call hs_office.bankaccount_create_test_data('Third OHG', 'DE02300209000106531065', 'CMCIDEDD');
|
||||
call hs_office.bankaccount_create_test_data('Fourth eG', 'DE02200505501015871393', 'HASPDEHH');
|
||||
call hs_office.bankaccount_create_test_data('Mel Bessler', 'DE02100100100006820101', 'PBNKDEFF');
|
||||
call hs_office.bankaccount_create_test_data('Anita Bessler', 'DE02300606010002474689', 'DAAEDEDD');
|
||||
call hs_office.bankaccount_create_test_data('Paul Winkler', 'DE02600501010002034304', 'SOLADEST600');
|
||||
end;
|
||||
$$;
|
||||
|
@@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_office.debitor');
|
||||
-- ============================================================================
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-debitor-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRoleDescriptors('hsOfficeDebitor', 'hs_office.debitor');
|
||||
call rbac.generateRbacRoleDescriptors('hs_office.debitor');
|
||||
--//
|
||||
|
||||
|
||||
@@ -51,15 +51,15 @@ begin
|
||||
|
||||
SELECT * FROM hs_office.bankaccount WHERE uuid = NEW.refundBankAccountUuid INTO newRefundBankAccount;
|
||||
|
||||
call rbac.grantRoleToRole(hsOfficeBankAccountREFERRER(newRefundBankAccount), hsOfficeRelationAGENT(newDebitorRel));
|
||||
call rbac.grantRoleToRole(hsOfficeRelationADMIN(newDebitorRel), hsOfficeRelationADMIN(newPartnerRel));
|
||||
call rbac.grantRoleToRole(hsOfficeRelationAGENT(newDebitorRel), hsOfficeBankAccountADMIN(newRefundBankAccount));
|
||||
call rbac.grantRoleToRole(hsOfficeRelationAGENT(newDebitorRel), hsOfficeRelationAGENT(newPartnerRel));
|
||||
call rbac.grantRoleToRole(hsOfficeRelationTENANT(newPartnerRel), hsOfficeRelationAGENT(newDebitorRel));
|
||||
call rbac.grantRoleToRole(hs_office.bankaccount_REFERRER(newRefundBankAccount), hs_office.relation_AGENT(newDebitorRel));
|
||||
call rbac.grantRoleToRole(hs_office.relation_ADMIN(newDebitorRel), hs_office.relation_ADMIN(newPartnerRel));
|
||||
call rbac.grantRoleToRole(hs_office.relation_AGENT(newDebitorRel), hs_office.bankaccount_ADMIN(newRefundBankAccount));
|
||||
call rbac.grantRoleToRole(hs_office.relation_AGENT(newDebitorRel), hs_office.relation_AGENT(newPartnerRel));
|
||||
call rbac.grantRoleToRole(hs_office.relation_TENANT(newPartnerRel), hs_office.relation_AGENT(newDebitorRel));
|
||||
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'DELETE'), hsOfficeRelationOWNER(newDebitorRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'SELECT'), hsOfficeRelationTENANT(newDebitorRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'UPDATE'), hsOfficeRelationADMIN(newDebitorRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'DELETE'), hs_office.relation_OWNER(newDebitorRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'SELECT'), hs_office.relation_TENANT(newDebitorRel));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'UPDATE'), hs_office.relation_ADMIN(newDebitorRel));
|
||||
|
||||
call rbac.leaveTriggerForObjectUuid(NEW.uuid);
|
||||
end; $$;
|
||||
@@ -146,7 +146,7 @@ do language plpgsql $$
|
||||
LOOP
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(row.uuid, 'INSERT', 'hs_office.debitor'),
|
||||
rbac.globalADMIN());
|
||||
rbac.global_ADMIN());
|
||||
END LOOP;
|
||||
end;
|
||||
$$;
|
||||
@@ -154,7 +154,7 @@ $$;
|
||||
/**
|
||||
Grants hs_office.debitor INSERT permission to specified role of new global rows.
|
||||
*/
|
||||
create or replace function hs_office.new_debitor_grants_insert_to_global_tf()
|
||||
create or replace function hs_office.debitor_grants_insert_to_global_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -162,16 +162,16 @@ begin
|
||||
-- unconditional for all rows in that table
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.debitor'),
|
||||
rbac.globalADMIN());
|
||||
rbac.global_ADMIN());
|
||||
-- end.
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger z_new_debitor_grants_after_insert_tg
|
||||
-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger debitor_z_grants_after_insert_tg
|
||||
after insert on rbac.global
|
||||
for each row
|
||||
execute procedure hs_office.new_debitor_grants_insert_to_global_tf();
|
||||
execute procedure hs_office.debitor_grants_insert_to_global_tf();
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
|
@@ -8,7 +8,7 @@
|
||||
/*
|
||||
Creates a single debitor test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficeDebitorTestData(
|
||||
create or replace procedure hs_office.debitor_create_test_data(
|
||||
withDebitorNumberSuffix numeric(5),
|
||||
forPartnerPersonName varchar,
|
||||
forBillingContactCaption varchar,
|
||||
@@ -52,9 +52,9 @@ do language plpgsql $$
|
||||
begin
|
||||
call base.defineContext('creating debitor test-data', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN');
|
||||
|
||||
call createHsOfficeDebitorTestData(11, 'First GmbH', 'first contact', 'fir');
|
||||
call createHsOfficeDebitorTestData(12, 'Second e.K.', 'second contact', 'sec');
|
||||
call createHsOfficeDebitorTestData(13, 'Third OHG', 'third contact', 'thi');
|
||||
call hs_office.debitor_create_test_data(11, 'First GmbH', 'first contact', 'fir');
|
||||
call hs_office.debitor_create_test_data(12, 'Second e.K.', 'second contact', 'sec');
|
||||
call hs_office.debitor_create_test_data(13, 'Third OHG', 'third contact', 'thi');
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_office.sepamandate');
|
||||
-- ============================================================================
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-sepamandate-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRoleDescriptors('hsOfficeSepaMandate', 'hs_office.sepamandate');
|
||||
call rbac.generateRbacRoleDescriptors('hs_office.sepamandate');
|
||||
--//
|
||||
|
||||
|
||||
@@ -48,34 +48,34 @@ begin
|
||||
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeSepaMandateOWNER(NEW),
|
||||
hs_office.sepamandate_OWNER(NEW),
|
||||
permissions => array['DELETE'],
|
||||
incomingSuperRoles => array[rbac.globalADMIN()],
|
||||
incomingSuperRoles => array[rbac.global_ADMIN()],
|
||||
subjectUuids => array[rbac.currentSubjectUuid()]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeSepaMandateADMIN(NEW),
|
||||
hs_office.sepamandate_ADMIN(NEW),
|
||||
permissions => array['UPDATE'],
|
||||
incomingSuperRoles => array[hsOfficeSepaMandateOWNER(NEW)]
|
||||
incomingSuperRoles => array[hs_office.sepamandate_OWNER(NEW)]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeSepaMandateAGENT(NEW),
|
||||
incomingSuperRoles => array[hsOfficeSepaMandateADMIN(NEW)],
|
||||
hs_office.sepamandate_AGENT(NEW),
|
||||
incomingSuperRoles => array[hs_office.sepamandate_ADMIN(NEW)],
|
||||
outgoingSubRoles => array[
|
||||
hsOfficeBankAccountREFERRER(newBankAccount),
|
||||
hsOfficeRelationAGENT(newDebitorRel)]
|
||||
hs_office.bankaccount_REFERRER(newBankAccount),
|
||||
hs_office.relation_AGENT(newDebitorRel)]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeSepaMandateREFERRER(NEW),
|
||||
hs_office.sepamandate_REFERRER(NEW),
|
||||
permissions => array['SELECT'],
|
||||
incomingSuperRoles => array[
|
||||
hsOfficeBankAccountADMIN(newBankAccount),
|
||||
hsOfficeRelationAGENT(newDebitorRel),
|
||||
hsOfficeSepaMandateAGENT(NEW)],
|
||||
outgoingSubRoles => array[hsOfficeRelationTENANT(newDebitorRel)]
|
||||
hs_office.bankaccount_ADMIN(newBankAccount),
|
||||
hs_office.relation_AGENT(newDebitorRel),
|
||||
hs_office.sepamandate_AGENT(NEW)],
|
||||
outgoingSubRoles => array[hs_office.relation_TENANT(newDebitorRel)]
|
||||
);
|
||||
|
||||
call rbac.leaveTriggerForObjectUuid(NEW.uuid);
|
||||
@@ -121,7 +121,7 @@ do language plpgsql $$
|
||||
LOOP
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(row.uuid, 'INSERT', 'hs_office.sepamandate'),
|
||||
hsOfficeRelationADMIN(row));
|
||||
hs_office.relation_ADMIN(row));
|
||||
END LOOP;
|
||||
end;
|
||||
$$;
|
||||
@@ -129,7 +129,7 @@ $$;
|
||||
/**
|
||||
Grants hs_office.sepamandate INSERT permission to specified role of new relation rows.
|
||||
*/
|
||||
create or replace function hs_office.new_sepamandate_grants_insert_to_relation_tf()
|
||||
create or replace function hs_office.sepamandate_grants_insert_to_relation_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -137,16 +137,16 @@ begin
|
||||
if NEW.type = 'DEBITOR' then
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.sepamandate'),
|
||||
hsOfficeRelationADMIN(NEW));
|
||||
hs_office.relation_ADMIN(NEW));
|
||||
end if;
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger z_new_sepamandate_grants_after_insert_tg
|
||||
-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger sepamandate_z_grants_after_insert_tg
|
||||
after insert on hs_office.relation
|
||||
for each row
|
||||
execute procedure hs_office.new_sepamandate_grants_insert_to_relation_tf();
|
||||
execute procedure hs_office.sepamandate_grants_insert_to_relation_tf();
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
|
@@ -50,7 +50,7 @@ INSERT INTO hs_office.sepamandate_legacy_id(uuid, sepa_mandate_id)
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-sepamandate-MIGRATION-insert-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
create or replace function insertSepaMandateLegacyIdMapping()
|
||||
create or replace function hs_office.sepamandate_insert_legacy_id_mapping_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -65,17 +65,17 @@ begin
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger createSepaMandateLegacyIdMapping
|
||||
create trigger insert_legacy_id_mapping_tg
|
||||
after insert on hs_office.sepamandate
|
||||
for each row
|
||||
execute procedure insertSepaMandateLegacyIdMapping();
|
||||
execute procedure hs_office.sepamandate_insert_legacy_id_mapping_tf();
|
||||
--/
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-sepamandate-MIGRATION-delete-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
create or replace function deleteSepaMandateLegacyIdMapping()
|
||||
create or replace function hs_office.sepamandate_delete_legacy_id_mapping_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -90,8 +90,8 @@ begin
|
||||
return OLD;
|
||||
end; $$;
|
||||
|
||||
create trigger removeSepaMandateLegacyIdMapping
|
||||
create trigger delete_legacy_id_mapping_tf
|
||||
before delete on hs_office.sepamandate
|
||||
for each row
|
||||
execute procedure deleteSepaMandateLegacyIdMapping();
|
||||
execute procedure hs_office.sepamandate_delete_legacy_id_mapping_tf();
|
||||
--/
|
||||
|
@@ -8,7 +8,7 @@
|
||||
/*
|
||||
Creates a single sepaMandate test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficeSepaMandateTestData(
|
||||
create or replace procedure hs_office.sepamandate_create_test_data(
|
||||
forPartnerNumber numeric(5),
|
||||
forDebitorSuffix char(2),
|
||||
forIban varchar,
|
||||
@@ -45,9 +45,9 @@ do language plpgsql $$
|
||||
begin
|
||||
call base.defineContext('creating SEPA-mandate test-data', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN');
|
||||
|
||||
call createHsOfficeSepaMandateTestData(10001, '11', 'DE02120300000000202051', 'ref-10001-11');
|
||||
call createHsOfficeSepaMandateTestData(10002, '12', 'DE02100500000054540402', 'ref-10002-12');
|
||||
call createHsOfficeSepaMandateTestData(10003, '13', 'DE02300209000106531065', 'ref-10003-13');
|
||||
call hs_office.sepamandate_create_test_data(10001, '11', 'DE02120300000000202051', 'ref-10001-11');
|
||||
call hs_office.sepamandate_create_test_data(10002, '12', 'DE02100500000054540402', 'ref-10002-12');
|
||||
call hs_office.sepamandate_create_test_data(10003, '13', 'DE02300209000106531065', 'ref-10003-13');
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@@ -4,7 +4,7 @@
|
||||
--changeset michael.hoennig:hs-office-membership-MAIN-TABLE endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TYPE HsOfficeMembershipStatus AS ENUM (
|
||||
CREATE TYPE hs_office.HsOfficeMembershipStatus AS ENUM (
|
||||
'INVALID',
|
||||
'ACTIVE',
|
||||
'CANCELLED',
|
||||
@@ -15,7 +15,7 @@ CREATE TYPE HsOfficeMembershipStatus AS ENUM (
|
||||
'UNKNOWN'
|
||||
);
|
||||
|
||||
CREATE CAST (character varying as HsOfficeMembershipStatus) WITH INOUT AS IMPLICIT;
|
||||
CREATE CAST (character varying as hs_office.HsOfficeMembershipStatus) WITH INOUT AS IMPLICIT;
|
||||
|
||||
create table if not exists hs_office.membership
|
||||
(
|
||||
@@ -24,7 +24,7 @@ create table if not exists hs_office.membership
|
||||
partnerUuid uuid not null references hs_office.partner(uuid),
|
||||
memberNumberSuffix char(2) not null check (memberNumberSuffix::text ~ '^[0-9][0-9]$'),
|
||||
validity daterange not null,
|
||||
status HsOfficeMembershipStatus not null default 'ACTIVE',
|
||||
status hs_office.HsOfficeMembershipStatus not null default 'ACTIVE',
|
||||
membershipFeeBillable boolean not null default true,
|
||||
|
||||
UNIQUE(partnerUuid, memberNumberSuffix)
|
||||
|
@@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_office.membership');
|
||||
-- ============================================================================
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-membership-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRoleDescriptors('hsOfficeMembership', 'hs_office.membership');
|
||||
call rbac.generateRbacRoleDescriptors('hs_office.membership');
|
||||
--//
|
||||
|
||||
|
||||
@@ -44,25 +44,25 @@ begin
|
||||
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeMembershipOWNER(NEW),
|
||||
hs_office.membership_OWNER(NEW),
|
||||
subjectUuids => array[rbac.currentSubjectUuid()]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeMembershipADMIN(NEW),
|
||||
hs_office.membership_ADMIN(NEW),
|
||||
permissions => array['DELETE', 'UPDATE'],
|
||||
incomingSuperRoles => array[
|
||||
hsOfficeMembershipOWNER(NEW),
|
||||
hsOfficeRelationADMIN(newPartnerRel)]
|
||||
hs_office.membership_OWNER(NEW),
|
||||
hs_office.relation_ADMIN(newPartnerRel)]
|
||||
);
|
||||
|
||||
perform rbac.defineRoleWithGrants(
|
||||
hsOfficeMembershipAGENT(NEW),
|
||||
hs_office.membership_AGENT(NEW),
|
||||
permissions => array['SELECT'],
|
||||
incomingSuperRoles => array[
|
||||
hsOfficeMembershipADMIN(NEW),
|
||||
hsOfficeRelationAGENT(newPartnerRel)],
|
||||
outgoingSubRoles => array[hsOfficeRelationTENANT(newPartnerRel)]
|
||||
hs_office.membership_ADMIN(NEW),
|
||||
hs_office.relation_AGENT(newPartnerRel)],
|
||||
outgoingSubRoles => array[hs_office.relation_TENANT(newPartnerRel)]
|
||||
);
|
||||
|
||||
call rbac.leaveTriggerForObjectUuid(NEW.uuid);
|
||||
@@ -108,7 +108,7 @@ do language plpgsql $$
|
||||
LOOP
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(row.uuid, 'INSERT', 'hs_office.membership'),
|
||||
rbac.globalADMIN());
|
||||
rbac.global_ADMIN());
|
||||
END LOOP;
|
||||
end;
|
||||
$$;
|
||||
@@ -116,7 +116,7 @@ $$;
|
||||
/**
|
||||
Grants hs_office.membership INSERT permission to specified role of new global rows.
|
||||
*/
|
||||
create or replace function hs_office.new_membership_grants_insert_to_global_tf()
|
||||
create or replace function hs_office.membership_grants_insert_to_global_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -124,16 +124,16 @@ begin
|
||||
-- unconditional for all rows in that table
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.membership'),
|
||||
rbac.globalADMIN());
|
||||
rbac.global_ADMIN());
|
||||
-- end.
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger z_new_membership_grants_after_insert_tg
|
||||
-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger membership_z_grants_after_insert_tg
|
||||
after insert on rbac.global
|
||||
for each row
|
||||
execute procedure hs_office.new_membership_grants_insert_to_global_tf();
|
||||
execute procedure hs_office.membership_grants_insert_to_global_tf();
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
|
@@ -8,7 +8,7 @@
|
||||
/*
|
||||
Creates a single membership test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficeMembershipTestData(
|
||||
create or replace procedure hs_office.membership_create_test_data(
|
||||
forPartnerNumber numeric(5),
|
||||
newMemberNumberSuffix char(2) )
|
||||
language plpgsql as $$
|
||||
@@ -35,9 +35,9 @@ do language plpgsql $$
|
||||
begin
|
||||
call base.defineContext('creating Membership test-data', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN');
|
||||
|
||||
call createHsOfficeMembershipTestData(10001, '01');
|
||||
call createHsOfficeMembershipTestData(10002, '02');
|
||||
call createHsOfficeMembershipTestData(10003, '03');
|
||||
call hs_office.membership_create_test_data(10001, '01');
|
||||
call hs_office.membership_create_test_data(10002, '02');
|
||||
call hs_office.membership_create_test_data(10003, '03');
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@@ -4,20 +4,20 @@
|
||||
--changeset michael.hoennig:hs-office-coopshares-MAIN-TABLE endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TYPE HsOfficeCoopSharesTransactionType AS ENUM ('ADJUSTMENT', 'SUBSCRIPTION', 'CANCELLATION');
|
||||
CREATE TYPE hs_office.CoopSharesTransactionType AS ENUM ('ADJUSTMENT', 'SUBSCRIPTION', 'CANCELLATION');
|
||||
|
||||
CREATE CAST (character varying as HsOfficeCoopSharesTransactionType) WITH INOUT AS IMPLICIT;
|
||||
CREATE CAST (character varying as hs_office.CoopSharesTransactionType) WITH INOUT AS IMPLICIT;
|
||||
|
||||
create table if not exists hs_office.coopsharestransaction
|
||||
create table if not exists hs_office.coopsharetx
|
||||
(
|
||||
uuid uuid unique references rbac.object (uuid) initially deferred,
|
||||
version int not null default 0,
|
||||
membershipUuid uuid not null references hs_office.membership(uuid),
|
||||
transactionType HsOfficeCoopSharesTransactionType not null,
|
||||
transactionType hs_office.CoopSharesTransactionType not null,
|
||||
valueDate date not null,
|
||||
shareCount integer not null,
|
||||
reference varchar(48) not null,
|
||||
adjustedShareTxUuid uuid unique REFERENCES hs_office.coopsharestransaction(uuid) DEFERRABLE INITIALLY DEFERRED,
|
||||
adjustedShareTxUuid uuid unique REFERENCES hs_office.coopsharetx(uuid) DEFERRABLE INITIALLY DEFERRED,
|
||||
comment varchar(512)
|
||||
);
|
||||
--//
|
||||
@@ -26,7 +26,7 @@ create table if not exists hs_office.coopsharestransaction
|
||||
--changeset michael.hoennig:hs-office-coopshares-BUSINESS-RULES endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
alter table hs_office.coopsharestransaction
|
||||
alter table hs_office.coopsharetx
|
||||
add constraint reverse_entry_missing
|
||||
check ( transactionType = 'ADJUSTMENT' and adjustedShareTxUuid is not null
|
||||
or transactionType <> 'ADJUSTMENT' and adjustedShareTxUuid is null);
|
||||
@@ -36,7 +36,7 @@ alter table hs_office.coopsharestransaction
|
||||
--changeset michael.hoennig:hs-office-coopshares-SHARE-COUNT-CONSTRAINT endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
create or replace function checkSharesByMembershipUuid(forMembershipUuid UUID, newShareCount integer)
|
||||
create or replace function hs_office.coopsharestx_check_positive_total(forMembershipUuid UUID, newShareCount integer)
|
||||
returns boolean
|
||||
language plpgsql as $$
|
||||
declare
|
||||
@@ -44,7 +44,7 @@ declare
|
||||
totalShareCount integer;
|
||||
begin
|
||||
select sum(cst.shareCount)
|
||||
from hs_office.coopsharestransaction cst
|
||||
from hs_office.coopsharetx cst
|
||||
where cst.membershipUuid = forMembershipUuid
|
||||
into currentShareCount;
|
||||
totalShareCount := currentShareCount + newShareCount;
|
||||
@@ -54,9 +54,9 @@ begin
|
||||
return true;
|
||||
end; $$;
|
||||
|
||||
alter table hs_office.coopsharestransaction
|
||||
alter table hs_office.coopsharetx
|
||||
add constraint check_positive_total_shares_count
|
||||
check ( checkSharesByMembershipUuid(membershipUuid, shareCount) );
|
||||
check ( hs_office.coopsharestx_check_positive_total(membershipUuid, shareCount) );
|
||||
|
||||
--//
|
||||
|
||||
@@ -64,5 +64,5 @@ alter table hs_office.coopsharestransaction
|
||||
--changeset michael.hoennig:hs-office-coopshares-MAIN-TABLE-JOURNAL endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
call base.create_journal('hs_office.coopsharestransaction');
|
||||
call base.create_journal('hs_office.coopsharetx');
|
||||
--//
|
||||
|
@@ -3,29 +3,29 @@
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset RbacObjectGenerator:hs-office-coopsharestransaction-rbac-OBJECT endDelimiter:--//
|
||||
--changeset RbacObjectGenerator:hs-office-coopsharetx-rbac-OBJECT endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRelatedRbacObject('hs_office.coopsharestransaction');
|
||||
call rbac.generateRelatedRbacObject('hs_office.coopsharetx');
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-coopsharestransaction-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-coopsharetx-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRoleDescriptors('hsOfficeCoopSharesTransaction', 'hs_office.coopsharestransaction');
|
||||
call rbac.generateRbacRoleDescriptors('hs_office.coopsharetx');
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset RolesGrantsAndPermissionsGenerator:hs-office-coopsharestransaction-rbac-insert-trigger endDelimiter:--//
|
||||
--changeset RolesGrantsAndPermissionsGenerator:hs-office-coopsharetx-rbac-insert-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Creates the roles, grants and permission for the AFTER INSERT TRIGGER.
|
||||
*/
|
||||
|
||||
create or replace procedure hs_office.coopsharestransaction_build_rbac_system(
|
||||
NEW hs_office.coopsharestransaction
|
||||
create or replace procedure hs_office.coopsharetx_build_rbac_system(
|
||||
NEW hs_office.coopsharetx
|
||||
)
|
||||
language plpgsql as $$
|
||||
|
||||
@@ -38,114 +38,114 @@ begin
|
||||
SELECT * FROM hs_office.membership WHERE uuid = NEW.membershipUuid INTO newMembership;
|
||||
assert newMembership.uuid is not null, format('newMembership must not be null for NEW.membershipUuid = %s', NEW.membershipUuid);
|
||||
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'SELECT'), hsOfficeMembershipAGENT(newMembership));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'UPDATE'), hsOfficeMembershipADMIN(newMembership));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'SELECT'), hs_office.membership_AGENT(newMembership));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'UPDATE'), hs_office.membership_ADMIN(newMembership));
|
||||
|
||||
call rbac.leaveTriggerForObjectUuid(NEW.uuid);
|
||||
end; $$;
|
||||
|
||||
/*
|
||||
AFTER INSERT TRIGGER to create the role+grant structure for a new hs_office.coopsharestransaction row.
|
||||
AFTER INSERT TRIGGER to create the role+grant structure for a new hs_office.coopsharetx row.
|
||||
*/
|
||||
|
||||
create or replace function hs_office.coopsharestransaction_build_rbac_system_after_insert_tf()
|
||||
create or replace function hs_office.coopsharetx_build_rbac_system_after_insert_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
begin
|
||||
call hs_office.coopsharestransaction_build_rbac_system(NEW);
|
||||
call hs_office.coopsharetx_build_rbac_system(NEW);
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger build_rbac_system_after_insert_tg
|
||||
after insert on hs_office.coopsharestransaction
|
||||
after insert on hs_office.coopsharetx
|
||||
for each row
|
||||
execute procedure hs_office.coopsharestransaction_build_rbac_system_after_insert_tf();
|
||||
execute procedure hs_office.coopsharetx_build_rbac_system_after_insert_tf();
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset InsertTriggerGenerator:hs-office-coopsharestransaction-rbac-GRANTING-INSERT-PERMISSION endDelimiter:--//
|
||||
--changeset InsertTriggerGenerator:hs-office-coopsharetx-rbac-GRANTING-INSERT-PERMISSION endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
-- granting INSERT permission to hs_office.membership ----------------------------
|
||||
|
||||
/*
|
||||
Grants INSERT INTO hs_office.coopsharestransaction permissions to specified role of pre-existing hs_office.membership rows.
|
||||
Grants INSERT INTO hs_office.coopsharetx permissions to specified role of pre-existing hs_office.membership rows.
|
||||
*/
|
||||
do language plpgsql $$
|
||||
declare
|
||||
row hs_office.membership;
|
||||
begin
|
||||
call base.defineContext('create INSERT INTO hs_office.coopsharestransaction permissions for pre-exising hs_office.membership rows');
|
||||
call base.defineContext('create INSERT INTO hs_office.coopsharetx permissions for pre-exising hs_office.membership rows');
|
||||
|
||||
FOR row IN SELECT * FROM hs_office.membership
|
||||
-- unconditional for all rows in that table
|
||||
LOOP
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(row.uuid, 'INSERT', 'hs_office.coopsharestransaction'),
|
||||
hsOfficeMembershipADMIN(row));
|
||||
rbac.createPermission(row.uuid, 'INSERT', 'hs_office.coopsharetx'),
|
||||
hs_office.membership_ADMIN(row));
|
||||
END LOOP;
|
||||
end;
|
||||
$$;
|
||||
|
||||
/**
|
||||
Grants hs_office.coopsharestransaction INSERT permission to specified role of new membership rows.
|
||||
Grants hs_office.coopsharetx INSERT permission to specified role of new membership rows.
|
||||
*/
|
||||
create or replace function hs_office.new_coopsharetx_grants_insert_to_membership_tf()
|
||||
create or replace function hs_office.coopsharetx_grants_insert_to_membership_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
begin
|
||||
-- unconditional for all rows in that table
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.coopsharestransaction'),
|
||||
hsOfficeMembershipADMIN(NEW));
|
||||
rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.coopsharetx'),
|
||||
hs_office.membership_ADMIN(NEW));
|
||||
-- end.
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger z_new_coopsharestransaction_grants_after_insert_tg
|
||||
-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger coopsharetx_z_grants_after_insert_tg
|
||||
after insert on hs_office.membership
|
||||
for each row
|
||||
execute procedure hs_office.new_coopsharetx_grants_insert_to_membership_tf();
|
||||
execute procedure hs_office.coopsharetx_grants_insert_to_membership_tf();
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset InsertTriggerGenerator:hs-office-coopsharestransaction-rbac-CHECKING-INSERT-PERMISSION endDelimiter:--//
|
||||
--changeset InsertTriggerGenerator:hs-office-coopsharetx-rbac-CHECKING-INSERT-PERMISSION endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
Checks if the user respectively the assumed roles are allowed to insert a row to hs_office.coopsharestransaction.
|
||||
Checks if the user respectively the assumed roles are allowed to insert a row to hs_office.coopsharetx.
|
||||
*/
|
||||
create or replace function hs_office.coopsharestransaction_insert_permission_check_tf()
|
||||
create or replace function hs_office.coopsharetx_insert_permission_check_tf()
|
||||
returns trigger
|
||||
language plpgsql as $$
|
||||
declare
|
||||
superObjectUuid uuid;
|
||||
begin
|
||||
-- check INSERT permission via direct foreign key: NEW.membershipUuid
|
||||
if rbac.hasInsertPermission(NEW.membershipUuid, 'hs_office.coopsharestransaction') then
|
||||
if rbac.hasInsertPermission(NEW.membershipUuid, 'hs_office.coopsharetx') then
|
||||
return NEW;
|
||||
end if;
|
||||
|
||||
raise exception '[403] insert into hs_office.coopsharestransaction values(%) not allowed for current subjects % (%)',
|
||||
raise exception '[403] insert into hs_office.coopsharetx values(%) not allowed for current subjects % (%)',
|
||||
NEW, base.currentSubjects(), rbac.currentSubjectOrAssumedRolesUuids();
|
||||
end; $$;
|
||||
|
||||
create trigger coopsharestransaction_insert_permission_check_tg
|
||||
before insert on hs_office.coopsharestransaction
|
||||
create trigger coopsharetx_insert_permission_check_tg
|
||||
before insert on hs_office.coopsharetx
|
||||
for each row
|
||||
execute procedure hs_office.coopsharestransaction_insert_permission_check_tf();
|
||||
execute procedure hs_office.coopsharetx_insert_permission_check_tf();
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset RbacIdentityViewGenerator:hs-office-coopsharestransaction-rbac-IDENTITY-VIEW endDelimiter:--//
|
||||
--changeset RbacIdentityViewGenerator:hs-office-coopsharetx-rbac-IDENTITY-VIEW endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
call rbac.generateRbacIdentityViewFromProjection('hs_office.coopsharestransaction',
|
||||
call rbac.generateRbacIdentityViewFromProjection('hs_office.coopsharetx',
|
||||
$idName$
|
||||
reference
|
||||
$idName$);
|
||||
@@ -153,9 +153,9 @@ call rbac.generateRbacIdentityViewFromProjection('hs_office.coopsharestransactio
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset RbacRestrictedViewGenerator:hs-office-coopsharestransaction-rbac-RESTRICTED-VIEW endDelimiter:--//
|
||||
--changeset RbacRestrictedViewGenerator:hs-office-coopsharetx-rbac-RESTRICTED-VIEW endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRestrictedView('hs_office.coopsharestransaction',
|
||||
call rbac.generateRbacRestrictedView('hs_office.coopsharetx',
|
||||
$orderBy$
|
||||
reference
|
||||
$orderBy$,
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
CREATE TABLE hs_office.coopsharestransaction_legacy_id
|
||||
(
|
||||
uuid uuid NOT NULL REFERENCES hs_office.coopsharestransaction(uuid),
|
||||
uuid uuid NOT NULL REFERENCES hs_office.coopsharetx(uuid),
|
||||
member_share_id integer NOT NULL
|
||||
);
|
||||
--//
|
||||
@@ -42,14 +42,14 @@ ALTER TABLE hs_office.coopsharestransaction_legacy_id
|
||||
|
||||
CALL base.defineContext('schema-migration');
|
||||
INSERT INTO hs_office.coopsharestransaction_legacy_id(uuid, member_share_id)
|
||||
SELECT uuid, nextVal('hs_office.coopsharestransaction_legacy_id_seq') FROM hs_office.coopsharestransaction;
|
||||
SELECT uuid, nextVal('hs_office.coopsharestransaction_legacy_id_seq') FROM hs_office.coopsharetx;
|
||||
--/
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-coopShares-MIGRATION-insert-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
create or replace function insertCoopSharesLegacyIdMapping()
|
||||
create or replace function hs_office.coopsharetx_insert_legacy_id_mapping_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -64,17 +64,17 @@ begin
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger createCoopSharesLegacyIdMapping
|
||||
after insert on hs_office.coopsharestransaction
|
||||
create trigger insert_legacy_id_mapping_tg
|
||||
after insert on hs_office.coopsharetx
|
||||
for each row
|
||||
execute procedure insertCoopSharesLegacyIdMapping();
|
||||
execute procedure hs_office.coopsharetx_insert_legacy_id_mapping_tf();
|
||||
--/
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-coopShares-MIGRATION-delete-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
create or replace function deleteCoopSharesLegacyIdMapping()
|
||||
create or replace function hs_office.coopsharetx_delete_legacy_id_mapping_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -89,8 +89,8 @@ begin
|
||||
return OLD;
|
||||
end; $$;
|
||||
|
||||
create trigger removeCoopSharesLegacyIdMapping
|
||||
before delete on hs_office.coopsharestransaction
|
||||
create trigger delete_legacy_id_mapping_tg
|
||||
before delete on hs_office.coopsharetx
|
||||
for each row
|
||||
execute procedure deleteCoopSharesLegacyIdMapping();
|
||||
execute procedure hs_office.coopsharetx_delete_legacy_id_mapping_tf();
|
||||
--/
|
||||
|
@@ -8,7 +8,7 @@
|
||||
/*
|
||||
Creates a single coopSharesTransaction test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficeCoopSharesTransactionTestData(
|
||||
create or replace procedure hs_office.coopsharetx_create_test_data(
|
||||
givenPartnerNumber numeric,
|
||||
givenMemberNumberSuffix char(2)
|
||||
)
|
||||
@@ -27,7 +27,7 @@ begin
|
||||
raise notice 'creating test coopSharesTransaction: %', givenPartnerNumber::text || givenMemberNumberSuffix;
|
||||
subscriptionEntryUuid := uuid_generate_v4();
|
||||
insert
|
||||
into hs_office.coopsharestransaction(uuid, membershipuuid, transactiontype, valuedate, sharecount, reference, comment, adjustedShareTxUuid)
|
||||
into hs_office.coopsharetx(uuid, membershipuuid, transactiontype, valuedate, sharecount, reference, comment, adjustedShareTxUuid)
|
||||
values
|
||||
(uuid_generate_v4(), membership.uuid, 'SUBSCRIPTION', '2010-03-15', 4, 'ref '||givenPartnerNumber::text || givenMemberNumberSuffix||'-1', 'initial subscription', null),
|
||||
(uuid_generate_v4(), membership.uuid, 'CANCELLATION', '2021-09-01', -2, 'ref '||givenPartnerNumber::text || givenMemberNumberSuffix||'-2', 'cancelling some', null),
|
||||
@@ -46,8 +46,8 @@ do language plpgsql $$
|
||||
call base.defineContext('creating coopSharesTransaction test-data');
|
||||
SET CONSTRAINTS ALL DEFERRED;
|
||||
|
||||
call createHsOfficeCoopSharesTransactionTestData(10001, '01');
|
||||
call createHsOfficeCoopSharesTransactionTestData(10002, '02');
|
||||
call createHsOfficeCoopSharesTransactionTestData(10003, '03');
|
||||
call hs_office.coopsharetx_create_test_data(10001, '01');
|
||||
call hs_office.coopsharetx_create_test_data(10002, '02');
|
||||
call hs_office.coopsharetx_create_test_data(10003, '03');
|
||||
end;
|
||||
$$;
|
||||
|
@@ -4,7 +4,7 @@
|
||||
--changeset michael.hoennig:hs-office-coopassets-MAIN-TABLE endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TYPE HsOfficeCoopAssetsTransactionType AS ENUM ('ADJUSTMENT',
|
||||
CREATE TYPE hs_office.CoopAssetsTransactionType AS ENUM ('ADJUSTMENT',
|
||||
'DEPOSIT',
|
||||
'DISBURSAL',
|
||||
'TRANSFER',
|
||||
@@ -13,18 +13,18 @@ CREATE TYPE HsOfficeCoopAssetsTransactionType AS ENUM ('ADJUSTMENT',
|
||||
'LOSS',
|
||||
'LIMITATION');
|
||||
|
||||
CREATE CAST (character varying as HsOfficeCoopAssetsTransactionType) WITH INOUT AS IMPLICIT;
|
||||
CREATE CAST (character varying as hs_office.CoopAssetsTransactionType) WITH INOUT AS IMPLICIT;
|
||||
|
||||
create table if not exists hs_office.coopassetstransaction
|
||||
create table if not exists hs_office.coopassettx
|
||||
(
|
||||
uuid uuid unique references rbac.object (uuid) initially deferred,
|
||||
version int not null default 0,
|
||||
membershipUuid uuid not null references hs_office.membership(uuid),
|
||||
transactionType HsOfficeCoopAssetsTransactionType not null,
|
||||
transactionType hs_office.CoopAssetsTransactionType not null,
|
||||
valueDate date not null,
|
||||
assetValue money not null,
|
||||
reference varchar(48) not null,
|
||||
adjustedAssetTxUuid uuid unique REFERENCES hs_office.coopassetstransaction(uuid) DEFERRABLE INITIALLY DEFERRED,
|
||||
adjustedAssetTxUuid uuid unique REFERENCES hs_office.coopassettx(uuid) DEFERRABLE INITIALLY DEFERRED,
|
||||
comment varchar(512)
|
||||
);
|
||||
--//
|
||||
@@ -34,7 +34,7 @@ create table if not exists hs_office.coopassetstransaction
|
||||
--changeset michael.hoennig:hs-office-coopassets-BUSINESS-RULES endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
alter table hs_office.coopassetstransaction
|
||||
alter table hs_office.coopassettx
|
||||
add constraint reverse_entry_missing
|
||||
check ( transactionType = 'ADJUSTMENT' and adjustedAssetTxUuid is not null
|
||||
or transactionType <> 'ADJUSTMENT' and adjustedAssetTxUuid is null);
|
||||
@@ -44,7 +44,7 @@ alter table hs_office.coopassetstransaction
|
||||
--changeset michael.hoennig:hs-office-coopassets-ASSET-VALUE-CONSTRAINT endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
create or replace function checkAssetsByMembershipUuid(forMembershipUuid UUID, newAssetValue money)
|
||||
create or replace function hs_office.coopassetstx_check_positive_total(forMembershipUuid UUID, newAssetValue money)
|
||||
returns boolean
|
||||
language plpgsql as $$
|
||||
declare
|
||||
@@ -52,7 +52,7 @@ declare
|
||||
totalAssetValue money;
|
||||
begin
|
||||
select sum(cat.assetValue)
|
||||
from hs_office.coopassetstransaction cat
|
||||
from hs_office.coopassettx cat
|
||||
where cat.membershipUuid = forMembershipUuid
|
||||
into currentAssetValue;
|
||||
totalAssetValue := currentAssetValue + newAssetValue;
|
||||
@@ -62,9 +62,9 @@ begin
|
||||
return true;
|
||||
end; $$;
|
||||
|
||||
alter table hs_office.coopassetstransaction
|
||||
alter table hs_office.coopassettx
|
||||
add constraint check_positive_total
|
||||
check ( checkAssetsByMembershipUuid(membershipUuid, assetValue) );
|
||||
check ( hs_office.coopassetstx_check_positive_total(membershipUuid, assetValue) );
|
||||
--//
|
||||
|
||||
|
||||
@@ -72,5 +72,5 @@ alter table hs_office.coopassetstransaction
|
||||
--changeset michael.hoennig:hs-office-coopassets-MAIN-TABLE-JOURNAL endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
call base.create_journal('hs_office.coopassetstransaction');
|
||||
call base.create_journal('hs_office.coopassettx');
|
||||
--//
|
||||
|
@@ -3,29 +3,29 @@
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset RbacObjectGenerator:hs-office-coopassetstransaction-rbac-OBJECT endDelimiter:--//
|
||||
--changeset RbacObjectGenerator:hs-office-coopassettx-rbac-OBJECT endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRelatedRbacObject('hs_office.coopassetstransaction');
|
||||
call rbac.generateRelatedRbacObject('hs_office.coopassettx');
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-coopassetstransaction-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
--changeset RbacRoleDescriptorsGenerator:hs-office-coopassettx-rbac-ROLE-DESCRIPTORS endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRoleDescriptors('hsOfficeCoopAssetsTransaction', 'hs_office.coopassetstransaction');
|
||||
call rbac.generateRbacRoleDescriptors('hs_office.coopassettx');
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset RolesGrantsAndPermissionsGenerator:hs-office-coopassetstransaction-rbac-insert-trigger endDelimiter:--//
|
||||
--changeset RolesGrantsAndPermissionsGenerator:hs-office-coopassettx-rbac-insert-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Creates the roles, grants and permission for the AFTER INSERT TRIGGER.
|
||||
*/
|
||||
|
||||
create or replace procedure hs_office.coopassetstransaction_build_rbac_system(
|
||||
NEW hs_office.coopassetstransaction
|
||||
create or replace procedure hs_office.coopassettx_build_rbac_system(
|
||||
NEW hs_office.coopassettx
|
||||
)
|
||||
language plpgsql as $$
|
||||
|
||||
@@ -38,114 +38,114 @@ begin
|
||||
SELECT * FROM hs_office.membership WHERE uuid = NEW.membershipUuid INTO newMembership;
|
||||
assert newMembership.uuid is not null, format('newMembership must not be null for NEW.membershipUuid = %s', NEW.membershipUuid);
|
||||
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'SELECT'), hsOfficeMembershipAGENT(newMembership));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'UPDATE'), hsOfficeMembershipADMIN(newMembership));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'SELECT'), hs_office.membership_AGENT(newMembership));
|
||||
call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'UPDATE'), hs_office.membership_ADMIN(newMembership));
|
||||
|
||||
call rbac.leaveTriggerForObjectUuid(NEW.uuid);
|
||||
end; $$;
|
||||
|
||||
/*
|
||||
AFTER INSERT TRIGGER to create the role+grant structure for a new hs_office.coopassetstransaction row.
|
||||
AFTER INSERT TRIGGER to create the role+grant structure for a new hs_office.coopassettx row.
|
||||
*/
|
||||
|
||||
create or replace function hs_office.coopassetstransaction_build_rbac_system_after_insert_tf()
|
||||
create or replace function hs_office.coopassettx_build_rbac_system_after_insert_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
begin
|
||||
call hs_office.coopassetstransaction_build_rbac_system(NEW);
|
||||
call hs_office.coopassettx_build_rbac_system(NEW);
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger build_rbac_system_after_insert_tg
|
||||
after insert on hs_office.coopassetstransaction
|
||||
after insert on hs_office.coopassettx
|
||||
for each row
|
||||
execute procedure hs_office.coopassetstransaction_build_rbac_system_after_insert_tf();
|
||||
execute procedure hs_office.coopassettx_build_rbac_system_after_insert_tf();
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset InsertTriggerGenerator:hs-office-coopassetstransaction-rbac-GRANTING-INSERT-PERMISSION endDelimiter:--//
|
||||
--changeset InsertTriggerGenerator:hs-office-coopassettx-rbac-GRANTING-INSERT-PERMISSION endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
-- granting INSERT permission to hs_office.membership ----------------------------
|
||||
|
||||
/*
|
||||
Grants INSERT INTO hs_office.coopassetstransaction permissions to specified role of pre-existing hs_office.membership rows.
|
||||
Grants INSERT INTO hs_office.coopassettx permissions to specified role of pre-existing hs_office.membership rows.
|
||||
*/
|
||||
do language plpgsql $$
|
||||
declare
|
||||
row hs_office.membership;
|
||||
begin
|
||||
call base.defineContext('create INSERT INTO hs_office.coopassetstransaction permissions for pre-exising hs_office.membership rows');
|
||||
call base.defineContext('create INSERT INTO hs_office.coopassettx permissions for pre-exising hs_office.membership rows');
|
||||
|
||||
FOR row IN SELECT * FROM hs_office.membership
|
||||
-- unconditional for all rows in that table
|
||||
LOOP
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(row.uuid, 'INSERT', 'hs_office.coopassetstransaction'),
|
||||
hsOfficeMembershipADMIN(row));
|
||||
rbac.createPermission(row.uuid, 'INSERT', 'hs_office.coopassettx'),
|
||||
hs_office.membership_ADMIN(row));
|
||||
END LOOP;
|
||||
end;
|
||||
$$;
|
||||
|
||||
/**
|
||||
Grants hs_office.coopassetstransaction INSERT permission to specified role of new membership rows.
|
||||
Grants hs_office.coopassettx INSERT permission to specified role of new membership rows.
|
||||
*/
|
||||
create or replace function hs_office.new_coopassettx_grants_insert_to_membership_tf()
|
||||
create or replace function hs_office.coopassettx_grants_insert_to_membership_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
begin
|
||||
-- unconditional for all rows in that table
|
||||
call rbac.grantPermissionToRole(
|
||||
rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.coopassetstransaction'),
|
||||
hsOfficeMembershipADMIN(NEW));
|
||||
rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.coopassettx'),
|
||||
hs_office.membership_ADMIN(NEW));
|
||||
-- end.
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger z_new_coopassetstransaction_grants_after_insert_tg
|
||||
-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger coopassettx_z_grants_after_insert_tg
|
||||
after insert on hs_office.membership
|
||||
for each row
|
||||
execute procedure hs_office.new_coopassettx_grants_insert_to_membership_tf();
|
||||
execute procedure hs_office.coopassettx_grants_insert_to_membership_tf();
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset InsertTriggerGenerator:hs-office-coopassetstransaction-rbac-CHECKING-INSERT-PERMISSION endDelimiter:--//
|
||||
--changeset InsertTriggerGenerator:hs-office-coopassettx-rbac-CHECKING-INSERT-PERMISSION endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
Checks if the user respectively the assumed roles are allowed to insert a row to hs_office.coopassetstransaction.
|
||||
Checks if the user respectively the assumed roles are allowed to insert a row to hs_office.coopassettx.
|
||||
*/
|
||||
create or replace function hs_office.coopassetstransaction_insert_permission_check_tf()
|
||||
create or replace function hs_office.coopassettx_insert_permission_check_tf()
|
||||
returns trigger
|
||||
language plpgsql as $$
|
||||
declare
|
||||
superObjectUuid uuid;
|
||||
begin
|
||||
-- check INSERT permission via direct foreign key: NEW.membershipUuid
|
||||
if rbac.hasInsertPermission(NEW.membershipUuid, 'hs_office.coopassetstransaction') then
|
||||
if rbac.hasInsertPermission(NEW.membershipUuid, 'hs_office.coopassettx') then
|
||||
return NEW;
|
||||
end if;
|
||||
|
||||
raise exception '[403] insert into hs_office.coopassetstransaction values(%) not allowed for current subjects % (%)',
|
||||
raise exception '[403] insert into hs_office.coopassettx values(%) not allowed for current subjects % (%)',
|
||||
NEW, base.currentSubjects(), rbac.currentSubjectOrAssumedRolesUuids();
|
||||
end; $$;
|
||||
|
||||
create trigger coopassetstransaction_insert_permission_check_tg
|
||||
before insert on hs_office.coopassetstransaction
|
||||
create trigger coopassettx_insert_permission_check_tg
|
||||
before insert on hs_office.coopassettx
|
||||
for each row
|
||||
execute procedure hs_office.coopassetstransaction_insert_permission_check_tf();
|
||||
execute procedure hs_office.coopassettx_insert_permission_check_tf();
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset RbacIdentityViewGenerator:hs-office-coopassetstransaction-rbac-IDENTITY-VIEW endDelimiter:--//
|
||||
--changeset RbacIdentityViewGenerator:hs-office-coopassettx-rbac-IDENTITY-VIEW endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
call rbac.generateRbacIdentityViewFromProjection('hs_office.coopassetstransaction',
|
||||
call rbac.generateRbacIdentityViewFromProjection('hs_office.coopassettx',
|
||||
$idName$
|
||||
reference
|
||||
$idName$);
|
||||
@@ -153,9 +153,9 @@ call rbac.generateRbacIdentityViewFromProjection('hs_office.coopassetstransactio
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset RbacRestrictedViewGenerator:hs-office-coopassetstransaction-rbac-RESTRICTED-VIEW endDelimiter:--//
|
||||
--changeset RbacRestrictedViewGenerator:hs-office-coopassettx-rbac-RESTRICTED-VIEW endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call rbac.generateRbacRestrictedView('hs_office.coopassetstransaction',
|
||||
call rbac.generateRbacRestrictedView('hs_office.coopassettx',
|
||||
$orderBy$
|
||||
reference
|
||||
$orderBy$,
|
||||
|
@@ -7,9 +7,9 @@
|
||||
--changeset michael.hoennig:hs-office-coopassets-MIGRATION-mapping endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TABLE hs_office.coopassetstransaction_legacy_id
|
||||
CREATE TABLE hs_office.coopassettx_legacy_id
|
||||
(
|
||||
uuid uuid NOT NULL REFERENCES hs_office.coopassetstransaction(uuid),
|
||||
uuid uuid NOT NULL REFERENCES hs_office.coopassettx(uuid),
|
||||
member_asset_id integer NOT NULL
|
||||
);
|
||||
--//
|
||||
@@ -19,10 +19,10 @@ CREATE TABLE hs_office.coopassetstransaction_legacy_id
|
||||
--changeset michael.hoennig:hs-office-coopassets-MIGRATION-sequence endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE SEQUENCE IF NOT EXISTS hs_office.coopassetstransaction_legacy_id_seq
|
||||
CREATE SEQUENCE IF NOT EXISTS hs_office.coopassettx_legacy_id_seq
|
||||
AS integer
|
||||
START 1000000000
|
||||
OWNED BY hs_office.coopassetstransaction_legacy_id.member_asset_id;
|
||||
OWNED BY hs_office.coopassettx_legacy_id.member_asset_id;
|
||||
--//
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ CREATE SEQUENCE IF NOT EXISTS hs_office.coopassetstransaction_legacy_id_seq
|
||||
--changeset michael.hoennig:hs-office-coopassets-MIGRATION-default endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
ALTER TABLE hs_office.coopassetstransaction_legacy_id
|
||||
ALTER TABLE hs_office.coopassettx_legacy_id
|
||||
ALTER COLUMN member_asset_id
|
||||
SET DEFAULT nextVal('hs_office.coopassetstransaction_legacy_id_seq');
|
||||
SET DEFAULT nextVal('hs_office.coopassettx_legacy_id_seq');
|
||||
--/
|
||||
|
||||
|
||||
@@ -41,15 +41,15 @@ ALTER TABLE hs_office.coopassetstransaction_legacy_id
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CALL base.defineContext('schema-migration');
|
||||
INSERT INTO hs_office.coopassetstransaction_legacy_id(uuid, member_asset_id)
|
||||
SELECT uuid, nextVal('hs_office.coopassetstransaction_legacy_id_seq') FROM hs_office.coopassetstransaction;
|
||||
INSERT INTO hs_office.coopassettx_legacy_id(uuid, member_asset_id)
|
||||
SELECT uuid, nextVal('hs_office.coopassettx_legacy_id_seq') FROM hs_office.coopassettx;
|
||||
--/
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-coopAssets-MIGRATION-insert-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
create or replace function insertCoopAssetsLegacyIdMapping()
|
||||
create or replace function hs_office.coopassettx_insert_legacy_id_mapping_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -58,23 +58,23 @@ begin
|
||||
raise exception 'invalid usage of trigger';
|
||||
end if;
|
||||
|
||||
INSERT INTO hs_office.coopassetstransaction_legacy_id VALUES
|
||||
(NEW.uuid, nextVal('hs_office.coopassetstransaction_legacy_id_seq'));
|
||||
INSERT INTO hs_office.coopassettx_legacy_id VALUES
|
||||
(NEW.uuid, nextVal('hs_office.coopassettx_legacy_id_seq'));
|
||||
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger createCoopAssetsLegacyIdMapping
|
||||
after insert on hs_office.coopassetstransaction
|
||||
create trigger insert_legacy_id_mapping_tg
|
||||
after insert on hs_office.coopassettx
|
||||
for each row
|
||||
execute procedure insertCoopAssetsLegacyIdMapping();
|
||||
execute procedure hs_office.coopassettx_insert_legacy_id_mapping_tf();
|
||||
--/
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset michael.hoennig:hs-office-coopAssets-MIGRATION-delete-trigger endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
create or replace function deleteCoopAssetsLegacyIdMapping()
|
||||
create or replace function hs_office.coopassettx_delete_legacy_id_mapping_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
@@ -83,14 +83,14 @@ begin
|
||||
raise exception 'invalid usage of trigger';
|
||||
end if;
|
||||
|
||||
DELETE FROM hs_office.coopassetstransaction_legacy_id
|
||||
DELETE FROM hs_office.coopassettx_legacy_id
|
||||
WHERE uuid = OLD.uuid;
|
||||
|
||||
return OLD;
|
||||
end; $$;
|
||||
|
||||
create trigger removeCoopAssetsLegacyIdMapping
|
||||
before delete on hs_office.coopassetstransaction
|
||||
create trigger delete_legacy_id_mapping_tg
|
||||
before delete on hs_office.coopassettx
|
||||
for each row
|
||||
execute procedure deleteCoopAssetsLegacyIdMapping();
|
||||
execute procedure hs_office.coopassettx_delete_legacy_id_mapping_tf();
|
||||
--/
|
||||
|
@@ -8,7 +8,7 @@
|
||||
/*
|
||||
Creates a single coopAssetsTransaction test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficeCoopAssetsTransactionTestData(
|
||||
create or replace procedure hs_office.coopassettx_create_test_data(
|
||||
givenPartnerNumber numeric,
|
||||
givenMemberNumberSuffix char(2)
|
||||
)
|
||||
@@ -27,7 +27,7 @@ begin
|
||||
raise notice 'creating test coopAssetsTransaction: %', givenPartnerNumber || givenMemberNumberSuffix;
|
||||
lossEntryUuid := uuid_generate_v4();
|
||||
insert
|
||||
into hs_office.coopassetstransaction(uuid, membershipuuid, transactiontype, valuedate, assetvalue, reference, comment, adjustedAssetTxUuid)
|
||||
into hs_office.coopassettx(uuid, membershipuuid, transactiontype, valuedate, assetvalue, reference, comment, adjustedAssetTxUuid)
|
||||
values
|
||||
(uuid_generate_v4(), membership.uuid, 'DEPOSIT', '2010-03-15', 320.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-1', 'initial deposit', null),
|
||||
(uuid_generate_v4(), membership.uuid, 'DISBURSAL', '2021-09-01', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-2', 'partial disbursal', null),
|
||||
@@ -46,8 +46,8 @@ do language plpgsql $$
|
||||
call base.defineContext('creating coopAssetsTransaction test-data');
|
||||
SET CONSTRAINTS ALL DEFERRED;
|
||||
|
||||
call createHsOfficeCoopAssetsTransactionTestData(10001, '01');
|
||||
call createHsOfficeCoopAssetsTransactionTestData(10002, '02');
|
||||
call createHsOfficeCoopAssetsTransactionTestData(10003, '03');
|
||||
call hs_office.coopassettx_create_test_data(10001, '01');
|
||||
call hs_office.coopassettx_create_test_data(10002, '02');
|
||||
call hs_office.coopassettx_create_test_data(10003, '03');
|
||||
end;
|
||||
$$;
|
||||
|
Reference in New Issue
Block a user