From a43088cb81297274235c6261b3a02d6567dde888 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 18 Sep 2024 13:28:36 +0200 Subject: [PATCH 01/14] introduce separate database-schema for hs_booking --- doc/rbac-performance-analysis.md | 8 +- sql/historization.sql | 8 +- ...e-cte-experiments-for-accessible-uuids.sql | 12 +-- .../debitor/HsBookingDebitorEntity.java | 2 +- .../booking/item/HsBookingItemRbacEntity.java | 2 +- .../booking/item/HsBookingItemRealEntity.java | 2 +- .../hs/booking/project/HsBookingProject.java | 2 +- .../project/HsBookingProjectRbacEntity.java | 4 +- .../project/HsBookingProjectRealEntity.java | 2 +- .../asset/HsHostingAssetRbacRepository.java | 4 +- .../asset/HsHostingAssetRealRepository.java | 4 +- .../hsadminng/rbac/generator/RbacView.java | 2 +- .../0-base/011-table-schema-and-name.sql | 3 + .../db/changelog/0-base/030-historization.sql | 15 ++- .../6-hs-booking/600-hs-booking-schema.sql | 8 ++ .../6100-hs-booking-debitor.sql | 2 +- .../6200-hs-booking-project.sql | 6 +- .../6203-hs-booking-project-rbac.sql | 56 +++++----- .../6208-hs-booking-project-test-data.sql | 4 +- .../630-booking-item/6300-hs-booking-item.sql | 12 +-- .../6303-hs-booking-item-rbac.sql | 100 +++++++++--------- .../6308-hs-booking-item-test-data.sql | 8 +- .../7010-hs-hosting-asset.sql | 4 +- .../7013-hs-hosting-asset-rbac.sql | 4 +- .../7018-hs-hosting-asset-test-data.sql | 20 ++-- .../changelog/9-hs-global/9000-statistics.sql | 4 +- .../db/changelog/db.changelog-master.yaml | 2 + ...HsBookingItemControllerAcceptanceTest.java | 4 +- ...sBookingItemRepositoryIntegrationTest.java | 60 +++++------ ...ookingProjectControllerAcceptanceTest.java | 2 +- ...okingProjectRepositoryIntegrationTest.java | 48 ++++----- ...sHostingAssetControllerAcceptanceTest.java | 2 +- ...HostingAssetRepositoryIntegrationTest.java | 14 +-- .../hsadminng/hs/migration/CsvDataImport.java | 8 +- .../hs/migration/ImportHostingAssets.java | 4 +- ...fficeDebitorRepositoryIntegrationTest.java | 2 +- .../test/ContextBasedTestWithCleanup.java | 2 +- 37 files changed, 229 insertions(+), 217 deletions(-) create mode 100644 src/main/resources/db/changelog/6-hs-booking/600-hs-booking-schema.sql diff --git a/doc/rbac-performance-analysis.md b/doc/rbac-performance-analysis.md index a37f24db..bc09371e 100644 --- a/doc/rbac-performance-analysis.md +++ b/doc/rbac-performance-analysis.md @@ -283,8 +283,8 @@ At this point, the import took 21mins with these statistics: | call buildRbacSystemForHsOfficeRelation(NEW) | 1276 | 0 | 8 | | with recursive grants as ( select descendantUuid, ascendantUuid from RbacGrants where descendantUuid = grantedId union all select ""grant"".descendantUuid, ""grant"".ascendantUuid from RbacGrants ""grant"" inner join grants recur on recur.ascendantUuid = ""grant"".descendantUuid ) select exists ( select $3 from grants where ascendantUuid = any(granteeIds) ) or grantedId = any(granteeIds) | 47540 | 0 | 0 | | insert into RbacGrants (grantedByTriggerOf, ascendantuuid, descendantUuid, assumed) values (currentTriggerObjectUuid(), superRoleId, subRoleId, doAssume) on conflict do nothing" | 40472 | 0 | 0 | -| insert into public.hs_booking_item_rv (caption,parentitemuuid,projectuuid,resources,type,validity,version,uuid) values ($1,$2,$3,$4,$5,$6,$7,$8) | 926 | 0 | 7 | -| insert into hs_booking_item (resources, version, projectuuid, type, parentitemuuid, validity, uuid, caption) values (new.resources, new. version, new. projectuuid, new. type, new. parentitemuuid, new. validity, new. uuid, new. caption) returning * | 926 | 0 | 7 | +| insert into public.hs_booking.item_rv (caption,parentitemuuid,projectuuid,resources,type,validity,version,uuid) values ($1,$2,$3,$4,$5,$6,$7,$8) | 926 | 0 | 7 | +| insert into hs_booking.item (resources, version, projectuuid, type, parentitemuuid, validity, uuid, caption) values (new.resources, new. version, new. projectuuid, new. type, new. parentitemuuid, new. validity, new. uuid, new. caption) returning * | 926 | 0 | 7 | The slowest query now was fetching Relations joined with Contact, Anchor-Person and Holder-Person, for all tables using the restricted (RBAC) views (_rv). @@ -306,8 +306,8 @@ We changed these mappings from `EAGER` (default) to `LAZY` to `@ManyToOne(fetch insert into public.hs_office.relation_rv (anchoruuid,contactuuid,holderuuid,mark,type,version,uuid) values ($1,$2,$3,$4,$5,$6,$7) | 1261 | 0 | 8 | | insert into hs_office.relation (uuid, version, anchoruuid, holderuuid, contactuuid, type, mark) values (new.uuid, new. version, new. anchoruuid, new. holderuuid, new. contactuuid, new. type, new. mark) returning * | 1261 | 0 | 8 | | call buildRbacSystemForHsOfficeRelation(NEW) | 1276 | 0 | 7 | -| insert into public.hs_booking_item_rv (caption,parentitemuuid,projectuuid,resources,type,validity,version,uuid) values ($1,$2,$3,$4,$5,$6,$7,$8) | 926 | 0 | 7 | -| insert into hs_booking_item (resources, version, projectuuid, type, parentitemuuid, validity, uuid, caption) values (new.resources, new. version, new. projectuuid, new. type, new. parentitemuuid, new. validity, new. uuid, new. caption) returning * | 926 | 0 | 7 | +| insert into public.hs_booking.item_rv (caption,parentitemuuid,projectuuid,resources,type,validity,version,uuid) values ($1,$2,$3,$4,$5,$6,$7,$8) | 926 | 0 | 7 | +| insert into hs_booking.item (resources, version, projectuuid, type, parentitemuuid, validity, uuid, caption) values (new.resources, new. version, new. projectuuid, new. type, new. parentitemuuid, new. validity, new. uuid, new. caption) returning * | 926 | 0 | 7 | insert into RbacGrants (grantedByTriggerOf, ascendantuuid, descendantUuid, assumed) values (currentTriggerObjectUuid(), superRoleId, subRoleId, doAssume) on conflict do nothing | 40472 | 0 | 0 | Now, finally, the total runtime of the import was down to 12 minutes. This is repeatable, where originally, the import took about 25mins in most cases and just rarely - and for unknown reasons - 10min. diff --git a/sql/historization.sql b/sql/historization.sql index d854f394..622948c6 100644 --- a/sql/historization.sql +++ b/sql/historization.sql @@ -6,10 +6,10 @@ rollback; begin transaction; call defineContext('historization testing', null, 'superuser-alex@hostsharing.net', --- 'hs_booking_project#D-1000000-hshdefaultproject:ADMIN'); -- prod+test - 'hs_booking_project#D-1000313-D-1000313defaultproject:ADMIN'); -- prod+test --- 'hs_booking_project#D-1000300-mihdefaultproject:ADMIN'); -- prod --- 'hs_booking_project#D-1000300-mimdefaultproject:ADMIN'); -- test +-- 'hs_booking.project#D-1000000-hshdefaultproject:ADMIN'); -- prod+test + 'hs_booking.project#D-1000313-D-1000313defaultproject:ADMIN'); -- prod+test +-- 'hs_booking.project#D-1000300-mihdefaultproject:ADMIN'); -- prod +-- 'hs_booking.project#D-1000300-mimdefaultproject:ADMIN'); -- test -- update hs_hosting_asset set caption='lug00 b' where identifier = 'lug00' and type = 'MANAGED_WEBSPACE'; -- prod -- update hs_hosting_asset set caption='hsh00 A ' || now()::text where identifier = 'hsh00' and type = 'MANAGED_WEBSPACE'; -- test -- update hs_hosting_asset set caption='hsh00 B ' || now()::text where identifier = 'hsh00' and type = 'MANAGED_WEBSPACE'; -- test diff --git a/sql/recursive-cte-experiments-for-accessible-uuids.sql b/sql/recursive-cte-experiments-for-accessible-uuids.sql index 84fa6e79..a484a6a0 100644 --- a/sql/recursive-cte-experiments-for-accessible-uuids.sql +++ b/sql/recursive-cte-experiments-for-accessible-uuids.sql @@ -53,8 +53,8 @@ select distinct perm.objectuuid rollback transaction; begin transaction; CALL defineContext('performance testing', null, 'superuser-alex@hostsharing.net', - 'hs_booking_project#D-1000000-hshdefaultproject:ADMIN'); --- 'hs_booking_project#D-1000300-mihdefaultproject:ADMIN'); + 'hs_booking.project#D-1000000-hshdefaultproject:ADMIN'); +-- 'hs_booking.project#D-1000300-mihdefaultproject:ADMIN'); SET TRANSACTION READ ONLY; EXPLAIN ANALYZE select * from hs_hosting_asset_example_gv; end transaction ; @@ -89,8 +89,8 @@ BEGIN start_time := clock_timestamp(); CALL defineContext('performance testing', null, 'superuser-alex@hostsharing.net', - 'hs_booking_project#D-1000000-hshdefaultproject:ADMIN'); --- 'hs_booking_project#D-1000300-mihdefaultproject:ADMIN'); + 'hs_booking.project#D-1000000-hshdefaultproject:ADMIN'); +-- 'hs_booking.project#D-1000300-mihdefaultproject:ADMIN'); SET TRANSACTION READ ONLY; FOR i IN 0..25 LOOP @@ -128,8 +128,8 @@ $$; rollback transaction; begin transaction; CALL defineContext('performance testing', null, 'superuser-alex@hostsharing.net', - 'hs_booking_project#D-1000000-hshdefaultproject:ADMIN'); --- 'hs_booking_project#D-1000300-mihdefaultproject:ADMIN'); + 'hs_booking.project#D-1000000-hshdefaultproject:ADMIN'); +-- 'hs_booking.project#D-1000300-mihdefaultproject:ADMIN'); SET TRANSACTION READ ONLY; EXPLAIN SELECT * from ( diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java index 6a288a44..69932d5b 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/debitor/HsBookingDebitorEntity.java @@ -18,7 +18,7 @@ import static net.hostsharing.hsadminng.stringify.Stringify.stringify; // a partial HsOfficeDebitorEntity to reduce the number of SQL queries to load the entity @Entity -@Table(name = "hs_booking_debitor_xv") +@Table(schema = "hs_booking", name = "debitor_xv") @Getter @Builder @NoArgsConstructor diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRbacEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRbacEntity.java index 250b65ef..c07c4d02 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRbacEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRbacEntity.java @@ -31,7 +31,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.directlyFetc import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; @Entity -@Table(name = "hs_booking_item_rv") +@Table(schema = "hs_booking", name = "item_rv") @SuperBuilder(toBuilder = true) @Getter @Setter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRealEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRealEntity.java index c9e0f8de..f15139f7 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRealEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRealEntity.java @@ -13,7 +13,7 @@ import jakarta.persistence.Table; @Entity -@Table(name = "hs_booking_item") +@Table(schema = "hs_booking", name = "item") @SuperBuilder(toBuilder = true) @Getter @Setter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java index ae997f07..55069224 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProject.java @@ -71,7 +71,7 @@ public abstract class HsBookingProject implements Stringifyable, BaseEntity findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type); default List findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) { return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type)); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java index 15a7de84..a9b0cc5a 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java @@ -25,14 +25,14 @@ public interface HsHostingAssetRealRepository extends HsHostingAssetRepository findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type); default List findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) { return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type)); diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java index 1c1ed23a..2219972b 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java @@ -986,7 +986,7 @@ public class RbacView { // this is just a workaround: return getRawTableName() .replace("hs_office.", "hsof.") - .replace("hs_booking_", "hsbk_") + .replace("hs_booking.", "hsbk_") .replace("hs_hosting_", "hsho_") .replace("coopsharestransaction", "coopsharetx") .replace("coopassetstransaction", "coopassettx"); diff --git a/src/main/resources/db/changelog/0-base/011-table-schema-and-name.sql b/src/main/resources/db/changelog/0-base/011-table-schema-and-name.sql index baf4a87d..04234b53 100644 --- a/src/main/resources/db/changelog/0-base/011-table-schema-and-name.sql +++ b/src/main/resources/db/changelog/0-base/011-table-schema-and-name.sql @@ -9,6 +9,9 @@ create or replace function base.combine_table_schema_and_name(tableSchema name, returns text language plpgsql as $$ begin + assert LEFT(tableSchema, 1) <> '"', 'tableSchema must not start with "'; + assert LEFT(tableName, 1) <> '"', 'tableName must not start with "'; + if tableSchema is null or tableSchema = 'public' or tableSchema = '' then return tableName::text; else diff --git a/src/main/resources/db/changelog/0-base/030-historization.sql b/src/main/resources/db/changelog/0-base/030-historization.sql index e61671cc..c220222c 100644 --- a/src/main/resources/db/changelog/0-base/030-historization.sql +++ b/src/main/resources/db/changelog/0-base/030-historization.sql @@ -63,7 +63,6 @@ begin if (currentSubject is null or currentSubject = '') then raise exception 'hsadminng.currentSubject must be defined, please use "SET LOCAL ...;"'; end if; - raise notice 'currentSubject: %', currentSubject; -- determine task currentTask = current_setting('hsadminng.currentTask'); @@ -81,8 +80,9 @@ begin "alive" := false; end if; - sql := format('INSERT INTO %3$I_ex VALUES (DEFAULT, pg_current_xact_id(), %1$L, %2$L, $1.*)', + sql := format('INSERT INTO %3$s_ex VALUES (DEFAULT, pg_current_xact_id(), %1$L, %2$L, $1.*)', TG_OP, alive, base.combine_table_schema_and_name(tg_table_schema, tg_table_name)::name); + -- raise exception 'generated-SQL: %', sql; execute sql using "row"; return "row"; @@ -117,12 +117,12 @@ begin ' EXCLUDING CONSTRAINTS' || ' EXCLUDING STATISTICS' || ')'; - raise notice 'sql: %', createHistTableSql; + -- raise notice 'sql: %', createHistTableSql; execute createHistTableSql; -- create the historical view - viewName = quote_ident(format('%s_hv', baseTable)); - exVersionsTable = quote_ident(format('%s_ex', baseTable)); + viewName = baseTable || '_hv'; + exVersionsTable = baseTable || '_ex'; baseCols = (select string_agg(quote_ident(column_name), ', ') from information_schema.columns where table_schema = 'public' @@ -146,15 +146,14 @@ begin ' )' || ')', viewName, baseCols, exVersionsTable - ); - raise notice 'sql: %', createViewSQL; + ); + -- raise notice 'generated-sql: %', createViewSQL; execute createViewSQL; -- "-9-" to put the trigger execution after any alphabetically lesser tx-triggers createTriggerSQL = 'CREATE TRIGGER tx_9_historicize_tg' || ' AFTER INSERT OR DELETE OR UPDATE ON ' || baseTable || ' FOR EACH ROW EXECUTE PROCEDURE base.tx_historicize_tf()'; - raise notice 'sql: %', createTriggerSQL; execute createTriggerSQL; end; $$; diff --git a/src/main/resources/db/changelog/6-hs-booking/600-hs-booking-schema.sql b/src/main/resources/db/changelog/6-hs-booking/600-hs-booking-schema.sql new file mode 100644 index 00000000..b80eedb7 --- /dev/null +++ b/src/main/resources/db/changelog/6-hs-booking/600-hs-booking-schema.sql @@ -0,0 +1,8 @@ +--liquibase formatted sql + + +-- ============================================================================ +--changeset michael.hoennig:hs-booking-SCHEMA endDelimiter:--// +-- ---------------------------------------------------------------------------- +CREATE SCHEMA hs_booking; +--// diff --git a/src/main/resources/db/changelog/6-hs-booking/610-booking-debitor/6100-hs-booking-debitor.sql b/src/main/resources/db/changelog/6-hs-booking/610-booking-debitor/6100-hs-booking-debitor.sql index f3e0b612..9748984a 100644 --- a/src/main/resources/db/changelog/6-hs-booking/610-booking-debitor/6100-hs-booking-debitor.sql +++ b/src/main/resources/db/changelog/6-hs-booking/610-booking-debitor/6100-hs-booking-debitor.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:hs-booking-debitor-RESTRICTED-VIEW endDelimiter:--// -- ---------------------------------------------------------------------------- -create view hs_booking_debitor_xv as +create view hs_booking.debitor_xv as select debitor.uuid, debitor.version, (partner.partnerNumber::varchar || debitor.debitorNumberSuffix)::numeric as debitorNumber, diff --git a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6200-hs-booking-project.sql b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6200-hs-booking-project.sql index 70724958..34b13c8f 100644 --- a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6200-hs-booking-project.sql +++ b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6200-hs-booking-project.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:booking-project-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -create table if not exists hs_booking_project +create table if not exists hs_booking.project ( uuid uuid unique references rbac.object (uuid), version int not null default 0, @@ -18,12 +18,12 @@ create table if not exists hs_booking_project --changeset michael.hoennig:hs-booking-project-MAIN-TABLE-JOURNAL endDelimiter:--// -- ---------------------------------------------------------------------------- -call base.create_journal('hs_booking_project'); +call base.create_journal('hs_booking.project'); --// -- ============================================================================ --changeset michael.hoennig:hs-booking-project-MAIN-TABLE-HISTORIZATION endDelimiter:--// -- ---------------------------------------------------------------------------- -call base.tx_create_historicization('hs_booking_project'); +call base.tx_create_historicization('hs_booking.project'); --// diff --git a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql index 053c0f86..527a12e8 100644 --- a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql @@ -5,14 +5,14 @@ -- ============================================================================ --changeset RbacObjectGenerator:hs-booking-project-rbac-OBJECT endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRelatedRbacObject('hs_booking_project'); +call rbac.generateRelatedRbacObject('hs_booking.project'); --// -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:hs-booking-project-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRoleDescriptors('hsBookingProject', 'hs_booking_project'); +call rbac.generateRbacRoleDescriptors('hsBookingProject', 'hs_booking.project'); --// @@ -24,8 +24,8 @@ call rbac.generateRbacRoleDescriptors('hsBookingProject', 'hs_booking_project'); Creates the roles, grants and permission for the AFTER INSERT TRIGGER. */ -create or replace procedure hs_booking_project_build_rbac_system( - NEW hs_booking_project +create or replace procedure hs_booking.project_build_rbac_system( + NEW hs_booking.project ) language plpgsql as $$ @@ -76,22 +76,22 @@ begin end; $$; /* - AFTER INSERT TRIGGER to create the role+grant structure for a new hs_booking_project row. + AFTER INSERT TRIGGER to create the role+grant structure for a new hs_booking.project row. */ -create or replace function hs_booking_project_build_rbac_system_after_insert_tf() +create or replace function hs_booking.project_build_rbac_system_after_insert_tf() returns trigger language plpgsql strict as $$ begin - call hs_booking_project_build_rbac_system(NEW); + call hs_booking.project_build_rbac_system(NEW); return NEW; end; $$; create trigger build_rbac_system_after_insert_tg - after insert on hs_booking_project + after insert on hs_booking.project for each row -execute procedure hs_booking_project_build_rbac_system_after_insert_tf(); +execute procedure hs_booking.project_build_rbac_system_after_insert_tf(); --// @@ -102,45 +102,45 @@ execute procedure hs_booking_project_build_rbac_system_after_insert_tf(); -- granting INSERT permission to hs_office.relation ---------------------------- /* - Grants INSERT INTO hs_booking_project permissions to specified role of pre-existing hs_office.relation rows. + Grants INSERT INTO hs_booking.project permissions to specified role of pre-existing hs_office.relation rows. */ do language plpgsql $$ declare row hs_office.relation; begin - call base.defineContext('create INSERT INTO hs_booking_project permissions for pre-exising hs_office.relation rows'); + call base.defineContext('create INSERT INTO hs_booking.project permissions for pre-exising hs_office.relation rows'); FOR row IN SELECT * FROM hs_office.relation WHERE type = 'DEBITOR' LOOP call rbac.grantPermissionToRole( - rbac.createPermission(row.uuid, 'INSERT', 'hs_booking_project'), + rbac.createPermission(row.uuid, 'INSERT', 'hs_booking.project'), hsOfficeRelationADMIN(row)); END LOOP; end; $$; /** - Grants hs_booking_project INSERT permission to specified role of new relation rows. + Grants hs_booking.project INSERT permission to specified role of new relation rows. */ -create or replace function new_hsbk_project_grants_insert_to_relation_tf() +create or replace function hs_booking.new_project_grants_insert_to_relation_tf() returns trigger language plpgsql strict as $$ begin if NEW.type = 'DEBITOR' then call rbac.grantPermissionToRole( - rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking_project'), + rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking.project'), hsOfficeRelationADMIN(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_hs_booking_project_grants_after_insert_tg +create trigger z_new_project_grants_after_insert_tg after insert on hs_office.relation for each row -execute procedure new_hsbk_project_grants_insert_to_relation_tf(); +execute procedure hs_booking.new_project_grants_insert_to_relation_tf(); -- ============================================================================ @@ -148,9 +148,9 @@ execute procedure new_hsbk_project_grants_insert_to_relation_tf(); -- ---------------------------------------------------------------------------- /** - Checks if the user respectively the assumed roles are allowed to insert a row to hs_booking_project. + Checks if the user respectively the assumed roles are allowed to insert a row to hs_booking.project. */ -create or replace function hs_booking_project_insert_permission_check_tf() +create or replace function hs_booking.project_insert_permission_check_tf() returns trigger language plpgsql as $$ declare @@ -162,19 +162,19 @@ begin JOIN hs_office.debitor debitor ON debitor.debitorRelUuid = debitorRel.uuid WHERE debitor.uuid = NEW.debitorUuid ); - assert superObjectUuid is not null, 'object uuid fetched depending on hs_booking_project.debitorUuid must not be null, also check fetchSql in RBAC DSL'; - if rbac.hasInsertPermission(superObjectUuid, 'hs_booking_project') then + assert superObjectUuid is not null, 'object uuid fetched depending on hs_booking.project.debitorUuid must not be null, also check fetchSql in RBAC DSL'; + if rbac.hasInsertPermission(superObjectUuid, 'hs_booking.project') then return NEW; end if; - raise exception '[403] insert into hs_booking_project values(%) not allowed for current subjects % (%)', + raise exception '[403] insert into hs_booking.project values(%) not allowed for current subjects % (%)', NEW, base.currentSubjects(), rbac.currentSubjectOrAssumedRolesUuids(); end; $$; -create trigger hs_booking_project_insert_permission_check_tg - before insert on hs_booking_project +create trigger project_insert_permission_check_tg + before insert on hs_booking.project for each row - execute procedure hs_booking_project_insert_permission_check_tf(); + execute procedure hs_booking.project_insert_permission_check_tf(); --// @@ -182,10 +182,10 @@ create trigger hs_booking_project_insert_permission_check_tg --changeset RbacIdentityViewGenerator:hs-booking-project-rbac-IDENTITY-VIEW endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacIdentityViewFromQuery('hs_booking_project', +call rbac.generateRbacIdentityViewFromQuery('hs_booking.project', $idName$ SELECT bookingProject.uuid as uuid, debitorIV.idName || '-' || base.cleanIdentifier(bookingProject.caption) as idName - FROM hs_booking_project bookingProject + FROM hs_booking.project bookingProject JOIN hs_office.debitor_iv debitorIV ON debitorIV.uuid = bookingProject.debitorUuid $idName$); --// @@ -194,7 +194,7 @@ call rbac.generateRbacIdentityViewFromQuery('hs_booking_project', -- ============================================================================ --changeset RbacRestrictedViewGenerator:hs-booking-project-rbac-RESTRICTED-VIEW endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRestrictedView('hs_booking_project', +call rbac.generateRbacRestrictedView('hs_booking.project', $orderBy$ caption $orderBy$, diff --git a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6208-hs-booking-project-test-data.sql b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6208-hs-booking-project-test-data.sql index 60871add..3a8a2981 100644 --- a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6208-hs-booking-project-test-data.sql +++ b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6208-hs-booking-project-test-data.sql @@ -6,7 +6,7 @@ -- ---------------------------------------------------------------------------- /* - Creates a single hs_booking_project test record. + Creates a single hs_booking.project test record. */ create or replace procedure createHsBookingProjectTransactionTestData( givenPartnerNumber numeric, @@ -27,7 +27,7 @@ begin raise notice 'creating test booking-project: %', givenDebitorSuffix::text; raise notice '- using debitor (%): %', relatedDebitor.uuid, relatedDebitor; insert - into hs_booking_project (uuid, debitoruuid, caption) + into hs_booking.project (uuid, debitoruuid, caption) values (uuid_generate_v4(), relatedDebitor.uuid, 'D-' || givenPartnerNumber::text || givenDebitorSuffix || ' default project'); end; $$; --// diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql index cda9eece..8a744614 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql @@ -14,18 +14,18 @@ create type HsBookingItemType as enum ( CREATE CAST (character varying as HsBookingItemType) WITH INOUT AS IMPLICIT; -create table if not exists hs_booking_item +create table if not exists hs_booking.item ( uuid uuid unique references rbac.object (uuid), version int not null default 0, - projectUuid uuid null references hs_booking_project(uuid), + projectUuid uuid null references hs_booking.project(uuid), type HsBookingItemType not null, - parentItemUuid uuid null references hs_booking_item(uuid) initially deferred, + parentItemUuid uuid null references hs_booking.item(uuid) initially deferred, validity daterange not null, caption varchar(80) not null, resources jsonb not null, - constraint chk_hs_booking_item_has_project_or_parent_asset + constraint booking_item_has_project_or_parent_asset check (projectUuid is not null or parentItemUuid is not null) ); --// @@ -35,13 +35,13 @@ create table if not exists hs_booking_item --changeset michael.hoennig:hs-booking-item-MAIN-TABLE-JOURNAL endDelimiter:--// -- ---------------------------------------------------------------------------- -call base.create_journal('hs_booking_item'); +call base.create_journal('hs_booking.item'); --// -- ============================================================================ --changeset michael.hoennig:hs-booking-item-MAIN-TABLE-HISTORIZATION endDelimiter:--// -- ---------------------------------------------------------------------------- -call base.tx_create_historicization('hs_booking_item'); +call base.tx_create_historicization('hs_booking.item'); --// diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql index a27e0f8a..f0e692b9 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql @@ -5,14 +5,14 @@ -- ============================================================================ --changeset RbacObjectGenerator:hs-booking-item-rbac-OBJECT endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRelatedRbacObject('hs_booking_item'); +call rbac.generateRelatedRbacObject('hs_booking.item'); --// -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:hs-booking-item-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRoleDescriptors('hsBookingItem', 'hs_booking_item'); +call rbac.generateRbacRoleDescriptors('hsBookingItem', 'hs_booking.item'); --// @@ -24,21 +24,21 @@ call rbac.generateRbacRoleDescriptors('hsBookingItem', 'hs_booking_item'); Creates the roles, grants and permission for the AFTER INSERT TRIGGER. */ -create or replace procedure hs_booking_item_build_rbac_system( - NEW hs_booking_item +create or replace procedure hs_booking.item_build_rbac_system( + NEW hs_booking.item ) language plpgsql as $$ declare - newProject hs_booking_project; - newParentItem hs_booking_item; + newProject hs_booking.project; + newParentItem hs_booking.item; begin call rbac.enterTriggerForObjectUuid(NEW.uuid); - SELECT * FROM hs_booking_project WHERE uuid = NEW.projectUuid INTO newProject; + SELECT * FROM hs_booking.project WHERE uuid = NEW.projectUuid INTO newProject; - SELECT * FROM hs_booking_item WHERE uuid = NEW.parentItemUuid INTO newParentItem; + SELECT * FROM hs_booking.item WHERE uuid = NEW.parentItemUuid INTO newParentItem; perform rbac.defineRoleWithGrants( hsBookingItemOWNER(NEW), @@ -75,22 +75,22 @@ begin end; $$; /* - AFTER INSERT TRIGGER to create the role+grant structure for a new hs_booking_item row. + AFTER INSERT TRIGGER to create the role+grant structure for a new hs_booking.item row. */ -create or replace function hs_booking_item_build_rbac_system_after_insert_tf() +create or replace function hs_booking.item_build_rbac_system_after_insert_tf() returns trigger language plpgsql strict as $$ begin - call hs_booking_item_build_rbac_system(NEW); + call hs_booking.item_build_rbac_system(NEW); return NEW; end; $$; create trigger build_rbac_system_after_insert_tg - after insert on hs_booking_item + after insert on hs_booking.item for each row -execute procedure hs_booking_item_build_rbac_system_after_insert_tf(); +execute procedure hs_booking.item_build_rbac_system_after_insert_tf(); --// @@ -101,115 +101,115 @@ execute procedure hs_booking_item_build_rbac_system_after_insert_tf(); -- granting INSERT permission to rbac.global ---------------------------- /* - Grants INSERT INTO hs_booking_item permissions to specified role of pre-existing rbac.global rows. + Grants INSERT INTO hs_booking.item permissions to specified role of pre-existing rbac.global rows. */ do language plpgsql $$ declare row rbac.global; begin - call base.defineContext('create INSERT INTO hs_booking_item permissions for pre-exising rbac.global rows'); + call base.defineContext('create INSERT INTO hs_booking.item permissions for pre-exising rbac.global rows'); FOR row IN SELECT * FROM rbac.global -- unconditional for all rows in that table LOOP call rbac.grantPermissionToRole( - rbac.createPermission(row.uuid, 'INSERT', 'hs_booking_item'), + rbac.createPermission(row.uuid, 'INSERT', 'hs_booking.item'), rbac.globalADMIN()); END LOOP; end; $$; /** - Grants hs_booking_item INSERT permission to specified role of new global rows. + Grants hs_booking.item INSERT permission to specified role of new global rows. */ -create or replace function new_hsbk_item_grants_insert_to_global_tf() +create or replace function hs_booking.new_item_grants_insert_to_global_tf() returns trigger language plpgsql strict as $$ begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( - rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking_item'), + rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking.item'), rbac.globalADMIN()); -- 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_hs_booking_item_grants_after_insert_tg +create trigger z_new_item_grants_after_insert_tg after insert on rbac.global for each row -execute procedure new_hsbk_item_grants_insert_to_global_tf(); +execute procedure hs_booking.new_item_grants_insert_to_global_tf(); --- granting INSERT permission to hs_booking_project ---------------------------- +-- granting INSERT permission to hs_booking.project ---------------------------- /* - Grants INSERT INTO hs_booking_item permissions to specified role of pre-existing hs_booking_project rows. + Grants INSERT INTO hs_booking.item permissions to specified role of pre-existing hs_booking.project rows. */ do language plpgsql $$ declare - row hs_booking_project; + row hs_booking.project; begin - call base.defineContext('create INSERT INTO hs_booking_item permissions for pre-exising hs_booking_project rows'); + call base.defineContext('create INSERT INTO hs_booking.item permissions for pre-exising hs_booking.project rows'); - FOR row IN SELECT * FROM hs_booking_project + FOR row IN SELECT * FROM hs_booking.project -- unconditional for all rows in that table LOOP call rbac.grantPermissionToRole( - rbac.createPermission(row.uuid, 'INSERT', 'hs_booking_item'), + rbac.createPermission(row.uuid, 'INSERT', 'hs_booking.item'), hsBookingProjectADMIN(row)); END LOOP; end; $$; /** - Grants hs_booking_item INSERT permission to specified role of new hs_booking_project rows. + Grants hs_booking.item INSERT permission to specified role of new project rows. */ -create or replace function new_hsbk_item_grants_insert_to_hsbk_project_tf() +create or replace function hs_booking.new_item_grants_insert_to_project_tf() returns trigger language plpgsql strict as $$ begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( - rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking_item'), + rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking.item'), hsBookingProjectADMIN(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_hs_booking_item_grants_after_insert_tg - after insert on hs_booking_project +create trigger z_new_item_grants_after_insert_tg + after insert on hs_booking.project for each row -execute procedure new_hsbk_item_grants_insert_to_hsbk_project_tf(); +execute procedure hs_booking.new_item_grants_insert_to_project_tf(); --- granting INSERT permission to hs_booking_item ---------------------------- +-- granting INSERT permission to hs_booking.item ---------------------------- -- Granting INSERT INTO hs_hosting_asset permissions to specified role of pre-existing hs_hosting_asset rows slipped, -- because there cannot yet be any pre-existing rows in the same table yet. /** - Grants hs_booking_item INSERT permission to specified role of new hs_booking_item rows. + Grants hs_booking.item INSERT permission to specified role of new item rows. */ -create or replace function new_hsbk_item_grants_insert_to_hsbk_item_tf() +create or replace function hs_booking.new_item_grants_insert_to_item_tf() returns trigger language plpgsql strict as $$ begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( - rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking_item'), + rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking.item'), hsBookingItemADMIN(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_hs_booking_item_grants_after_insert_tg - after insert on hs_booking_item +create trigger z_new_item_grants_after_insert_tg + after insert on hs_booking.item for each row -execute procedure new_hsbk_item_grants_insert_to_hsbk_item_tf(); +execute procedure hs_booking.new_item_grants_insert_to_item_tf(); -- ============================================================================ @@ -217,9 +217,9 @@ execute procedure new_hsbk_item_grants_insert_to_hsbk_item_tf(); -- ---------------------------------------------------------------------------- /** - Checks if the user respectively the assumed roles are allowed to insert a row to hs_booking_item. + Checks if the user respectively the assumed roles are allowed to insert a row to hs_booking.item. */ -create or replace function hs_booking_item_insert_permission_check_tf() +create or replace function hs_booking.item_insert_permission_check_tf() returns trigger language plpgsql as $$ declare @@ -230,22 +230,22 @@ begin return NEW; end if; -- check INSERT permission via direct foreign key: NEW.projectUuid - if rbac.hasInsertPermission(NEW.projectUuid, 'hs_booking_item') then + if rbac.hasInsertPermission(NEW.projectUuid, 'hs_booking.item') then return NEW; end if; -- check INSERT permission via direct foreign key: NEW.parentItemUuid - if rbac.hasInsertPermission(NEW.parentItemUuid, 'hs_booking_item') then + if rbac.hasInsertPermission(NEW.parentItemUuid, 'hs_booking.item') then return NEW; end if; - raise exception '[403] insert into hs_booking_item values(%) not allowed for current subjects % (%)', + raise exception '[403] insert into hs_booking.item values(%) not allowed for current subjects % (%)', NEW, base.currentSubjects(), rbac.currentSubjectOrAssumedRolesUuids(); end; $$; -create trigger hs_booking_item_insert_permission_check_tg - before insert on hs_booking_item +create trigger item_insert_permission_check_tg + before insert on hs_booking.item for each row - execute procedure hs_booking_item_insert_permission_check_tf(); + execute procedure hs_booking.item_insert_permission_check_tf(); --// @@ -253,7 +253,7 @@ create trigger hs_booking_item_insert_permission_check_tg --changeset RbacIdentityViewGenerator:hs-booking-item-rbac-IDENTITY-VIEW endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacIdentityViewFromProjection('hs_booking_item', +call rbac.generateRbacIdentityViewFromProjection('hs_booking.item', $idName$ caption $idName$); @@ -263,7 +263,7 @@ call rbac.generateRbacIdentityViewFromProjection('hs_booking_item', -- ============================================================================ --changeset RbacRestrictedViewGenerator:hs-booking-item-rbac-RESTRICTED-VIEW endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRestrictedView('hs_booking_item', +call rbac.generateRbacRestrictedView('hs_booking.item', $orderBy$ validity $orderBy$, diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql index d6f31b0f..84d53142 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql @@ -6,7 +6,7 @@ -- ---------------------------------------------------------------------------- /* - Creates a single hs_booking_item test record. + Creates a single hs_booking.item test record. */ create or replace procedure createHsBookingItemTransactionTestData( givenPartnerNumber numeric, @@ -14,12 +14,12 @@ create or replace procedure createHsBookingItemTransactionTestData( ) language plpgsql as $$ declare - relatedProject hs_booking_project; + relatedProject hs_booking.project; privateCloudUuid uuid; managedServerUuid uuid; begin select project.* into relatedProject - from hs_booking_project project + from hs_booking.project project where project.caption = 'D-' || givenPartnerNumber || givenDebitorSuffix || ' default project'; raise notice 'creating test booking-item: %', givenPartnerNumber::text || givenDebitorSuffix::text; @@ -27,7 +27,7 @@ begin privateCloudUuid := uuid_generate_v4(); managedServerUuid := uuid_generate_v4(); insert - into hs_booking_item (uuid, projectuuid, type, parentitemuuid, caption, validity, resources) + into hs_booking.item (uuid, projectuuid, type, parentitemuuid, caption, validity, resources) values (privateCloudUuid, relatedProject.uuid, 'PRIVATE_CLOUD', null, 'some PrivateCloud', daterange('20240401', null, '[]'), '{ "CPU": 10, "RAM": 32, "SSD": 4000, "HDD": 10000, "Traffic": 2000 }'::jsonb), (uuid_generate_v4(), null, 'MANAGED_SERVER', privateCloudUuid, 'some ManagedServer', daterange('20230115', '20240415', '[)'), '{ "CPU": 2, "RAM": 4, "SSD": 500, "Traffic": 500 }'::jsonb), (uuid_generate_v4(), null, 'CLOUD_SERVER', privateCloudUuid, 'test CloudServer', daterange('20230115', '20240415', '[)'), '{ "CPU": 2, "RAM": 4, "SSD": 750, "Traffic": 500 }'::jsonb), diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql index aef12936..c21a6602 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql @@ -32,7 +32,7 @@ create table if not exists hs_hosting_asset ( uuid uuid unique references rbac.object (uuid), version int not null default 0, - bookingItemUuid uuid null references hs_booking_item(uuid), + bookingItemUuid uuid null references hs_booking.item(uuid), type HsHostingAssetType not null, parentAssetUuid uuid null references hs_hosting_asset(uuid) initially deferred, assignedToAssetUuid uuid null references hs_hosting_asset(uuid) initially deferred, @@ -138,7 +138,7 @@ declare expectedBookingItemType HsBookingItemType; begin actualBookingItemType := (select type - from hs_booking_item + from hs_booking.item where NEW.bookingItemUuid = uuid); if NEW.type = 'CLOUD_SERVER' then diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql index 7050afd3..fa04eddc 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql @@ -30,7 +30,7 @@ create or replace procedure hs_hosting_asset_build_rbac_system( language plpgsql as $$ declare - newBookingItem hs_booking_item; + newBookingItem hs_booking.item; newAssignedToAsset hs_hosting_asset; newAlarmContact hs_office.contact; newParentAsset hs_hosting_asset; @@ -38,7 +38,7 @@ declare begin call rbac.enterTriggerForObjectUuid(NEW.uuid); - SELECT * FROM hs_booking_item WHERE uuid = NEW.bookingItemUuid INTO newBookingItem; + SELECT * FROM hs_booking.item WHERE uuid = NEW.bookingItemUuid INTO newBookingItem; SELECT * FROM hs_hosting_asset WHERE uuid = NEW.assignedToAssetUuid INTO newAssignedToAsset; diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql index 1a89bcc7..0506c67c 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql @@ -11,12 +11,12 @@ create or replace procedure createHsHostingAssetTestData(givenProjectCaption varchar) language plpgsql as $$ declare - relatedProject hs_booking_project; + relatedProject hs_booking.project; relatedDebitor hs_office.debitor; - privateCloudBI hs_booking_item; - managedServerBI hs_booking_item; - cloudServerBI hs_booking_item; - managedWebspaceBI hs_booking_item; + privateCloudBI hs_booking.item; + managedServerBI hs_booking.item; + cloudServerBI hs_booking.item; + managedWebspaceBI hs_booking.item; debitorNumberSuffix varchar; defaultPrefix varchar; managedServerUuid uuid; @@ -33,7 +33,7 @@ begin call base.defineContext('creating hosting-asset test-data', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN'); select project.* into relatedProject - from hs_booking_project project + from hs_booking.project project where project.caption = givenProjectCaption; assert relatedProject.uuid is not null, 'relatedProject for "' || givenProjectCaption || '" must not be null'; @@ -43,25 +43,25 @@ begin assert relatedDebitor.uuid is not null, 'relatedDebitor for "' || givenProjectCaption || '" must not be null'; select item.* into privateCloudBI - from hs_booking_item item + from hs_booking.item item where item.projectUuid = relatedProject.uuid and item.type = 'PRIVATE_CLOUD'; assert privateCloudBI.uuid is not null, 'relatedPrivateCloudBookingItem for "' || givenProjectCaption|| '" must not be null'; select item.* into managedServerBI - from hs_booking_item item + from hs_booking.item item where item.projectUuid = relatedProject.uuid and item.type = 'MANAGED_SERVER'; assert managedServerBI.uuid is not null, 'relatedManagedServerBookingItem for "' || givenProjectCaption|| '" must not be null'; select item.* into cloudServerBI - from hs_booking_item item + from hs_booking.item item where item.parentItemuuid = privateCloudBI.uuid and item.type = 'CLOUD_SERVER'; assert cloudServerBI.uuid is not null, 'relatedCloudServerBookingItem for "' || givenProjectCaption|| '" must not be null'; select item.* into managedWebspaceBI - from hs_booking_item item + from hs_booking.item item where item.projectUuid = relatedProject.uuid and item.type = 'MANAGED_WEBSPACE'; assert managedWebspaceBI.uuid is not null, 'relatedManagedWebspaceBookingItem for "' || givenProjectCaption|| '" must not be null'; diff --git a/src/main/resources/db/changelog/9-hs-global/9000-statistics.sql b/src/main/resources/db/changelog/9-hs-global/9000-statistics.sql index 5668dc2f..6d3e3c53 100644 --- a/src/main/resources/db/changelog/9-hs-global/9000-statistics.sql +++ b/src/main/resources/db/changelog/9-hs-global/9000-statistics.sql @@ -16,8 +16,8 @@ select * from hs_hosting_asset group by type union all - select to_char(count(*)::int, '9 999 999 999'), 'objects', 'hs_booking_item', type::text - from hs_booking_item + select to_char(count(*)::int, '9 999 999 999'), 'objects', 'hs_booking.item', type::text + from hs_booking.item group by type ) as totals order by replace(count, ' ', '')::int desc; --// diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index ced88d6c..cad1e16c 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -143,6 +143,8 @@ databaseChangeLog: file: db/changelog/5-hs-office/512-coopassets/5126-hs-office-coopassets-migration.sql - include: file: db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql + - include: + file: db/changelog/6-hs-booking/600-hs-booking-schema.sql - include: file: db/changelog/6-hs-booking/610-booking-debitor/6100-hs-booking-debitor.sql - include: diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java index 1b840deb..92f35895 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java @@ -251,7 +251,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup RestAssured // @formatter:off .given() .header("current-subject", "superuser-alex@hostsharing.net") - .header("assumed-roles", "hs_booking_project#D-1000313-D-1000313defaultproject:ADMIN") + .header("assumed-roles", "hs_booking.project#D-1000313-D-1000313defaultproject:ADMIN") .port(port) .when() .get("http://localhost/api/hs/booking/items/" + givenBookingItem.getUuid()) @@ -295,7 +295,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup RestAssured // @formatter:off .given() .header("current-subject", "superuser-alex@hostsharing.net") - .header("assumed-roles", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT") + .header("assumed-roles", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT") .contentType(ContentType.JSON) .body(""" { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepositoryIntegrationTest.java index bbdd7265..091c2c62 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepositoryIntegrationTest.java @@ -70,7 +70,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup final var query = em.createNativeQuery(""" select currentTask, targetTable, targetOp, targetdelta->>'caption' from base.tx_journal_v - where targettable = 'hs_booking_item'; + where targettable = 'hs_booking.item'; """); // when @@ -78,13 +78,13 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup // then assertThat(customerLogEntries).map(Arrays::toString).contains( - "[creating booking-item test-data, hs_booking_item, INSERT, prod CloudServer]", - "[creating booking-item test-data, hs_booking_item, INSERT, separate ManagedServer]", - "[creating booking-item test-data, hs_booking_item, INSERT, separate ManagedWebspace]", - "[creating booking-item test-data, hs_booking_item, INSERT, some ManagedServer]", - "[creating booking-item test-data, hs_booking_item, INSERT, some ManagedWebspace]", - "[creating booking-item test-data, hs_booking_item, INSERT, some PrivateCloud]", - "[creating booking-item test-data, hs_booking_item, INSERT, test CloudServer]"); + "[creating booking-item test-data, hs_booking.item, INSERT, prod CloudServer]", + "[creating booking-item test-data, hs_booking.item, INSERT, separate ManagedServer]", + "[creating booking-item test-data, hs_booking.item, INSERT, separate ManagedWebspace]", + "[creating booking-item test-data, hs_booking.item, INSERT, some ManagedServer]", + "[creating booking-item test-data, hs_booking.item, INSERT, some ManagedWebspace]", + "[creating booking-item test-data, hs_booking.item, INSERT, some PrivateCloud]", + "[creating booking-item test-data, hs_booking.item, INSERT, test CloudServer]"); } @Test @@ -92,7 +92,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup // given final String nativeQuerySql = """ select count(*) - from hs_booking_item_hv ha; + from hs_booking.item_hv ha; """; // when @@ -101,7 +101,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup @SuppressWarnings("unchecked") final var countBefore = (Integer) query.getSingleResult(); // then - assertThat(countBefore).as("hs_booking_item should not contain rows for a timestamp in the past").isEqualTo(0); + assertThat(countBefore).as("hs_booking.item should not contain rows for a timestamp in the past").isEqualTo(0); // and when historicalContext(Timestamp.from(ZonedDateTime.now().plusHours(1).toInstant())); @@ -109,7 +109,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup @SuppressWarnings("unchecked") final var countAfter = (Integer) query.getSingleResult(); // then - assertThat(countAfter).as("hs_booking_item should contain rows for a timestamp in the future").isGreaterThan(1); + assertThat(countAfter).as("hs_booking.item should contain rows for a timestamp in the future").isGreaterThan(1); } @Nested @@ -167,32 +167,32 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup final var all = rawRoleRepo.findAll(); assertThat(distinctRoleNamesOf(all)).containsExactlyInAnyOrder(Array.from( initialRoleNames, - "hs_booking_item#somenewbookingitem:ADMIN", - "hs_booking_item#somenewbookingitem:AGENT", - "hs_booking_item#somenewbookingitem:OWNER", - "hs_booking_item#somenewbookingitem:TENANT")); + "hs_booking.item#somenewbookingitem:ADMIN", + "hs_booking.item#somenewbookingitem:AGENT", + "hs_booking.item#somenewbookingitem:OWNER", + "hs_booking.item#somenewbookingitem:TENANT")); assertThat(distinctGrantDisplaysOf(rawGrantRepo.findAll())) .containsExactlyInAnyOrder(fromFormatted( initialGrantNames, // rbac.global-admin - "{ grant perm:hs_booking_item#somenewbookingitem:INSERT>hs_booking_item to role:hs_booking_item#somenewbookingitem:ADMIN by system and assume }", - "{ grant perm:hs_booking_item#somenewbookingitem:DELETE to role:rbac.global#global:ADMIN by system and assume }", + "{ grant perm:hs_booking.item#somenewbookingitem:INSERT>hs_booking.item to role:hs_booking.item#somenewbookingitem:ADMIN by system and assume }", + "{ grant perm:hs_booking.item#somenewbookingitem:DELETE to role:rbac.global#global:ADMIN by system and assume }", // owner - "{ grant role:hs_booking_item#somenewbookingitem:OWNER to role:hs_booking_project#D-1000111-D-1000111defaultproject:AGENT by system and assume }", + "{ grant role:hs_booking.item#somenewbookingitem:OWNER to role:hs_booking.project#D-1000111-D-1000111defaultproject:AGENT by system and assume }", // admin - "{ grant perm:hs_booking_item#somenewbookingitem:UPDATE to role:hs_booking_item#somenewbookingitem:ADMIN by system and assume }", - "{ grant role:hs_booking_item#somenewbookingitem:ADMIN to role:hs_booking_item#somenewbookingitem:OWNER by system and assume }", + "{ grant perm:hs_booking.item#somenewbookingitem:UPDATE to role:hs_booking.item#somenewbookingitem:ADMIN by system and assume }", + "{ grant role:hs_booking.item#somenewbookingitem:ADMIN to role:hs_booking.item#somenewbookingitem:OWNER by system and assume }", // agent - "{ grant role:hs_booking_item#somenewbookingitem:AGENT to role:hs_booking_item#somenewbookingitem:ADMIN by system and assume }", + "{ grant role:hs_booking.item#somenewbookingitem:AGENT to role:hs_booking.item#somenewbookingitem:ADMIN by system and assume }", // tenant - "{ grant role:hs_booking_item#somenewbookingitem:TENANT to role:hs_booking_item#somenewbookingitem:AGENT by system and assume }", - "{ grant perm:hs_booking_item#somenewbookingitem:SELECT to role:hs_booking_item#somenewbookingitem:TENANT by system and assume }", - "{ grant role:hs_booking_project#D-1000111-D-1000111defaultproject:TENANT to role:hs_booking_item#somenewbookingitem:TENANT by system and assume }", + "{ grant role:hs_booking.item#somenewbookingitem:TENANT to role:hs_booking.item#somenewbookingitem:AGENT by system and assume }", + "{ grant perm:hs_booking.item#somenewbookingitem:SELECT to role:hs_booking.item#somenewbookingitem:TENANT by system and assume }", + "{ grant role:hs_booking.project#D-1000111-D-1000111defaultproject:TENANT to role:hs_booking.item#somenewbookingitem:TENANT by system and assume }", null)); } @@ -230,7 +230,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup // given: context("person-FirbySusan@example.com"); final var debitor = debitorRepo.findDebitorByDebitorNumber(1000111); - context("person-FirbySusan@example.com", "hs_booking_project#D-1000111-D-1000111defaultproject:OWNER"); + context("person-FirbySusan@example.com", "hs_booking.project#D-1000111-D-1000111defaultproject:OWNER"); final var projectUuid = debitor.stream() .map(d -> realProjectRepo.findAllByDebitorUuid(d.getUuid())) .flatMap(List::stream) @@ -258,7 +258,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup // when final var result = jpaAttempt.transacted(() -> { - context("superuser-alex@hostsharing.net", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); + context("superuser-alex@hostsharing.net", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT"); final var foundBookingItem = em.find(HsBookingItemRbacEntity.class, givenBookingItemUuid); foundBookingItem.getResources().put("CPU", 2); foundBookingItem.getResources().remove("SSD-storage"); @@ -311,12 +311,12 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup @Test public void nonGlobalAdmin_canNotDeleteTheirRelatedBookingItem() { // given - context("superuser-alex@hostsharing.net", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); + context("superuser-alex@hostsharing.net", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT"); final var givenBookingItem = givenSomeTemporaryBookingItem("D-1000111 default project"); // when final var result = jpaAttempt.transacted(() -> { - context("person-FirbySusan@example.com", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); + context("person-FirbySusan@example.com", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT"); assertThat(rbacBookingItemRepo.findByUuid(givenBookingItem.getUuid())).isPresent(); rbacBookingItemRepo.deleteByUuid(givenBookingItem.getUuid()); @@ -325,7 +325,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup // then result.assertExceptionWithRootCauseMessage( JpaSystemException.class, - "[403] Subject ", " is not allowed to delete hs_booking_item"); + "[403] Subject ", " is not allowed to delete hs_booking.item"); assertThat(jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); return rbacBookingItemRepo.findByUuid(givenBookingItem.getUuid()); @@ -335,7 +335,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup @Test public void deletingABookingItemAlsoDeletesRelatedRolesAndGrants() { // given - context("superuser-alex@hostsharing.net", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); + context("superuser-alex@hostsharing.net", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT"); final var initialRoleNames = Array.from(distinctRoleNamesOf(rawRoleRepo.findAll())); final var initialGrantNames = Array.from(distinctGrantDisplaysOf(rawGrantRepo.findAll())); final var givenBookingItem = givenSomeTemporaryBookingItem("D-1000111 default project"); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java index a9f25b94..69c11d9f 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java @@ -168,7 +168,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean RestAssured // @formatter:off .given() .header("current-subject", "person-TuckerJack@example.com") - .header("assumed-roles", "hs_booking_project#D-1000313-D-1000313defaultproject:AGENT") + .header("assumed-roles", "hs_booking.project#D-1000313-D-1000313defaultproject:AGENT") .port(port) .when() .get("http://localhost/api/hs/booking/projects/" + givenBookingProjectUuid) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectRepositoryIntegrationTest.java index beae21e0..411d4360 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectRepositoryIntegrationTest.java @@ -65,7 +65,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea final var query = em.createNativeQuery(""" select currentTask, targetTable, targetOp, targetdelta->>'caption' from base.tx_journal_v - where targettable = 'hs_booking_project'; + where targettable = 'hs_booking.project'; """); // when @@ -73,9 +73,9 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea // then assertThat(customerLogEntries).map(Arrays::toString).contains( - "[creating booking-project test-data, hs_booking_project, INSERT, D-1000111 default project]", - "[creating booking-project test-data, hs_booking_project, INSERT, D-1000212 default project]", - "[creating booking-project test-data, hs_booking_project, INSERT, D-1000313 default project]"); + "[creating booking-project test-data, hs_booking.project, INSERT, D-1000111 default project]", + "[creating booking-project test-data, hs_booking.project, INSERT, D-1000212 default project]", + "[creating booking-project test-data, hs_booking.project, INSERT, D-1000313 default project]"); } @Test @@ -83,7 +83,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea // given final String nativeQuerySql = """ select count(*) - from hs_booking_project_hv ha; + from hs_booking.project_hv ha; """; // when @@ -92,7 +92,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea @SuppressWarnings("unchecked") final var countBefore = (Integer) query.getSingleResult(); // then - assertThat(countBefore).as("hs_booking_project_hv should not contain rows for a timestamp in the past").isEqualTo(0); + assertThat(countBefore).as("hs_booking.project_hv should not contain rows for a timestamp in the past").isEqualTo(0); // and when historicalContext(Timestamp.from(ZonedDateTime.now().plusHours(1).toInstant())); @@ -100,7 +100,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea @SuppressWarnings("unchecked") final var countAfter = (Integer) query.getSingleResult(); // then - assertThat(countAfter).as("hs_booking_project_hv should contain rows for a timestamp in the future").isGreaterThan(1); + assertThat(countAfter).as("hs_booking.project_hv should contain rows for a timestamp in the future").isGreaterThan(1); } @Nested @@ -152,33 +152,33 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea final var all = rawRoleRepo.findAll(); assertThat(distinctRoleNamesOf(all)).containsExactlyInAnyOrder(Array.from( initialRoleNames, - "hs_booking_project#D-1000111-somenewbookingproject:ADMIN", - "hs_booking_project#D-1000111-somenewbookingproject:AGENT", - "hs_booking_project#D-1000111-somenewbookingproject:OWNER", - "hs_booking_project#D-1000111-somenewbookingproject:TENANT")); + "hs_booking.project#D-1000111-somenewbookingproject:ADMIN", + "hs_booking.project#D-1000111-somenewbookingproject:AGENT", + "hs_booking.project#D-1000111-somenewbookingproject:OWNER", + "hs_booking.project#D-1000111-somenewbookingproject:TENANT")); assertThat(distinctGrantDisplaysOf(rawGrantRepo.findAll())) .map(s -> s.replace("hs_office.", "")) .containsExactlyInAnyOrder(fromFormatted( initialGrantNames, // rbacgGlobal-admin - "{ grant perm:hs_booking_project#D-1000111-somenewbookingproject:DELETE to role:rbac.global#global:ADMIN by system and assume }", + "{ grant perm:hs_booking.project#D-1000111-somenewbookingproject:DELETE to role:rbac.global#global:ADMIN by system and assume }", // owner - "{ grant role:hs_booking_project#D-1000111-somenewbookingproject:ADMIN to role:hs_booking_project#D-1000111-somenewbookingproject:OWNER by system and assume }", + "{ grant role:hs_booking.project#D-1000111-somenewbookingproject:ADMIN to role:hs_booking.project#D-1000111-somenewbookingproject:OWNER by system and assume }", // admin - "{ grant role:hs_booking_project#D-1000111-somenewbookingproject:AGENT to role:hs_booking_project#D-1000111-somenewbookingproject:ADMIN by system and assume }", - "{ grant perm:hs_booking_project#D-1000111-somenewbookingproject:UPDATE to role:hs_booking_project#D-1000111-somenewbookingproject:ADMIN by system and assume }", - "{ grant perm:hs_booking_project#D-1000111-somenewbookingproject:INSERT>hs_booking_item to role:hs_booking_project#D-1000111-somenewbookingproject:ADMIN by system and assume }", + "{ grant role:hs_booking.project#D-1000111-somenewbookingproject:AGENT to role:hs_booking.project#D-1000111-somenewbookingproject:ADMIN by system and assume }", + "{ grant perm:hs_booking.project#D-1000111-somenewbookingproject:UPDATE to role:hs_booking.project#D-1000111-somenewbookingproject:ADMIN by system and assume }", + "{ grant perm:hs_booking.project#D-1000111-somenewbookingproject:INSERT>hs_booking.item to role:hs_booking.project#D-1000111-somenewbookingproject:ADMIN by system and assume }", // agent - "{ grant role:hs_booking_project#D-1000111-somenewbookingproject:OWNER to role:relation#FirstGmbH-with-DEBITOR-FirstGmbH:AGENT by system }", - "{ grant role:hs_booking_project#D-1000111-somenewbookingproject:TENANT to role:hs_booking_project#D-1000111-somenewbookingproject:AGENT by system and assume }", + "{ grant role:hs_booking.project#D-1000111-somenewbookingproject:OWNER to role:relation#FirstGmbH-with-DEBITOR-FirstGmbH:AGENT by system }", + "{ grant role:hs_booking.project#D-1000111-somenewbookingproject:TENANT to role:hs_booking.project#D-1000111-somenewbookingproject:AGENT by system and assume }", // tenant - "{ grant role:relation#FirstGmbH-with-DEBITOR-FirstGmbH:TENANT to role:hs_booking_project#D-1000111-somenewbookingproject:TENANT by system and assume }", - "{ grant perm:hs_booking_project#D-1000111-somenewbookingproject:SELECT to role:hs_booking_project#D-1000111-somenewbookingproject:TENANT by system and assume }", + "{ grant role:relation#FirstGmbH-with-DEBITOR-FirstGmbH:TENANT to role:hs_booking.project#D-1000111-somenewbookingproject:TENANT by system and assume }", + "{ grant perm:hs_booking.project#D-1000111-somenewbookingproject:SELECT to role:hs_booking.project#D-1000111-somenewbookingproject:TENANT by system and assume }", null)); } @@ -214,7 +214,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea public void packetAgent_canViewOnlyRelatedBookingProjects(final TestCase testCase) { // given: - context("person-FirbySusan@example.com", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); + context("person-FirbySusan@example.com", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT"); final var debitorUuid = debitorRepo.findByDebitorNumber(1000111).stream() .findAny().orElseThrow().getUuid(); @@ -238,7 +238,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea // when final var result = jpaAttempt.transacted(() -> { - context("superuser-alex@hostsharing.net", "hs_booking_project#D-1000111-sometempproject:ADMIN"); + context("superuser-alex@hostsharing.net", "hs_booking.project#D-1000111-sometempproject:ADMIN"); final var foundBookingProject = em.find(HsBookingProjectRbacEntity.class, givenBookingProjectUuid); foundBookingProject.setCaption("updated caption"); return toCleanup(repoUnderTest(testCase).save(foundBookingProject)); @@ -290,7 +290,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea // when final var result = jpaAttempt.transacted(() -> { - context("person-FirbySusan@example.com", "hs_booking_project#D-1000111-sometempproject:AGENT"); + context("person-FirbySusan@example.com", "hs_booking.project#D-1000111-sometempproject:AGENT"); assertThat(rbacProjectRepo.findByUuid(givenBookingProject.getUuid())).isPresent(); repoUnderTest(TestCase.RBAC).deleteByUuid(givenBookingProject.getUuid()); @@ -299,7 +299,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea // then result.assertExceptionWithRootCauseMessage( JpaSystemException.class, - "[403] Subject ", " is not allowed to delete hs_booking_project"); + "[403] Subject ", " is not allowed to delete hs_booking.project"); assertThat(jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); return rbacProjectRepo.findByUuid(givenBookingProject.getUuid()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java index 92f1ee66..bc85266e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java @@ -454,7 +454,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup RestAssured // @formatter:off .given() .header("current-subject", "person-TuckerJack@example.com") - .header("assumed-roles", "hs_booking_project#D-1000313-D-1000313defaultproject:AGENT") + .header("assumed-roles", "hs_booking.project#D-1000313-D-1000313defaultproject:AGENT") .port(port) .when() .get("http://localhost/api/hs/hosting/assets/" + givenAssetUuid) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java index d408d241..b5cfcd33 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java @@ -167,7 +167,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu public void createsAndGrantsRoles() { // given // TODO.test: remove context(...) once all entities have real entities - context("superuser-alex@hostsharing.net", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); + context("superuser-alex@hostsharing.net", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT"); final var givenManagedServer = givenHostingAsset("D-1000111 default project", MANAGED_SERVER); final var newWebspaceBookingItem = newBookingItem(givenManagedServer.getBookingItem(), HsBookingItemType.MANAGED_WEBSPACE, "fir01"); em.flush(); @@ -175,7 +175,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu final var initialGrantNames = distinctGrantDisplaysOf(rawGrantRepo.findAll()); // when - context("superuser-alex@hostsharing.net", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); + context("superuser-alex@hostsharing.net", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT"); final var result = attempt(em, () -> { final var newAsset = HsHostingAssetRbacEntity.builder() .bookingItem(newWebspaceBookingItem) @@ -205,13 +205,13 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // owner "{ grant role:hs_hosting_asset#fir00:OWNER to user:superuser-alex@hostsharing.net by hs_hosting_asset#fir00:OWNER and assume }", - "{ grant role:hs_hosting_asset#fir00:OWNER to role:hs_booking_item#fir01:ADMIN by system and assume }", + "{ grant role:hs_hosting_asset#fir00:OWNER to role:hs_booking.item#fir01:ADMIN by system and assume }", "{ grant role:hs_hosting_asset#fir00:OWNER to role:hs_hosting_asset#vm1011:ADMIN by system and assume }", "{ grant perm:hs_hosting_asset#fir00:DELETE to role:hs_hosting_asset#fir00:OWNER by system and assume }", // admin "{ grant role:hs_hosting_asset#fir00:ADMIN to role:hs_hosting_asset#fir00:OWNER by system and assume }", - "{ grant role:hs_hosting_asset#fir00:ADMIN to role:hs_booking_item#fir01:AGENT by system and assume }", + "{ grant role:hs_hosting_asset#fir00:ADMIN to role:hs_booking.item#fir01:AGENT by system and assume }", "{ grant perm:hs_hosting_asset#fir00:UPDATE to role:hs_hosting_asset#fir00:ADMIN by system and assume }", // agent @@ -219,7 +219,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu "{ grant role:hs_hosting_asset#fir00:AGENT to role:hs_hosting_asset#fir00:ADMIN by system and assume }", // tenant - "{ grant role:hs_booking_item#fir01:TENANT to role:hs_hosting_asset#fir00:TENANT by system and assume }", + "{ grant role:hs_booking.item#fir01:TENANT to role:hs_hosting_asset#fir00:TENANT by system and assume }", "{ grant role:hs_hosting_asset#fir00:TENANT to role:hs_hosting_asset#fir00:AGENT by system and assume }", "{ grant role:hs_hosting_asset#vm1011:TENANT to role:hs_hosting_asset#fir00:TENANT by system and assume }", "{ grant perm:hs_hosting_asset#fir00:SELECT to role:hs_hosting_asset#fir00:TENANT by system and assume }", @@ -287,7 +287,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu @Test public void normalUser_canViewOnlyRelatedAssets() { // given: - context("person-FirbySusan@example.com", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); + context("person-FirbySusan@example.com", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT"); final var projectUuid = projectRepo.findByCaption("D-1000111 default project").stream() .findAny().orElseThrow().getUuid(); @@ -397,7 +397,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // when final var result = jpaAttempt.transacted(() -> { - context("person-FirbySusan@example.com", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); + context("person-FirbySusan@example.com", "hs_booking.project#D-1000111-D-1000111defaultproject:AGENT"); assertThat(rbacAssetRepo.findByUuid(givenAsset.getUuid())).isPresent(); rbacAssetRepo.deleteByUuid(givenAsset.getUuid()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java index 59f1d909..4f3c7f5f 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java @@ -250,10 +250,10 @@ public class CsvDataImport extends ContextBasedTest { // TODO.perf: could we instead skip creating test-data based on an env var? em.createNativeQuery("delete from hs_hosting_asset where true").executeUpdate(); em.createNativeQuery("delete from hs_hosting_asset_ex where true").executeUpdate(); - em.createNativeQuery("delete from hs_booking_item where true").executeUpdate(); - em.createNativeQuery("delete from hs_booking_item_ex where true").executeUpdate(); - em.createNativeQuery("delete from hs_booking_project where true").executeUpdate(); - em.createNativeQuery("delete from hs_booking_project_ex where true").executeUpdate(); + em.createNativeQuery("delete from hs_booking.item where true").executeUpdate(); + em.createNativeQuery("delete from hs_booking.item_ex where true").executeUpdate(); + em.createNativeQuery("delete from hs_booking.project where true").executeUpdate(); + em.createNativeQuery("delete from hs_booking.project_ex where true").executeUpdate(); em.createNativeQuery("delete from hs_office.coopassetstransaction where true").executeUpdate(); em.createNativeQuery("delete from hs_office.coopassetstransaction_legacy_id where true").executeUpdate(); em.createNativeQuery("delete from hs_office.coopsharestransaction where true").executeUpdate(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java index e8d510d9..a084d4f0 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java @@ -913,7 +913,7 @@ public class ImportHostingAssets extends BaseOfficeDataImport { @Test @Order(19910) void verifyBookingItemsAreActuallyPersisted() { - final var biCount = (Integer) em.createNativeQuery("select count(*) from hs_booking_item", Integer.class) + final var biCount = (Integer) em.createNativeQuery("select count(*) from hs_booking.item", Integer.class) .getSingleResult(); assertThat(biCount).isGreaterThan(isImportingControlledTestData() ? 5 : 500); } @@ -1068,7 +1068,7 @@ public class ImportHostingAssets extends BaseOfficeDataImport { assumeThatWeAreImportingControlledTestData(); final var haCount = jpaAttempt.transacted(() -> { - context(rbacSuperuser, "hs_booking_project#D-1000300-mimdefaultproject:AGENT"); + context(rbacSuperuser, "hs_booking.project#D-1000300-mimdefaultproject:AGENT"); return (Integer) em.createNativeQuery("select count(*) from hs_hosting_asset_rv where type='EMAIL_ADDRESS'", Integer.class) .getSingleResult(); }).assertSuccessful().returnedValue(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java index 53807d89..16cca312 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java @@ -185,7 +185,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean .containsExactlyInAnyOrder(Array.fromFormatted( initialGrantNames, "{ grant perm:relation#FirstGmbH-with-DEBITOR-FourtheG:INSERT>sepamandate to role:relation#FirstGmbH-with-DEBITOR-FourtheG:ADMIN by system and assume }", - "{ grant perm:relation#FirstGmbH-with-DEBITOR-FourtheG:INSERT>hs_booking_project to role:relation#FirstGmbH-with-DEBITOR-FourtheG:ADMIN by system and assume }", + "{ grant perm:relation#FirstGmbH-with-DEBITOR-FourtheG:INSERT>hs_booking.project to role:relation#FirstGmbH-with-DEBITOR-FourtheG:ADMIN by system and assume }", // owner "{ grant perm:debitor#D-1000122:DELETE to role:relation#FirstGmbH-with-DEBITOR-FourtheG:OWNER by system and assume }", diff --git a/src/test/java/net/hostsharing/hsadminng/rbac/test/ContextBasedTestWithCleanup.java b/src/test/java/net/hostsharing/hsadminng/rbac/test/ContextBasedTestWithCleanup.java index d0a5b861..1d2622a0 100644 --- a/src/test/java/net/hostsharing/hsadminng/rbac/test/ContextBasedTestWithCleanup.java +++ b/src/test/java/net/hostsharing/hsadminng/rbac/test/ContextBasedTestWithCleanup.java @@ -305,7 +305,7 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest { protected String[] roleNames(final String sqlLikeExpression) { final var pattern = Pattern.compile(sqlLikeExpression); //noinspection unchecked - final List rows = (List) em.createNativeQuery("select * from rbac.role_ev where roleidname like 'hs_booking_project#%'") + final List rows = (List) em.createNativeQuery("select * from rbac.role_ev where roleidname like 'hs_booking.project#%'") .getResultList(); return rows.stream() .map(row -> (row[0]).toString()) -- 2.39.5 From 87671f310ce7e1d402d5ad35efead3ec9c94b21a Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 18 Sep 2024 14:03:54 +0200 Subject: [PATCH 02/14] introduce separate database-schema for hs_hosting --- doc/rbac-performance-analysis.md | 20 ++--- sql/historization.sql | 14 +-- ...e-cte-experiments-for-accessible-uuids.sql | 38 ++++---- .../asset/HsHostingAssetRbacEntity.java | 2 +- .../asset/HsHostingAssetRbacRepository.java | 6 +- .../asset/HsHostingAssetRealEntity.java | 2 +- .../asset/HsHostingAssetRealRepository.java | 6 +- .../HsUnixUserHostingAssetValidator.java | 2 +- .../generator/InsertTriggerGenerator.java | 2 +- .../hsadminng/rbac/generator/RbacView.java | 2 +- .../630-booking-item/6300-hs-booking-item.sql | 6 +- .../6303-hs-booking-item-rbac.sql | 2 +- .../7-hs-hosting/700-hs-hosting-schema.sql | 8 ++ .../7010-hs-hosting-asset.sql | 46 +++++----- .../7013-hs-hosting-asset-rbac.sql | 48 +++++----- .../7016-hs-hosting-asset-migration.sql | 26 +++--- .../7018-hs-hosting-asset-test-data.sql | 4 +- .../changelog/9-hs-global/9000-statistics.sql | 4 +- .../db/changelog/db.changelog-master.yaml | 2 + ...sHostingAssetControllerAcceptanceTest.java | 6 +- ...HostingAssetRepositoryIntegrationTest.java | 90 +++++++++---------- ...UnixUserHostingAssetValidatorUnitTest.java | 2 +- .../hsadminng/hs/migration/CsvDataImport.java | 6 +- .../hs/migration/ImportHostingAssets.java | 16 ++-- 24 files changed, 185 insertions(+), 175 deletions(-) create mode 100644 src/main/resources/db/changelog/7-hs-hosting/700-hs-hosting-schema.sql diff --git a/doc/rbac-performance-analysis.md b/doc/rbac-performance-analysis.md index bc09371e..39037b8d 100644 --- a/doc/rbac-performance-analysis.md +++ b/doc/rbac-performance-analysis.md @@ -199,7 +199,7 @@ Limit (cost=6549.08..6549.35 rows=54 width=16) Group Key: grants.descendantuuid -> CTE Scan on grants (cost=0.00..22.06 rows=1103 width=16) -> Index Only Scan using rbacobject_objecttable_uuid_key on rbacobject obj (cost=0.28..0.31 rows=1 width=16) - Index Cond: ((objecttable = 'hs_hosting_asset'::text) AND (uuid = perm.objectuuid)) + Index Cond: ((objecttable = 'hs_hosting.asset'::text) AND (uuid = perm.objectuuid)) ``` ### Office-Relation-Query @@ -276,8 +276,8 @@ At this point, the import took 21mins with these statistics: | call rbac.grantRoleToRole(roleUuid, superRoleUuid, superRoleDesc.assumed) | 31316 | 0 | 1 | | call buildRbacSystemForHsHostingAsset(NEW) | 2258 | 0 | 7 | | select * from rbac.isGranted(array[granteeId], grantedId) | 44613 | 0 | 0 | -| insert into public.hs_hosting_asset_rv (alarmcontactuuid,assignedtoassetuuid,bookingitemuuid,caption,config,identifier,parentassetuuid,type,version,uuid) values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) | 2207 | 0 | 7 | -| insert into hs_hosting_asset (alarmcontactuuid, version, bookingitemuuid, type, parentassetuuid, assignedtoassetuuid, config, uuid, identifier, caption) values (new.alarmcontactuuid, new. version, new. bookingitemuuid, new. type, new. parentassetuuid, new. assignedtoassetuuid, new. config, new. uuid, new. identifier, new. caption) returning * | 2207 | 0 | 7 | +| insert into public.hs_hosting.asset_rv (alarmcontactuuid,assignedtoassetuuid,bookingitemuuid,caption,config,identifier,parentassetuuid,type,version,uuid) values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) | 2207 | 0 | 7 | +| insert into hs_hosting.asset (alarmcontactuuid, version, bookingitemuuid, type, parentassetuuid, assignedtoassetuuid, config, uuid, identifier, caption) values (new.alarmcontactuuid, new. version, new. bookingitemuuid, new. type, new. parentassetuuid, new. assignedtoassetuuid, new. config, new. uuid, new. identifier, new. caption) returning * | 2207 | 0 | 7 | | insert into public.hs_office.relation_rv (anchoruuid,contactuuid,holderuuid,mark,type,version,uuid) values ($1,$2,$3,$4,$5,$6,$7) | 1261 | 0 | 9 | | insert into hs_office.relation (uuid, version, anchoruuid, holderuuid, contactuuid, type, mark) values (new.uuid, new. version, new. anchoruuid, new. holderuuid, new. contactuuid, new. type, new. mark) returning * | 1261 | 0 | 9 | | call buildRbacSystemForHsOfficeRelation(NEW) | 1276 | 0 | 8 | @@ -300,8 +300,8 @@ We changed these mappings from `EAGER` (default) to `LAZY` to `@ManyToOne(fetch | call rbac.grantRoleToRole(roleUuid, superRoleUuid, superRoleDesc.assumed) | 31316 | 0 | 1 | | select * from rbac.isGranted(array[granteeId], grantedId) | 44613 | 0 | 0 | | call buildRbacSystemForHsHostingAsset(NEW) | 2258 | 0 | 7 | -| insert into public.hs_hosting_asset_rv (alarmcontactuuid,assignedtoassetuuid,bookingitemuuid,caption,config,identifier,parentassetuuid,type,version,uuid) values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) | 2207 | 0 | 7 | -| insert into hs_hosting_asset (alarmcontactuuid, version, bookingitemuuid, type, parentassetuuid, assignedtoassetuuid, config, uuid, identifier, caption) values (new.alarmcontactuuid, new. version, new. bookingitemuuid, new. type, new. parentassetuuid, new. assignedtoassetuuid, new. config, new. uuid, new. identifier, new. caption) returning * | 2207 | 0 | 7 | +| insert into public.hs_hosting.asset_rv (alarmcontactuuid,assignedtoassetuuid,bookingitemuuid,caption,config,identifier,parentassetuuid,type,version,uuid) values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) | 2207 | 0 | 7 | +| insert into hs_hosting.asset (alarmcontactuuid, version, bookingitemuuid, type, parentassetuuid, assignedtoassetuuid, config, uuid, identifier, caption) values (new.alarmcontactuuid, new. version, new. bookingitemuuid, new. type, new. parentassetuuid, new. assignedtoassetuuid, new. config, new. uuid, new. identifier, new. caption) returning * | 2207 | 0 | 7 | | with recursive grants as ( select descendantUuid, ascendantUuid from RbacGrants where descendantUuid = grantedId union all select ""grant"".descendantUuid, ""grant"".ascendantUuid from RbacGrants ""grant"" inner join grants recur on recur.ascendantUuid = ""grant"".descendantUuid ) select exists ( select $3 from grants where ascendantUuid = any(granteeIds) ) or grantedId = any(granteeIds) | 47538 | 0 | 0 | insert into public.hs_office.relation_rv (anchoruuid,contactuuid,holderuuid,mark,type,version,uuid) values ($1,$2,$3,$4,$5,$6,$7) | 1261 | 0 | 8 | | insert into hs_office.relation (uuid, version, anchoruuid, holderuuid, contactuuid, type, mark) values (new.uuid, new. version, new. anchoruuid, new. holderuuid, new. contactuuid, new. type, new. mark) returning * | 1261 | 0 | 8 | @@ -318,7 +318,7 @@ But once UnixUser and EmailAlias assets got added to the import, the total time This was not acceptable, especially not, considering that domains, email-addresses and database-assets are almost 10 times that number and thus the import would go up to over 1100min which is 20 hours. -In a first step, a `HsHostingAssetRawEntity` was created, mapped to the raw table (hs_hosting_asset) not to the RBAC-view (hs_hosting_asset_rv). Unfortunately we did not keep measurements, but that was only part of the problem anyway. +In a first step, a `HsHostingAssetRawEntity` was created, mapped to the raw table (hs_hosting.asset) not to the RBAC-view (hs_hosting.asset_rv). Unfortunately we did not keep measurements, but that was only part of the problem anyway. The main problem was, that there is something strange with persisting (`EntityManager.persist`) for EmailAlias assets. Where importing UnixUsers was mostly slow due to RBAC SELECT-permission checks, persisting EmailAliases suddenly created about a million (in numbers 1.000.000) SQL UPDATE statements after the INSERT, all with the same data, just increased version number (used for optimistic locking). We were not able to figure out why this happened. @@ -330,7 +330,7 @@ Now, the longest running queries are these: | No.| calls | total_m | mean_ms | query | |---:|---------|--------:|--------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| 1 | 13.093 | 4 | 21 | insert into hs_hosting_asset( uuid, type, bookingitemuuid, parentassetuuid, assignedtoassetuuid, alarmcontactuuid, identifier, caption, config, version) values ( $1, $2, $3, $4, $5, $6, $7, $8, cast($9 as jsonb), $10) | +| 1 | 13.093 | 4 | 21 | insert into hs_hosting.asset( uuid, type, bookingitemuuid, parentassetuuid, assignedtoassetuuid, alarmcontactuuid, identifier, caption, config, version) values ( $1, $2, $3, $4, $5, $6, $7, $8, cast($9 as jsonb), $10) | | 2 | 517 | 4 | 502 | select hore1_0.uuid,hore1_0.anchoruuid,hore1_0.contactuuid,hore1_0.holderuuid,hore1_0.mark,hore1_0.type,hore1_0.version from public.hs_office.relation_rv hore1_0 where hore1_0.uuid=$1 | | 3 | 13.144 | 4 | 21 | call buildRbacSystemForHsHostingAsset(NEW) | | 4 | 96.632 | 3 | 2 | call rbac.grantRoleToRole(roleUuid, superRoleUuid, superRoleDesc.assumed) | @@ -341,7 +341,7 @@ Now, the longest running queries are these: | 9 | 13.144 | 1 | 8 | SELECT createRoleWithGrants( hsHostingAssetTENANT(NEW), permissions => array[$7], incomingSuperRoles => array[ hsHostingAssetAGENT(NEW), hsOfficeContactADMIN(newAlarmContact)], outgoingSubRoles => array[ hsBookingItemTENANT(newBookingItem), hsHostingAssetTENANT(newParentAsset)] ) | | 10 | 13.144 | 1 | 5 | SELECT createRoleWithGrants( hsHostingAssetADMIN(NEW), permissions => array[$7], incomingSuperRoles => array[ hsBookingItemAGENT(newBookingItem), hsHostingAssetAGENT(newParentAsset), hsHostingAssetOWNER(NEW)] ) | -That the `INSERT into hs_hosting_asset` (No. 1) takes up the most time, seems to be normal, and 21ms for each call is also fine. +That the `INSERT into hs_hosting.asset` (No. 1) takes up the most time, seems to be normal, and 21ms for each call is also fine. It seems that the trigger effects (eg. No. 3 and No. 4) are included in the measure for the causing INSERT, otherwise summing up the totals would exceed the actual total time of the whole import. And it was to be expected that building the RBAC rules for new business objects takes most of the time. @@ -408,12 +408,12 @@ We found some solution approaches: This optimization idea came from Michael Hierweck and was promising. The idea is to reduce the size of the result of the recursive CTE query and maybe even speed up that query itself. -To evaluate this, I added a type column to the `rbacObject` table, initially as an enum hsHostingAssetType. Then I entered the type there for all rows from hs_hosting_asset. This means that 83,886 of 92,545 rows in `rbacobject` have a type set, leaving 8,659 without. +To evaluate this, I added a type column to the `rbacObject` table, initially as an enum hsHostingAssetType. Then I entered the type there for all rows from hs_hosting.asset. This means that 83,886 of 92,545 rows in `rbacobject` have a type set, leaving 8,659 without. If we do this for other types (we currently have 1,271 relations and 927 booking items), it gets more complicated because they are different enum types. As varchar(16), we could lose performance again due to the higher storage space requirements. But the performance gained is not particularly high anyway. -See the average seconds per recursive CTE select as role 'hs_hosting_asset:defaultproject:ADMIN', +See the average seconds per recursive CTE select as role 'hs_hosting.asset:defaultproject:ADMIN', joined with business query for all `'EMAIL_ADDRESSES'`: | | D-1000000-hsh | D-1000300-mih | diff --git a/sql/historization.sql b/sql/historization.sql index 622948c6..e96ce3de 100644 --- a/sql/historization.sql +++ b/sql/historization.sql @@ -10,17 +10,17 @@ call defineContext('historization testing', null, 'superuser-alex@hostsharing.ne 'hs_booking.project#D-1000313-D-1000313defaultproject:ADMIN'); -- prod+test -- 'hs_booking.project#D-1000300-mihdefaultproject:ADMIN'); -- prod -- 'hs_booking.project#D-1000300-mimdefaultproject:ADMIN'); -- test --- update hs_hosting_asset set caption='lug00 b' where identifier = 'lug00' and type = 'MANAGED_WEBSPACE'; -- prod --- update hs_hosting_asset set caption='hsh00 A ' || now()::text where identifier = 'hsh00' and type = 'MANAGED_WEBSPACE'; -- test --- update hs_hosting_asset set caption='hsh00 B ' || now()::text where identifier = 'hsh00' and type = 'MANAGED_WEBSPACE'; -- test +-- update hs_hosting.asset set caption='lug00 b' where identifier = 'lug00' and type = 'MANAGED_WEBSPACE'; -- prod +-- update hs_hosting.asset set caption='hsh00 A ' || now()::text where identifier = 'hsh00' and type = 'MANAGED_WEBSPACE'; -- test +-- update hs_hosting.asset set caption='hsh00 B ' || now()::text where identifier = 'hsh00' and type = 'MANAGED_WEBSPACE'; -- test --- insert into hs_hosting_asset +-- insert into hs_hosting.asset -- (uuid, bookingitemuuid, type, parentassetuuid, assignedtoassetuuid, identifier, caption, config, alarmcontactuuid) -- values -- (uuid_generate_v4(), null, 'EMAIL_ADDRESS', 'bbda5895-0569-4e20-bb4c-34f3a38f3f63'::uuid, null, -- 'new@thi.example.org', 'some new E-Mail-Address', '{}'::jsonb, null); -delete from hs_hosting_asset where uuid='5aea68d2-3b55-464f-8362-b05c76c5a681'::uuid; +delete from hs_hosting.asset where uuid='5aea68d2-3b55-464f-8362-b05c76c5a681'::uuid; commit; -- single version at point in time @@ -29,11 +29,11 @@ set hsadminng.tx_history_txid to ''; set hsadminng.tx_history_timestamp to '2024-08-29 12:42'; -- all versions select base.tx_history_txid(), txc.txtimestamp, txc.currentSubject, txc.currentTask, haex.* - from hs_hosting_asset_ex haex + from hs_hosting.asset_ex haex join base.tx_context txc on haex.txid=txc.txid where haex.identifier = 'test@thi.example.org'; -select uuid, version, type, identifier, caption from hs_hosting_asset_hv p where identifier = 'test@thi.example.org'; +select uuid, version, type, identifier, caption from hs_hosting.asset_hv p where identifier = 'test@thi.example.org'; select pg_current_xact_id(); diff --git a/sql/recursive-cte-experiments-for-accessible-uuids.sql b/sql/recursive-cte-experiments-for-accessible-uuids.sql index a484a6a0..bb86d6ec 100644 --- a/sql/recursive-cte-experiments-for-accessible-uuids.sql +++ b/sql/recursive-cte-experiments-for-accessible-uuids.sql @@ -6,10 +6,10 @@ select * from hs_statistics_v; -- This is the extracted recursive CTE query to determine the visible object UUIDs of a single table -- (and optionally the hosting-asset-type) as a separate VIEW. --- In the generated code this is part of the hs_hosting_asset_rv VIEW. +-- In the generated code this is part of the hs_hosting.asset_rv VIEW. -drop view if exists hs_hosting_asset_example_gv; -create view hs_hosting_asset_example_gv as +drop view if exists hs_hosting.asset_example_gv; +create view hs_hosting.asset_example_gv as with recursive recursive_grants as ( select distinct rbacgrants.descendantuuid, @@ -40,7 +40,7 @@ select distinct perm.objectuuid join rbacpermission perm on recursive_grants.descendantuuid = perm.uuid join rbacobject obj on obj.uuid = perm.objectuuid join count_check cc on cc.valid - where obj.objecttable::text = 'hs_hosting_asset'::text + where obj.objecttable::text = 'hs_hosting.asset'::text -- with/without this type condition -- and obj.type = 'EMAIL_ADDRESS'::hshostingassettype and obj.type = 'EMAIL_ADDRESS'::hshostingassettype @@ -56,7 +56,7 @@ CALL defineContext('performance testing', null, 'superuser-alex@hostsharing.net' 'hs_booking.project#D-1000000-hshdefaultproject:ADMIN'); -- 'hs_booking.project#D-1000300-mihdefaultproject:ADMIN'); SET TRANSACTION READ ONLY; -EXPLAIN ANALYZE select * from hs_hosting_asset_example_gv; +EXPLAIN ANALYZE select * from hs_hosting.asset_example_gv; end transaction ; -- ======================================================== @@ -64,15 +64,15 @@ end transaction ; -- An example for a restricted view (_rv) similar to the one generated by our RBAC system, -- but using the above separate VIEW to determine the visible objects. -drop view if exists hs_hosting_asset_example_rv; -create view hs_hosting_asset_example_rv as - with accessible_hs_hosting_asset_uuids as ( - select * from hs_hosting_asset_example_gv +drop view if exists hs_hosting.asset_example_rv; +create view hs_hosting.asset_example_rv as + with accessible_hs_hosting.asset_uuids as ( + select * from hs_hosting.asset_example_gv ) select target.* - from hs_hosting_asset target - where (target.uuid in (select accessible_hs_hosting_asset_uuids.objectuuid - from accessible_hs_hosting_asset_uuids)); + from hs_hosting.asset target + where (target.uuid in (select accessible_hs_hosting.asset_uuids.objectuuid + from accessible_hs_hosting.asset_uuids)); -- ------------------------------------------------------------------------------- @@ -99,7 +99,7 @@ BEGIN -- An example for a business query based on the view: select type, uuid, identifier, caption - from hs_hosting_asset_example_rv + from hs_hosting.asset_example_rv where type = 'EMAIL_ADDRESS' and identifier like letter || '%' -- end of the business query example. @@ -115,7 +115,7 @@ BEGIN END; $$; --- average seconds per recursive CTE select as role 'hs_hosting_asset:defaultproject:ADMIN' +-- average seconds per recursive CTE select as role 'hs_hosting.asset:defaultproject:ADMIN' -- joined with business query for all 'EMAIL_ADDRESSES': -- D-1000000-hsh D-1000300-mih -- - without type comparison in rbacobject: ~3.30 - ~3.49 ~0.23 @@ -136,7 +136,7 @@ EXPLAIN SELECT * from ( -- An example for a business query based on the view: select type, uuid, identifier, caption - from hs_hosting_asset_example_rv + from hs_hosting.asset_example_rv where type = 'EMAIL_ADDRESS' -- and identifier like 'b%' -- end of the business query example. @@ -151,17 +151,17 @@ end transaction; alter table rbacobject -- just for performance testing, we would need a joined enum or a varchar(16) which would make it slow - add column type hshostingassettype; + add column type hs_hosting.hshostingassettype; --- and fill the type column with hs_hosting_asset types: +-- and fill the type column with hs_hosting.asset types: rollback transaction; begin transaction; -call defineContext('setting rbacobject.type from hs_hosting_asset.type', null, 'superuser-alex@hostsharing.net'); +call defineContext('setting rbacobject.type from hs_hosting.asset.type', null, 'superuser-alex@hostsharing.net'); UPDATE rbacobject SET type = hs.type - FROM hs_hosting_asset hs + FROM hs_hosting.asset hs WHERE rbacobject.uuid = hs.uuid; end transaction; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacEntity.java index 4858f0e9..a7f48eb3 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacEntity.java @@ -33,7 +33,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.directlyFetc import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; @Entity -@Table(name = "hs_hosting_asset_rv") +@Table(schema = "hs_hosting", name = "asset_rv") @SuperBuilder(toBuilder = true) @Getter @Setter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacRepository.java index d7a012a7..73050383 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacRepository.java @@ -25,15 +25,15 @@ public interface HsHostingAssetRbacRepository extends HsHostingAssetRepository findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type); default List findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) { return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type)); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealEntity.java index a586f245..00a77980 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealEntity.java @@ -9,7 +9,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.Table; @Entity -@Table(name = "hs_hosting_asset") +@Table(schema = "hs_hosting", name = "asset") @SuperBuilder(builderMethodName = "genericBuilder", toBuilder = true) @Getter @Setter diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java index a9b0cc5a..1e177524 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java @@ -24,15 +24,15 @@ public interface HsHostingAssetRealRepository extends HsHostingAssetRepository findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type); default List findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) { return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type)); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java index a53b536f..024866c2 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java @@ -53,7 +53,7 @@ class HsUnixUserHostingAssetValidator extends HostingAssetEntityValidator { } private static Integer computeUserId(final EntityManager em, final PropertiesProvider propertiesProvider) { - final Object result = em.createNativeQuery("SELECT nextval('hs_hosting_asset_unixuser_system_id_seq')", Integer.class) + final Object result = em.createNativeQuery("SELECT nextval('hs_hosting.asset_unixuser_system_id_seq')", Integer.class) .getSingleResult(); return (Integer) result; } diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java b/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java index 5c398da2..1654bbc7 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java @@ -89,7 +89,7 @@ public class InsertTriggerGenerator { with("superRoleRef", toRoleDescriptor(g.getSuperRoleDef(), "row"))); } else { plPgSql.writeLn(""" - -- Granting INSERT INTO hs_hosting_asset permissions to specified role of pre-existing hs_hosting_asset rows slipped, + -- Granting INSERT INTO hs_hosting.asset permissions to specified role of pre-existing hs_hosting.asset rows slipped, -- because there cannot yet be any pre-existing rows in the same table yet. """, with("rawSuperTable", g.getSuperRoleDef().getEntityAlias().getRawTableNameWithSchema()), diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java index 2219972b..2c2d339a 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java @@ -987,7 +987,7 @@ public class RbacView { return getRawTableName() .replace("hs_office.", "hsof.") .replace("hs_booking.", "hsbk_") - .replace("hs_hosting_", "hsho_") + .replace("hs_hosting.", "hsho_") .replace("coopsharestransaction", "coopsharetx") .replace("coopassetstransaction", "coopassettx"); } diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql index 8a744614..ad56e436 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:booking-item-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -create type HsBookingItemType as enum ( +create type hs_booking.HsBookingItemType as enum ( 'PRIVATE_CLOUD', 'CLOUD_SERVER', 'MANAGED_SERVER', @@ -12,14 +12,14 @@ create type HsBookingItemType as enum ( 'DOMAIN_SETUP' ); -CREATE CAST (character varying as HsBookingItemType) WITH INOUT AS IMPLICIT; +CREATE CAST (character varying as hs_booking.HsBookingItemType) WITH INOUT AS IMPLICIT; create table if not exists hs_booking.item ( uuid uuid unique references rbac.object (uuid), version int not null default 0, projectUuid uuid null references hs_booking.project(uuid), - type HsBookingItemType not null, + type hs_booking.HsBookingItemType not null, parentItemUuid uuid null references hs_booking.item(uuid) initially deferred, validity daterange not null, caption varchar(80) not null, diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql index f0e692b9..f357da1f 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql @@ -186,7 +186,7 @@ execute procedure hs_booking.new_item_grants_insert_to_project_tf(); -- granting INSERT permission to hs_booking.item ---------------------------- --- Granting INSERT INTO hs_hosting_asset permissions to specified role of pre-existing hs_hosting_asset rows slipped, +-- Granting INSERT INTO hs_hosting.asset permissions to specified role of pre-existing hs_hosting.asset rows slipped, -- because there cannot yet be any pre-existing rows in the same table yet. /** diff --git a/src/main/resources/db/changelog/7-hs-hosting/700-hs-hosting-schema.sql b/src/main/resources/db/changelog/7-hs-hosting/700-hs-hosting-schema.sql new file mode 100644 index 00000000..ff20294d --- /dev/null +++ b/src/main/resources/db/changelog/7-hs-hosting/700-hs-hosting-schema.sql @@ -0,0 +1,8 @@ +--liquibase formatted sql + + +-- ============================================================================ +--changeset michael.hoennig:hs-hosting-SCHEMA endDelimiter:--// +-- ---------------------------------------------------------------------------- +CREATE SCHEMA hs_hosting; +--// diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql index c21a6602..30b4b79a 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:hosting-asset-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -create type HsHostingAssetType as enum ( +create type hs_hosting.HsHostingAssetType as enum ( 'CLOUD_SERVER', 'MANAGED_SERVER', 'MANAGED_WEBSPACE', @@ -26,22 +26,22 @@ create type HsHostingAssetType as enum ( 'IPV6_NUMBER' ); -CREATE CAST (character varying as HsHostingAssetType) WITH INOUT AS IMPLICIT; +CREATE CAST (character varying as hs_hosting.HsHostingAssetType) WITH INOUT AS IMPLICIT; -create table if not exists hs_hosting_asset +create table if not exists hs_hosting.asset ( uuid uuid unique references rbac.object (uuid), version int not null default 0, bookingItemUuid uuid null references hs_booking.item(uuid), - type HsHostingAssetType not null, - parentAssetUuid uuid null references hs_hosting_asset(uuid) initially deferred, - assignedToAssetUuid uuid null references hs_hosting_asset(uuid) initially deferred, + type hs_hosting.HsHostingAssetType not null, + parentAssetUuid uuid null references hs_hosting.asset(uuid) initially deferred, + assignedToAssetUuid uuid null references hs_hosting.asset(uuid) initially deferred, identifier varchar(80) not null, caption varchar(80), config jsonb not null, alarmContactUuid uuid null references hs_office.contact(uuid) initially deferred, - constraint chk_hs_hosting_asset_has_booking_item_or_parent_asset + constraint hosting_asset_has_booking_item_or_parent_asset check (bookingItemUuid is not null or parentAssetUuid is not null or type in ('DOMAIN_SETUP', 'IPV4_NUMBER', 'IPV6_NUMBER')) ); --// @@ -54,16 +54,16 @@ create table if not exists hs_hosting_asset -- TODO.impl: this could be generated from HsHostingAssetType -- also including a check for assignedToAssetUuud -create or replace function hs_hosting_asset_type_hierarchy_check_tf() +create or replace function hs_hosting.asset_type_hierarchy_check_tf() returns trigger language plpgsql as $$ declare - actualParentType HsHostingAssetType; - expectedParentType HsHostingAssetType; + actualParentType hs_hosting.HsHostingAssetType; + expectedParentType hs_hosting.HsHostingAssetType; begin if NEW.parentAssetUuid is not null then actualParentType := (select type - from hs_hosting_asset + from hs_hosting.asset where NEW.parentAssetUuid = uuid); end if; @@ -104,10 +104,10 @@ begin return NEW; end; $$; -create trigger hs_hosting_asset_type_hierarchy_check_tg - before insert on hs_hosting_asset +create trigger hosting_asset_type_hierarchy_check_tg + before insert on hs_hosting.asset for each row - execute procedure hs_hosting_asset_type_hierarchy_check_tf(); + execute procedure hs_hosting.asset_type_hierarchy_check_tf(); --// @@ -116,7 +116,7 @@ create trigger hs_hosting_asset_type_hierarchy_check_tg --changeset michael.hoennig:hosting-asset-system-sequences endDelimiter:--// -- ---------------------------------------------------------------------------- -CREATE SEQUENCE IF NOT EXISTS hs_hosting_asset_unixuser_system_id_seq +CREATE SEQUENCE IF NOT EXISTS hs_hosting.asset_unixuser_system_id_seq AS integer MINVALUE 1000000 MAXVALUE 9999999 @@ -130,12 +130,12 @@ CREATE SEQUENCE IF NOT EXISTS hs_hosting_asset_unixuser_system_id_seq --changeset michael.hoennig:hosting-asset-BOOKING-ITEM-HIERARCHY-CHECK endDelimiter:--// -- ---------------------------------------------------------------------------- -create or replace function hs_hosting_asset_booking_item_hierarchy_check_tf() +create or replace function hs_hosting.asset_booking_item_hierarchy_check_tf() returns trigger language plpgsql as $$ declare - actualBookingItemType HsBookingItemType; - expectedBookingItemType HsBookingItemType; + actualBookingItemType hs_booking.HsBookingItemType; + expectedBookingItemType hs_booking.HsBookingItemType; begin actualBookingItemType := (select type from hs_booking.item @@ -156,24 +156,24 @@ begin return NEW; end; $$; -create trigger hs_hosting_asset_booking_item_hierarchy_check_tg - before insert on hs_hosting_asset +create trigger hosting_asset_booking_item_hierarchy_check_tg + before insert on hs_hosting.asset for each row -execute procedure hs_hosting_asset_booking_item_hierarchy_check_tf(); +execute procedure hs_hosting.asset_booking_item_hierarchy_check_tf(); --// -- ============================================================================ --changeset michael.hoennig:hs-hosting-asset-MAIN-TABLE-JOURNAL endDelimiter:--// -- ---------------------------------------------------------------------------- -call base.create_journal('hs_hosting_asset'); +call base.create_journal('hs_hosting.asset'); --// -- ============================================================================ --changeset michael.hoennig:hs-hosting-asset-MAIN-TABLE-HISTORIZATION endDelimiter:--// -- ---------------------------------------------------------------------------- -call base.tx_create_historicization('hs_hosting_asset'); +call base.tx_create_historicization('hs_hosting.asset'); --// diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql index fa04eddc..2c739bf5 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql @@ -5,14 +5,14 @@ -- ============================================================================ --changeset RbacObjectGenerator:hs-hosting-asset-rbac-OBJECT endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRelatedRbacObject('hs_hosting_asset'); +call rbac.generateRelatedRbacObject('hs_hosting.asset'); --// -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:hs-hosting-asset-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRoleDescriptors('hsHostingAsset', 'hs_hosting_asset'); +call rbac.generateRbacRoleDescriptors('hsHostingAsset', 'hs_hosting.asset'); --// @@ -24,27 +24,27 @@ call rbac.generateRbacRoleDescriptors('hsHostingAsset', 'hs_hosting_asset'); Creates the roles, grants and permission for the AFTER INSERT TRIGGER. */ -create or replace procedure hs_hosting_asset_build_rbac_system( - NEW hs_hosting_asset +create or replace procedure hs_hosting.asset_build_rbac_system( + NEW hs_hosting.asset ) language plpgsql as $$ declare newBookingItem hs_booking.item; - newAssignedToAsset hs_hosting_asset; + newAssignedToAsset hs_hosting.asset; newAlarmContact hs_office.contact; - newParentAsset hs_hosting_asset; + newParentAsset hs_hosting.asset; begin call rbac.enterTriggerForObjectUuid(NEW.uuid); SELECT * FROM hs_booking.item WHERE uuid = NEW.bookingItemUuid INTO newBookingItem; - SELECT * FROM hs_hosting_asset WHERE uuid = NEW.assignedToAssetUuid INTO newAssignedToAsset; + SELECT * FROM hs_hosting.asset WHERE uuid = NEW.assignedToAssetUuid INTO newAssignedToAsset; SELECT * FROM hs_office.contact WHERE uuid = NEW.alarmContactUuid INTO newAlarmContact; - SELECT * FROM hs_hosting_asset WHERE uuid = NEW.parentAssetUuid INTO newParentAsset; + SELECT * FROM hs_hosting.asset WHERE uuid = NEW.parentAssetUuid INTO newParentAsset; perform rbac.defineRoleWithGrants( hsHostingAssetOWNER(NEW), @@ -93,22 +93,22 @@ begin end; $$; /* - AFTER INSERT TRIGGER to create the role+grant structure for a new hs_hosting_asset row. + AFTER INSERT TRIGGER to create the role+grant structure for a new hs_hosting.asset row. */ -create or replace function hs_hosting_asset_build_rbac_system_after_insert_tf() +create or replace function hs_hosting.asset_build_rbac_system_after_insert_tf() returns trigger language plpgsql strict as $$ begin - call hs_hosting_asset_build_rbac_system(NEW); + call hs_hosting.asset_build_rbac_system(NEW); return NEW; end; $$; create trigger build_rbac_system_after_insert_tg - after insert on hs_hosting_asset + after insert on hs_hosting.asset for each row -execute procedure hs_hosting_asset_build_rbac_system_after_insert_tf(); +execute procedure hs_hosting.asset_build_rbac_system_after_insert_tf(); --// @@ -120,9 +120,9 @@ execute procedure hs_hosting_asset_build_rbac_system_after_insert_tf(); Called from the AFTER UPDATE TRIGGER to re-wire the grants. */ -create or replace procedure hs_hosting_asset_update_rbac_system( - OLD hs_hosting_asset, - NEW hs_hosting_asset +create or replace procedure hs_hosting.asset_update_rbac_system( + OLD hs_hosting.asset, + NEW hs_hosting.asset ) language plpgsql as $$ begin @@ -130,27 +130,27 @@ begin if NEW.assignedToAssetUuid is distinct from OLD.assignedToAssetUuid or NEW.alarmContactUuid is distinct from OLD.alarmContactUuid then delete from rbac.grants g where g.grantedbytriggerof = OLD.uuid; - call hs_hosting_asset_build_rbac_system(NEW); + call hs_hosting.asset_build_rbac_system(NEW); end if; end; $$; /* - AFTER UPDATE TRIGGER to re-wire the grant structure for a new hs_hosting_asset row. + AFTER UPDATE TRIGGER to re-wire the grant structure for a new hs_hosting.asset row. */ -create or replace function hs_hosting_asset_update_rbac_system_after_update_tf() +create or replace function hs_hosting.asset_update_rbac_system_after_update_tf() returns trigger language plpgsql strict as $$ begin - call hs_hosting_asset_update_rbac_system(OLD, NEW); + call hs_hosting.asset_update_rbac_system(OLD, NEW); return NEW; end; $$; create trigger update_rbac_system_after_update_tg - after update on hs_hosting_asset + after update on hs_hosting.asset for each row -execute procedure hs_hosting_asset_update_rbac_system_after_update_tf(); +execute procedure hs_hosting.asset_update_rbac_system_after_update_tf(); --// @@ -158,7 +158,7 @@ execute procedure hs_hosting_asset_update_rbac_system_after_update_tf(); --changeset RbacIdentityViewGenerator:hs-hosting-asset-rbac-IDENTITY-VIEW endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacIdentityViewFromProjection('hs_hosting_asset', +call rbac.generateRbacIdentityViewFromProjection('hs_hosting.asset', $idName$ identifier $idName$); @@ -168,7 +168,7 @@ call rbac.generateRbacIdentityViewFromProjection('hs_hosting_asset', -- ============================================================================ --changeset RbacRestrictedViewGenerator:hs-hosting-asset-rbac-RESTRICTED-VIEW endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRestrictedView('hs_hosting_asset', +call rbac.generateRbacRestrictedView('hs_hosting.asset', $orderBy$ identifier $orderBy$, diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7016-hs-hosting-asset-migration.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7016-hs-hosting-asset-migration.sql index 9ce96e72..1aff9f5e 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7016-hs-hosting-asset-migration.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7016-hs-hosting-asset-migration.sql @@ -7,9 +7,9 @@ --changeset hs-hosting-asset-MIGRATION-mapping:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -CREATE TABLE hs_hosting_asset_legacy_id +CREATE TABLE hs_hosting.asset_legacy_id ( - uuid uuid NOT NULL REFERENCES hs_hosting_asset(uuid), + uuid uuid NOT NULL REFERENCES hs_hosting.asset(uuid), legacy_id integer NOT NULL ); --// @@ -19,10 +19,10 @@ CREATE TABLE hs_hosting_asset_legacy_id --changeset hs-hosting-asset-MIGRATION-sequence:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -CREATE SEQUENCE IF NOT EXISTS hs_hosting_asset_legacy_id_seq +CREATE SEQUENCE IF NOT EXISTS hs_hosting.asset_legacy_id_seq AS integer START 1000000000 - OWNED BY hs_hosting_asset_legacy_id.legacy_id; + OWNED BY hs_hosting.asset_legacy_id.legacy_id; --// @@ -30,9 +30,9 @@ CREATE SEQUENCE IF NOT EXISTS hs_hosting_asset_legacy_id_seq --changeset hs-hosting-asset-MIGRATION-default:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -ALTER TABLE hs_hosting_asset_legacy_id +ALTER TABLE hs_hosting.asset_legacy_id ALTER COLUMN legacy_id - SET DEFAULT nextVal('hs_hosting_asset_legacy_id_seq'); + SET DEFAULT nextVal('hs_hosting.asset_legacy_id_seq'); --/ @@ -41,8 +41,8 @@ ALTER TABLE hs_hosting_asset_legacy_id -- ---------------------------------------------------------------------------- CALL base.defineContext('schema-migration'); -INSERT INTO hs_hosting_asset_legacy_id(uuid, legacy_id) - SELECT uuid, nextVal('hs_hosting_asset_legacy_id_seq') FROM hs_hosting_asset; +INSERT INTO hs_hosting.asset_legacy_id(uuid, legacy_id) + SELECT uuid, nextVal('hs_hosting.asset_legacy_id_seq') FROM hs_hosting.asset; --/ @@ -58,14 +58,14 @@ begin raise exception 'invalid usage of trigger'; end if; - INSERT INTO hs_hosting_asset_legacy_id VALUES - (NEW.uuid, nextVal('hs_hosting_asset_legacy_id_seq')); + INSERT INTO hs_hosting.asset_legacy_id VALUES + (NEW.uuid, nextVal('hs_hosting.asset_legacy_id_seq')); return NEW; end; $$; create trigger createassetLegacyIdMapping - after insert on hs_hosting_asset + after insert on hs_hosting.asset for each row execute procedure insertassetLegacyIdMapping(); --/ @@ -83,14 +83,14 @@ begin raise exception 'invalid usage of trigger'; end if; - DELETE FROM hs_hosting_asset_legacy_id + DELETE FROM hs_hosting.asset_legacy_id WHERE uuid = OLD.uuid; return OLD; end; $$; create trigger deleteassetLegacyIdMapping_tg - before delete on hs_hosting_asset + before delete on hs_hosting.asset for each row execute procedure deleteassetLegacyIdMapping_tf(); --/ diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql index 0506c67c..72f6527d 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql @@ -6,7 +6,7 @@ -- ---------------------------------------------------------------------------- /* - Creates a single hs_hosting_asset test record. + Creates a single hs_hosting.asset test record. */ create or replace procedure createHsHostingAssetTestData(givenProjectCaption varchar) language plpgsql as $$ @@ -79,7 +79,7 @@ begin debitorNumberSuffix := relatedDebitor.debitorNumberSuffix; defaultPrefix := relatedDebitor.defaultPrefix; - insert into hs_hosting_asset + insert into hs_hosting.asset (uuid, bookingitemuuid, type, parentAssetUuid, assignedToAssetUuid, identifier, caption, config) values (managedServerUuid, managedServerBI.uuid, 'MANAGED_SERVER', null, null, 'vm10' || debitorNumberSuffix, 'some ManagedServer', '{ "monit_max_cpu_usage": 90, "monit_max_ram_usage": 80, "monit_max_ssd_usage": 70 }'::jsonb), diff --git a/src/main/resources/db/changelog/9-hs-global/9000-statistics.sql b/src/main/resources/db/changelog/9-hs-global/9000-statistics.sql index 6d3e3c53..8d64948d 100644 --- a/src/main/resources/db/changelog/9-hs-global/9000-statistics.sql +++ b/src/main/resources/db/changelog/9-hs-global/9000-statistics.sql @@ -12,8 +12,8 @@ select * from rbac.object group by objecttable union all - select to_char(count(*)::int, '9 999 999 999'), 'objects', 'hs_hosting_asset', type::text - from hs_hosting_asset + select to_char(count(*)::int, '9 999 999 999'), 'objects', 'hs_hosting.asset', type::text + from hs_hosting.asset group by type union all select to_char(count(*)::int, '9 999 999 999'), 'objects', 'hs_booking.item', type::text diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index cad1e16c..78622a51 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -159,6 +159,8 @@ databaseChangeLog: file: db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql - include: file: db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql + - include: + file: db/changelog/7-hs-hosting/700-hs-hosting-schema.sql - include: file: db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql - include: diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java index bc85266e..6f2d42d4 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java @@ -114,7 +114,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup RestAssured // @formatter:off .given() .header("current-subject", "superuser-alex@hostsharing.net") - .header("assumed-roles", "hs_hosting_asset#fir01:AGENT") + .header("assumed-roles", "hs_hosting.asset#fir01:AGENT") .port(port) .when() . get("http://localhost/api/hs/hosting/assets?type=" + EMAIL_ALIAS) @@ -218,7 +218,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup final var location = RestAssured // @formatter:off .given() .header("current-subject", "superuser-alex@hostsharing.net") - .header("assumed-roles", "hs_hosting_asset#vm1011:ADMIN") + .header("assumed-roles", "hs_hosting.asset#vm1011:ADMIN") .contentType(ContentType.JSON) .body(""" { @@ -574,7 +574,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup RestAssured // @formatter:off .given() .header("current-subject", "superuser-alex@hostsharing.net") - //.header("assumed-roles", "hs_hosting_asset#vm2001:ADMIN") + //.header("assumed-roles", "hs_hosting.asset#vm2001:ADMIN") .contentType(ContentType.JSON) .body(""" { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java index b5cfcd33..e04591c7 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java @@ -78,7 +78,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu final var query = em.createNativeQuery(""" select currentTask, targetTable, targetOp, targetdelta->>'caption' from base.tx_journal_v - where targettable = 'hs_hosting_asset'; + where targettable = 'hs_hosting.asset'; """); // when @@ -86,24 +86,24 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // then assertThat(customerLogEntries).map(Arrays::toString).contains( - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, another CloudServer]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some Domain-DNS-Setup]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some Domain-HTTP-Setup]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some Domain-MBOX-Setup]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some Domain-SMTP-Setup]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some Domain-Setup]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some E-Mail-Address]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some E-Mail-Alias]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some ManagedServer]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some UnixUser for E-Mail]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some UnixUser for Website]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some Webspace]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some default MariaDB instance]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some default MariaDB user]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some default MariaDB database]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some default Postgresql instance]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some default Postgresql user]", - "[creating hosting-asset test-data, hs_hosting_asset, INSERT, some default Postgresql database]" + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, another CloudServer]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some Domain-DNS-Setup]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some Domain-HTTP-Setup]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some Domain-MBOX-Setup]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some Domain-SMTP-Setup]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some Domain-Setup]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some E-Mail-Address]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some E-Mail-Alias]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some ManagedServer]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some UnixUser for E-Mail]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some UnixUser for Website]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some Webspace]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some default MariaDB instance]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some default MariaDB user]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some default MariaDB database]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some default Postgresql instance]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some default Postgresql user]", + "[creating hosting-asset test-data, hs_hosting.asset, INSERT, some default Postgresql database]" ); } @@ -112,7 +112,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // given final String nativeQuerySql = """ select count(*) - from hs_hosting_asset_hv ha; + from hs_hosting.asset_hv ha; """; // when @@ -121,7 +121,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu @SuppressWarnings("unchecked") final var countBefore = (Integer) query.getSingleResult(); // then - assertThat(countBefore).as("hs_hosting_asset_hv should not contain rows for a timestamp in the past").isEqualTo(0); + assertThat(countBefore).as("hs_hosting.asset_hv should not contain rows for a timestamp in the past").isEqualTo(0); // and when historicalContext(Timestamp.from(ZonedDateTime.now().plusHours(1).toInstant())); @@ -129,7 +129,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu @SuppressWarnings("unchecked") final var countAfter = (Integer) query.getSingleResult(); // then - assertThat(countAfter).as("hs_hosting_asset_hv should contain rows for a timestamp in the future").isGreaterThan(1); + assertThat(countAfter).as("hs_hosting.asset_hv should contain rows for a timestamp in the future").isGreaterThan(1); } @Nested @@ -192,37 +192,37 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu final var all = rawRoleRepo.findAll(); assertThat(distinctRoleNamesOf(all)).containsExactlyInAnyOrder(Array.from( initialRoleNames, - "hs_hosting_asset#fir00:ADMIN", - "hs_hosting_asset#fir00:AGENT", - "hs_hosting_asset#fir00:OWNER", - "hs_hosting_asset#fir00:TENANT")); + "hs_hosting.asset#fir00:ADMIN", + "hs_hosting.asset#fir00:AGENT", + "hs_hosting.asset#fir00:OWNER", + "hs_hosting.asset#fir00:TENANT")); assertThat(distinctGrantDisplaysOf(rawGrantRepo.findAll())) .containsExactlyInAnyOrder(fromFormatted( initialGrantNames, // rbac.global-admin - "{ grant role:hs_hosting_asset#fir00:OWNER to role:rbac.global#global:ADMIN by system }", // workaround + "{ grant role:hs_hosting.asset#fir00:OWNER to role:rbac.global#global:ADMIN by system }", // workaround // owner - "{ grant role:hs_hosting_asset#fir00:OWNER to user:superuser-alex@hostsharing.net by hs_hosting_asset#fir00:OWNER and assume }", - "{ grant role:hs_hosting_asset#fir00:OWNER to role:hs_booking.item#fir01:ADMIN by system and assume }", - "{ grant role:hs_hosting_asset#fir00:OWNER to role:hs_hosting_asset#vm1011:ADMIN by system and assume }", - "{ grant perm:hs_hosting_asset#fir00:DELETE to role:hs_hosting_asset#fir00:OWNER by system and assume }", + "{ grant role:hs_hosting.asset#fir00:OWNER to user:superuser-alex@hostsharing.net by hs_hosting.asset#fir00:OWNER and assume }", + "{ grant role:hs_hosting.asset#fir00:OWNER to role:hs_booking.item#fir01:ADMIN by system and assume }", + "{ grant role:hs_hosting.asset#fir00:OWNER to role:hs_hosting.asset#vm1011:ADMIN by system and assume }", + "{ grant perm:hs_hosting.asset#fir00:DELETE to role:hs_hosting.asset#fir00:OWNER by system and assume }", // admin - "{ grant role:hs_hosting_asset#fir00:ADMIN to role:hs_hosting_asset#fir00:OWNER by system and assume }", - "{ grant role:hs_hosting_asset#fir00:ADMIN to role:hs_booking.item#fir01:AGENT by system and assume }", - "{ grant perm:hs_hosting_asset#fir00:UPDATE to role:hs_hosting_asset#fir00:ADMIN by system and assume }", + "{ grant role:hs_hosting.asset#fir00:ADMIN to role:hs_hosting.asset#fir00:OWNER by system and assume }", + "{ grant role:hs_hosting.asset#fir00:ADMIN to role:hs_booking.item#fir01:AGENT by system and assume }", + "{ grant perm:hs_hosting.asset#fir00:UPDATE to role:hs_hosting.asset#fir00:ADMIN by system and assume }", // agent - "{ grant role:hs_hosting_asset#fir00:ADMIN to role:hs_hosting_asset#vm1011:AGENT by system and assume }", - "{ grant role:hs_hosting_asset#fir00:AGENT to role:hs_hosting_asset#fir00:ADMIN by system and assume }", + "{ grant role:hs_hosting.asset#fir00:ADMIN to role:hs_hosting.asset#vm1011:AGENT by system and assume }", + "{ grant role:hs_hosting.asset#fir00:AGENT to role:hs_hosting.asset#fir00:ADMIN by system and assume }", // tenant - "{ grant role:hs_booking.item#fir01:TENANT to role:hs_hosting_asset#fir00:TENANT by system and assume }", - "{ grant role:hs_hosting_asset#fir00:TENANT to role:hs_hosting_asset#fir00:AGENT by system and assume }", - "{ grant role:hs_hosting_asset#vm1011:TENANT to role:hs_hosting_asset#fir00:TENANT by system and assume }", - "{ grant perm:hs_hosting_asset#fir00:SELECT to role:hs_hosting_asset#fir00:TENANT by system and assume }", + "{ grant role:hs_booking.item#fir01:TENANT to role:hs_hosting.asset#fir00:TENANT by system and assume }", + "{ grant role:hs_hosting.asset#fir00:TENANT to role:hs_hosting.asset#fir00:AGENT by system and assume }", + "{ grant role:hs_hosting.asset#vm1011:TENANT to role:hs_hosting.asset#fir00:TENANT by system and assume }", + "{ grant perm:hs_hosting.asset#fir00:SELECT to role:hs_hosting.asset#fir00:TENANT by system and assume }", null)); } @@ -251,7 +251,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu assertThatAssetIsPersisted(result.returnedValue()); // ... a rbac.global admin can see the new domain setup as well if the domain OWNER role is assumed - context("superuser-alex@hostsharing.net", "hs_hosting_asset#example.net:OWNER"); // only works with the assumed role + context("superuser-alex@hostsharing.net", "hs_hosting.asset#example.net:OWNER"); // only works with the assumed role assertThatAssetIsPersisted(result.returnedValue()); } @@ -309,7 +309,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu .findAny().orElseThrow().getUuid(); // when - context("superuser-alex@hostsharing.net", "hs_hosting_asset#vm1012:AGENT"); + context("superuser-alex@hostsharing.net", "hs_hosting.asset#vm1012:AGENT"); final var result = rbacAssetRepo.findAllByCriteria(null, parentAssetUuid, null); // then @@ -326,7 +326,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu context("superuser-alex@hostsharing.net"); // when - context("superuser-alex@hostsharing.net", "hs_hosting_asset#sec01:AGENT"); + context("superuser-alex@hostsharing.net", "hs_hosting.asset#sec01:AGENT"); final var result = rbacAssetRepo.findAllByCriteria(null, null, EMAIL_ADDRESS); // then @@ -417,7 +417,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // when final var result = jpaAttempt.transacted(() -> { - context("person-FirbySusan@example.com", "hs_hosting_asset#vm1000:ADMIN"); + context("person-FirbySusan@example.com", "hs_hosting.asset#vm1000:ADMIN"); assertThat(rbacAssetRepo.findByUuid(givenAsset.getUuid())).isPresent(); rbacAssetRepo.deleteByUuid(givenAsset.getUuid()); @@ -426,7 +426,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // then result.assertExceptionWithRootCauseMessage( JpaSystemException.class, - "[403] Subject ", " is not allowed to delete hs_hosting_asset"); + "[403] Subject ", " is not allowed to delete hs_hosting.asset"); assertThat(jpaAttempt.transacted(() -> { return realAssetRepo.findByUuid(givenAsset.getUuid()); }).assertSuccessful().returnedValue()).isPresent(); // still there diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java index 95a950db..6ff2ab36 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java @@ -68,7 +68,7 @@ class HsUnixUserHostingAssetValidatorUnitTest { void initMocks() { final var nativeQueryMock = mock(Query.class); lenient().when(nativeQueryMock.getSingleResult()).thenReturn(12345678); - lenient().when(em.createNativeQuery("SELECT nextval('hs_hosting_asset_unixuser_system_id_seq')", Integer.class)) + lenient().when(em.createNativeQuery("SELECT nextval('hs_hosting.asset_unixuser_system_id_seq')", Integer.class)) .thenReturn(nativeQueryMock); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java index 4f3c7f5f..3dd9a11f 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java @@ -187,7 +187,7 @@ public class CsvDataImport extends ContextBasedTest { } final var query = em.createNativeQuery(""" - insert into hs_hosting_asset( + insert into hs_hosting.asset( uuid, type, bookingitemuuid, @@ -248,8 +248,8 @@ public class CsvDataImport extends ContextBasedTest { jpaAttempt.transacted(() -> { context(rbacSuperuser); // TODO.perf: could we instead skip creating test-data based on an env var? - em.createNativeQuery("delete from hs_hosting_asset where true").executeUpdate(); - em.createNativeQuery("delete from hs_hosting_asset_ex where true").executeUpdate(); + em.createNativeQuery("delete from hs_hosting.asset where true").executeUpdate(); + em.createNativeQuery("delete from hs_hosting.asset_ex where true").executeUpdate(); em.createNativeQuery("delete from hs_booking.item where true").executeUpdate(); em.createNativeQuery("delete from hs_booking.item_ex where true").executeUpdate(); em.createNativeQuery("delete from hs_booking.project where true").executeUpdate(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java index a084d4f0..90d987be 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java @@ -921,7 +921,7 @@ public class ImportHostingAssets extends BaseOfficeDataImport { @Test @Order(19920) void verifyHostingAssetsAreActuallyPersisted() { - final var haCount = (Integer) em.createNativeQuery("select count(*) from hs_hosting_asset", Integer.class) + final var haCount = (Integer) em.createNativeQuery("select count(*) from hs_hosting.asset", Integer.class) .getSingleResult(); assertThat(haCount).isGreaterThan(isImportingControlledTestData() ? 40 : 15000); @@ -1069,7 +1069,7 @@ public class ImportHostingAssets extends BaseOfficeDataImport { final var haCount = jpaAttempt.transacted(() -> { context(rbacSuperuser, "hs_booking.project#D-1000300-mimdefaultproject:AGENT"); - return (Integer) em.createNativeQuery("select count(*) from hs_hosting_asset_rv where type='EMAIL_ADDRESS'", Integer.class) + return (Integer) em.createNativeQuery("select count(*) from hs_hosting.asset_rv where type='EMAIL_ADDRESS'", Integer.class) .getSingleResult(); }).assertSuccessful().returnedValue(); assertThat(haCount).isEqualTo(68); @@ -1136,7 +1136,7 @@ public class ImportHostingAssets extends BaseOfficeDataImport { jpaAttempt.transacted(() -> { context(rbacSuperuser); - updateLegacyIds(assets, "hs_hosting_asset_legacy_id", "legacy_id"); + updateLegacyIds(assets, "hs_hosting.asset_legacy_id", "legacy_id"); }).assertSuccessful(); } @@ -1145,7 +1145,7 @@ public class ImportHostingAssets extends BaseOfficeDataImport { final int expectedCountInTestDataCount, final int minCountExpectedInProdData) { final var q = em.createNativeQuery( - "select count(*) from hs_hosting_asset where type = cast(:type as HsHostingAssetType)", + "select count(*) from hs_hosting.asset where type = cast(:type as HsHostingAssetType)", Integer.class); q.setParameter("type", assetType.name()); final var count = (Integer) q.getSingleResult(); @@ -1895,8 +1895,8 @@ public class ImportHostingAssets extends BaseOfficeDataImport { //noinspection unchecked return ((List>) em.createNativeQuery( """ - SELECT li.* FROM hs_hosting_asset_legacy_id li - JOIN hs_hosting_asset ha ON ha.uuid=li.uuid + SELECT li.* FROM hs_hosting.asset_legacy_id li + JOIN hs_hosting.asset ha ON ha.uuid=li.uuid WHERE CAST(ha.type AS text)=:type ORDER BY legacy_id """, @@ -1910,8 +1910,8 @@ public class ImportHostingAssets extends BaseOfficeDataImport { //noinspection unchecked return ((List>) em.createNativeQuery( """ - SELECT ha.uuid, ha.type, ha.identifier FROM hs_hosting_asset ha - JOIN hs_hosting_asset_legacy_id li ON li.uuid=ha.uuid + SELECT ha.uuid, ha.type, ha.identifier FROM hs_hosting.asset ha + JOIN hs_hosting.asset_legacy_id li ON li.uuid=ha.uuid WHERE li.legacy_id is null AND CAST(ha.type AS text)=:type ORDER BY li.legacy_id """, -- 2.39.5 From 6514d6a17cd090bf49e0d97224523528db1d1a52 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 18 Sep 2024 14:14:22 +0200 Subject: [PATCH 03/14] fix ImportHostingAssets --- .../hostsharing/hsadminng/hs/migration/ImportHostingAssets.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java index 90d987be..2fd29b56 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java @@ -1145,7 +1145,7 @@ public class ImportHostingAssets extends BaseOfficeDataImport { final int expectedCountInTestDataCount, final int minCountExpectedInProdData) { final var q = em.createNativeQuery( - "select count(*) from hs_hosting.asset where type = cast(:type as HsHostingAssetType)", + "select count(*) from hs_hosting.asset where type = cast(:type as hs_hosting.HsHostingAssetType)", Integer.class); q.setParameter("type", assetType.name()); final var count = (Integer) q.getSingleResult(); -- 2.39.5 From a0e1d9627876e758ba50c69edceea4845876dc4c Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 18 Sep 2024 15:04:21 +0200 Subject: [PATCH 04/14] move test-data-creation to separate schemas --- .../2018-rbactest-customer-test-data.sql | 14 ++++----- .../2028-rbactest-package-test-data.sql | 12 ++++---- .../2038-rbactest-domain-test-data.sql | 26 ++++++++-------- .../5018-hs-office-contact-test-data.sql | 30 +++++++++---------- .../502-person/5020-hs-office-person.sql | 6 ++-- .../5028-hs-office-person-test-data.sql | 2 +- .../503-relation/5030-hs-office-relation.sql | 6 ++-- .../5038-hs-office-relation-test-data.sql | 2 +- .../5048-hs-office-partner-test-data.sql | 12 ++++---- .../5058-hs-office-bankaccount-test-data.sql | 18 +++++------ .../5068-hs-office-debitor-test-data.sql | 8 ++--- .../5078-hs-office-sepamandate-test-data.sql | 8 ++--- .../5100-hs-office-membership.sql | 6 ++-- .../5108-hs-office-membership-test-data.sql | 8 ++--- .../5110-hs-office-coopshares.sql | 6 ++-- .../5118-hs-office-coopshares-test-data.sql | 8 ++--- .../5120-hs-office-coopassets.sql | 6 ++-- .../5128-hs-office-coopassets-test-data.sql | 8 ++--- .../6308-hs-booking-item-test-data.sql | 8 ++--- .../7018-hs-hosting-asset-test-data.sql | 8 ++--- 20 files changed, 100 insertions(+), 102 deletions(-) diff --git a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql index f441522e..af57b169 100644 --- a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql +++ b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql @@ -7,7 +7,7 @@ /* Generates a customer reference number for a given test data counter. */ -create or replace function testCustomerReference(customerCount integer) +create or replace function rbactest.testCustomerReference(customerCount integer) returns integer returns null on null input language plpgsql as $$ @@ -19,7 +19,7 @@ end; $$; /* Creates a single customer test record with dist. */ -create or replace procedure createTestCustomerTestData( +create or replace procedure rbactest.createTestCustomerTestData( custReference integer, custPrefix varchar ) @@ -51,7 +51,7 @@ end; $$; /* Creates a range of test customers for mass data generation. */ -create or replace procedure createTestCustomerTestData( +create or replace procedure rbactest.createTestCustomerTestData( startCount integer, -- count of auto generated rows before the run endCount integer -- count of auto generated rows after the run ) @@ -59,7 +59,7 @@ create or replace procedure createTestCustomerTestData( begin for t in startCount..endCount loop - call createTestCustomerTestData(testCustomerReference(t), base.intToVarChar(t, 3)); + call rbactest.createTestCustomerTestData(rbactest.testCustomerReference(t), base.intToVarChar(t, 3)); commit; end loop; end; $$; @@ -74,9 +74,9 @@ do language plpgsql $$ begin call base.defineContext('creating RBAC test customer', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN'); - call createTestCustomerTestData(99901, 'xxx'); - call createTestCustomerTestData(99902, 'yyy'); - call createTestCustomerTestData(99903, 'zzz'); + call rbactest.createTestCustomerTestData(99901, 'xxx'); + call rbactest.createTestCustomerTestData(99902, 'yyy'); + call rbactest.createTestCustomerTestData(99903, 'zzz'); end; $$; --// diff --git a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql index 869b9cb4..4b227df2 100644 --- a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql +++ b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql @@ -6,7 +6,7 @@ /* Creates the given number of test packages for the given customer. */ -create or replace procedure createPackageTestData(customerPrefix varchar, pacCount int) +create or replace procedure rbactest.createPackageTestData(customerPrefix varchar, pacCount int) language plpgsql as $$ declare cust rbactest.customer; @@ -41,7 +41,7 @@ end; $$; /* Creates a range of test packages for mass data generation. */ -create or replace procedure createPackageTestData() +create or replace procedure rbactest.createPackageTestData() language plpgsql as $$ declare cust rbactest.customer; @@ -49,7 +49,7 @@ begin for cust in (select * from rbactest.customer) loop continue when cust.reference >= 90000; -- reserved for functional testing - call createPackageTestData(cust.prefix, 3); + call rbactest.createPackageTestData(cust.prefix, 3); end loop; commit; @@ -64,9 +64,9 @@ $$; do language plpgsql $$ begin - call createPackageTestData('xxx', 3); - call createPackageTestData('yyy', 3); - call createPackageTestData('zzz', 3); + call rbactest.createPackageTestData('xxx', 3); + call rbactest.createPackageTestData('yyy', 3); + call rbactest.createPackageTestData('zzz', 3); end; $$; --// diff --git a/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2038-rbactest-domain-test-data.sql b/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2038-rbactest-domain-test-data.sql index 38843d1e..23ce972c 100644 --- a/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2038-rbactest-domain-test-data.sql +++ b/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2038-rbactest-domain-test-data.sql @@ -6,7 +6,7 @@ /* Creates the given count of test unix users for a single package. */ -create or replace procedure createdomainTestData( packageName varchar, domainCount int ) +create or replace procedure rbactest.createDomainTestData( packageName varchar, domainCount int ) language plpgsql as $$ declare pac record; @@ -32,12 +32,10 @@ end; $$; /* Creates a range of unix users for mass data generation. */ -create or replace procedure createdomainTestData( domainPerPackage integer ) +create or replace procedure rbactest.createDomainTestData( domainPerPackage integer ) language plpgsql as $$ declare pac record; - pacAdmin varchar; - currentTask varchar; begin for pac in (select p.uuid, p.name @@ -45,7 +43,7 @@ begin join rbactest.customer c on p.customeruuid = c.uuid where c.reference < 90000) -- reserved for functional testing loop - call createdomainTestData(pac.name, 2); + call rbactest.createdomainTestData(pac.name, 2); commit; end loop; @@ -59,17 +57,17 @@ end; $$; do language plpgsql $$ begin - call createdomainTestData('xxx00', 2); - call createdomainTestData('xxx01', 2); - call createdomainTestData('xxx02', 2); + call rbactest.createDomainTestData('xxx00', 2); + call rbactest.createDomainTestData('xxx01', 2); + call rbactest.createDomainTestData('xxx02', 2); - call createdomainTestData('yyy00', 2); - call createdomainTestData('yyy01', 2); - call createdomainTestData('yyy02', 2); + call rbactest.createDomainTestData('yyy00', 2); + call rbactest.createDomainTestData('yyy01', 2); + call rbactest.createDomainTestData('yyy02', 2); - call createdomainTestData('zzz00', 2); - call createdomainTestData('zzz01', 2); - call createdomainTestData('zzz02', 2); + call rbactest.createDomainTestData('zzz00', 2); + call rbactest.createDomainTestData('zzz01', 2); + call rbactest.createDomainTestData('zzz02', 2); end; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/501-contact/5018-hs-office-contact-test-data.sql b/src/main/resources/db/changelog/5-hs-office/501-contact/5018-hs-office-contact-test-data.sql index 40f9e065..5acd8e4f 100644 --- a/src/main/resources/db/changelog/5-hs-office/501-contact/5018-hs-office-contact-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/501-contact/5018-hs-office-contact-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single contact test record. */ -create or replace procedure createHsOfficeContactTestData(contCaption varchar) +create or replace procedure hs_office.createHsOfficeContactTestData(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.createHsOfficeContactTestData( 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.createHsOfficeContactTestData(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.createHsOfficeContactTestData('first contact'); + call hs_office.createHsOfficeContactTestData('second contact'); + call hs_office.createHsOfficeContactTestData('third contact'); + call hs_office.createHsOfficeContactTestData('fourth contact'); + call hs_office.createHsOfficeContactTestData('fifth contact'); + call hs_office.createHsOfficeContactTestData('sixth contact'); + call hs_office.createHsOfficeContactTestData('seventh contact'); + call hs_office.createHsOfficeContactTestData('eighth contact'); + call hs_office.createHsOfficeContactTestData('ninth contact'); + call hs_office.createHsOfficeContactTestData('tenth contact'); + call hs_office.createHsOfficeContactTestData('eleventh contact'); + call hs_office.createHsOfficeContactTestData('twelfth contact'); end; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql b/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql index 428df466..81245561 100644 --- a/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql +++ b/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:hs-office-person-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -CREATE TYPE HsOfficePersonType AS ENUM ( +CREATE TYPE hs_office.HsOfficePersonType 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.HsOfficePersonType) 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.HsOfficePersonType not null, tradeName varchar(96), salutation varchar(30), title varchar(20), diff --git a/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql b/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql index 9ba8dd37..ae02d0d3 100644 --- a/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql @@ -9,7 +9,7 @@ Creates a single person test record. */ create or replace procedure createHsOfficePersonTestData( - newPersonType HsOfficePersonType, + newPersonType hs_office.HsOfficePersonType, newTradeName varchar, newFamilyName varchar = null, newGivenName varchar = null diff --git a/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql b/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql index 1c17aa78..8c946f66 100644 --- a/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql +++ b/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:hs-office-relation-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -CREATE TYPE HsOfficeRelationType AS ENUM ( +CREATE TYPE hs_office.HsOfficeRelationType 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.HsOfficeRelationType) 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.HsOfficeRelationType not null, mark varchar(24) ); --// diff --git a/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql b/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql index 3cb64e13..0de446e8 100644 --- a/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql @@ -10,7 +10,7 @@ */ create or replace procedure createHsOfficeRelationTestData( holderPersonName varchar, - relationType HsOfficeRelationType, + relationType hs_office.HsOfficeRelationType, anchorPersonName varchar, contactCaption varchar, mark varchar default null) diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5048-hs-office-partner-test-data.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5048-hs-office-partner-test-data.sql index 114158c5..f8239efc 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5048-hs-office-partner-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5048-hs-office-partner-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single partner test record. */ -create or replace procedure createHsOfficePartnerTestData( +create or replace procedure hs_office.createHsOfficePartnerTestData( 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.createHsOfficePartnerTestData('Hostsharing eG', 10001, 'First GmbH', 'first contact'); + call hs_office.createHsOfficePartnerTestData('Hostsharing eG', 10002, 'Second e.K.', 'second contact'); + call hs_office.createHsOfficePartnerTestData('Hostsharing eG', 10003, 'Third OHG', 'third contact'); + call hs_office.createHsOfficePartnerTestData('Hostsharing eG', 10004, 'Fourth eG', 'fourth contact'); + call hs_office.createHsOfficePartnerTestData('Hostsharing eG', 10010, 'Smith', 'fifth contact'); end; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5058-hs-office-bankaccount-test-data.sql b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5058-hs-office-bankaccount-test-data.sql index 0a8123eb..f8233c48 100644 --- a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5058-hs-office-bankaccount-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5058-hs-office-bankaccount-test-data.sql @@ -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.createHsOfficeBankAccountTestData(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.createHsOfficeBankAccountTestData('First GmbH', 'DE02120300000000202051', 'BYLADEM1001'); + call hs_office.createHsOfficeBankAccountTestData('Peter Smith', 'DE02500105170137075030', 'INGDDEFF'); + call hs_office.createHsOfficeBankAccountTestData('Second e.K.', 'DE02100500000054540402', 'BELADEBE'); + call hs_office.createHsOfficeBankAccountTestData('Third OHG', 'DE02300209000106531065', 'CMCIDEDD'); + call hs_office.createHsOfficeBankAccountTestData('Fourth eG', 'DE02200505501015871393', 'HASPDEHH'); + call hs_office.createHsOfficeBankAccountTestData('Mel Bessler', 'DE02100100100006820101', 'PBNKDEFF'); + call hs_office.createHsOfficeBankAccountTestData('Anita Bessler', 'DE02300606010002474689', 'DAAEDEDD'); + call hs_office.createHsOfficeBankAccountTestData('Paul Winkler', 'DE02600501010002034304', 'SOLADEST600'); end; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/506-debitor/5068-hs-office-debitor-test-data.sql b/src/main/resources/db/changelog/5-hs-office/506-debitor/5068-hs-office-debitor-test-data.sql index df82033d..db4bc66e 100644 --- a/src/main/resources/db/changelog/5-hs-office/506-debitor/5068-hs-office-debitor-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/506-debitor/5068-hs-office-debitor-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single debitor test record. */ -create or replace procedure createHsOfficeDebitorTestData( +create or replace procedure hs_office.createHsOfficeDebitorTestData( 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.createHsOfficeDebitorTestData(11, 'First GmbH', 'first contact', 'fir'); + call hs_office.createHsOfficeDebitorTestData(12, 'Second e.K.', 'second contact', 'sec'); + call hs_office.createHsOfficeDebitorTestData(13, 'Third OHG', 'third contact', 'thi'); end; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5078-hs-office-sepamandate-test-data.sql b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5078-hs-office-sepamandate-test-data.sql index 51e33f6b..2de78d7a 100644 --- a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5078-hs-office-sepamandate-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5078-hs-office-sepamandate-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single sepaMandate test record. */ -create or replace procedure createHsOfficeSepaMandateTestData( +create or replace procedure hs_office.createHsOfficeSepaMandateTestData( 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.createHsOfficeSepaMandateTestData(10001, '11', 'DE02120300000000202051', 'ref-10001-11'); + call hs_office.createHsOfficeSepaMandateTestData(10002, '12', 'DE02100500000054540402', 'ref-10002-12'); + call hs_office.createHsOfficeSepaMandateTestData(10003, '13', 'DE02300209000106531065', 'ref-10003-13'); end; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/510-membership/5100-hs-office-membership.sql b/src/main/resources/db/changelog/5-hs-office/510-membership/5100-hs-office-membership.sql index e0147e5a..d8d64559 100644 --- a/src/main/resources/db/changelog/5-hs-office/510-membership/5100-hs-office-membership.sql +++ b/src/main/resources/db/changelog/5-hs-office/510-membership/5100-hs-office-membership.sql @@ -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) diff --git a/src/main/resources/db/changelog/5-hs-office/510-membership/5108-hs-office-membership-test-data.sql b/src/main/resources/db/changelog/5-hs-office/510-membership/5108-hs-office-membership-test-data.sql index 8b904d6d..34cb07d5 100644 --- a/src/main/resources/db/changelog/5-hs-office/510-membership/5108-hs-office-membership-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/510-membership/5108-hs-office-membership-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single membership test record. */ -create or replace procedure createHsOfficeMembershipTestData( +create or replace procedure hs_office.createHsOfficeMembershipTestData( 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.createHsOfficeMembershipTestData(10001, '01'); + call hs_office.createHsOfficeMembershipTestData(10002, '02'); + call hs_office.createHsOfficeMembershipTestData(10003, '03'); end; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql index 7e15a874..5cf3ef82 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql @@ -4,16 +4,16 @@ --changeset michael.hoennig:hs-office-coopshares-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -CREATE TYPE HsOfficeCoopSharesTransactionType AS ENUM ('ADJUSTMENT', 'SUBSCRIPTION', 'CANCELLATION'); +CREATE TYPE hs_office.HsOfficeCoopSharesTransactionType AS ENUM ('ADJUSTMENT', 'SUBSCRIPTION', 'CANCELLATION'); -CREATE CAST (character varying as HsOfficeCoopSharesTransactionType) WITH INOUT AS IMPLICIT; +CREATE CAST (character varying as hs_office.HsOfficeCoopSharesTransactionType) WITH INOUT AS IMPLICIT; create table if not exists hs_office.coopsharestransaction ( 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.HsOfficeCoopSharesTransactionType not null, valueDate date not null, shareCount integer not null, reference varchar(48) not null, diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql index a4c634a7..bfddf0c7 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single coopSharesTransaction test record. */ -create or replace procedure createHsOfficeCoopSharesTransactionTestData( +create or replace procedure hs_office.createHsOfficeCoopSharesTransactionTestData( givenPartnerNumber numeric, givenMemberNumberSuffix char(2) ) @@ -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.createHsOfficeCoopSharesTransactionTestData(10001, '01'); + call hs_office.createHsOfficeCoopSharesTransactionTestData(10002, '02'); + call hs_office.createHsOfficeCoopSharesTransactionTestData(10003, '03'); end; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql index 4804f4d7..4da4e0bd 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:hs-office-coopassets-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -CREATE TYPE HsOfficeCoopAssetsTransactionType AS ENUM ('ADJUSTMENT', +CREATE TYPE hs_office.HsOfficeCoopAssetsTransactionType AS ENUM ('ADJUSTMENT', 'DEPOSIT', 'DISBURSAL', 'TRANSFER', @@ -13,14 +13,14 @@ 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.HsOfficeCoopAssetsTransactionType) WITH INOUT AS IMPLICIT; create table if not exists hs_office.coopassetstransaction ( 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.HsOfficeCoopAssetsTransactionType not null, valueDate date not null, assetValue money not null, reference varchar(48) not null, diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql index 21a4ef82..da9265d8 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single coopAssetsTransaction test record. */ -create or replace procedure createHsOfficeCoopAssetsTransactionTestData( +create or replace procedure hs_office.createHsOfficeCoopAssetsTransactionTestData( givenPartnerNumber numeric, givenMemberNumberSuffix char(2) ) @@ -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.createHsOfficeCoopAssetsTransactionTestData(10001, '01'); + call hs_office.createHsOfficeCoopAssetsTransactionTestData(10002, '02'); + call hs_office.createHsOfficeCoopAssetsTransactionTestData(10003, '03'); end; $$; diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql index 84d53142..03c89b6a 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single hs_booking.item test record. */ -create or replace procedure createHsBookingItemTransactionTestData( +create or replace procedure hs_booking.createHsBookingItemTransactionTestData( givenPartnerNumber numeric, givenDebitorSuffix char(2) ) @@ -49,9 +49,9 @@ do language plpgsql $$ begin call base.defineContext('creating booking-item test-data', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN'); - call createHsBookingItemTransactionTestData(10001, '11'); - call createHsBookingItemTransactionTestData(10002, '12'); - call createHsBookingItemTransactionTestData(10003, '13'); + call hs_booking.createHsBookingItemTransactionTestData(10001, '11'); + call hs_booking.createHsBookingItemTransactionTestData(10002, '12'); + call hs_booking.createHsBookingItemTransactionTestData(10003, '13'); end; $$; --// diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql index 72f6527d..e9574b14 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single hs_hosting.asset test record. */ -create or replace procedure createHsHostingAssetTestData(givenProjectCaption varchar) +create or replace procedure hs_office.createHsHostingAssetTestData(givenProjectCaption varchar) language plpgsql as $$ declare relatedProject hs_booking.project; @@ -112,9 +112,9 @@ do language plpgsql $$ begin call base.defineContext('creating hosting-asset test-data', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN'); - call createHsHostingAssetTestData('D-1000111 default project'); - call createHsHostingAssetTestData('D-1000212 default project'); - call createHsHostingAssetTestData('D-1000313 default project'); + call hs_office.createHsHostingAssetTestData('D-1000111 default project'); + call hs_office.createHsHostingAssetTestData('D-1000212 default project'); + call hs_office.createHsHostingAssetTestData('D-1000313 default project'); end; $$; --// -- 2.39.5 From 94f6bab004eb086559a39ed84a3966222a392595 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 18 Sep 2024 15:58:59 +0200 Subject: [PATCH 05/14] WIP towards customerOwner -> rbactest.customer_OWNER for example --- .../RbacRoleDescriptorsGenerator.java | 3 +- .../changelog/1-rbac/1058-rbac-generators.sql | 29 ++++++++++--------- .../2013-rbactest-customer-rbac.sql | 2 +- .../2023-rbactest-package-rbac.sql | 2 +- .../2033-rbactest-domain-rbac.sql | 2 +- .../5013-hs-office-contact-rbac.sql | 2 +- .../502-person/5023-hs-office-person-rbac.sql | 2 +- .../5033-hs-office-relation-rbac.sql | 2 +- .../5043-hs-office-partner-rbac.sql | 2 +- .../5044-hs-office-partner-details-rbac.sql | 2 +- .../5053-hs-office-bankaccount-rbac.sql | 2 +- .../5063-hs-office-debitor-rbac.sql | 2 +- .../5073-hs-office-sepamandate-rbac.sql | 2 +- .../5103-hs-office-membership-rbac.sql | 2 +- .../5113-hs-office-coopshares-rbac.sql | 2 +- .../5123-hs-office-coopassets-rbac.sql | 2 +- .../6203-hs-booking-project-rbac.sql | 2 +- .../6303-hs-booking-item-rbac.sql | 2 +- .../7013-hs-hosting-asset-rbac.sql | 2 +- src/test/resources/application.yml | 2 +- 20 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacRoleDescriptorsGenerator.java b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacRoleDescriptorsGenerator.java index 098ebf81..4d78d0c2 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacRoleDescriptorsGenerator.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacRoleDescriptorsGenerator.java @@ -19,12 +19,11 @@ public class RbacRoleDescriptorsGenerator { -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:${liquibaseTagPrefix}-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- - call rbac.generateRbacRoleDescriptors('${simpleEntityVarName}', '${rawTableName}'); + call rbac.generateRbacRoleDescriptors('${rawTableName}'); --// """, with("liquibaseTagPrefix", liquibaseTagPrefix), - with("simpleEntityVarName", simpleEntityVarName), with("rawTableName", rawTableName)); } } diff --git a/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql b/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql index 0c7b8b2e..e7e4db47 100644 --- a/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql +++ b/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql @@ -49,62 +49,63 @@ $$; --changeset michael.hoennig:rbac-generators-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -create procedure rbac.generateRbacRoleDescriptors(prefix text, targetTable text) +create procedure rbac.generateRbacRoleDescriptors(targetTable text) language plpgsql as $$ declare sql text; begin sql = format($sql$ - create or replace function %1$sOwner(entity %2$s, assumed boolean = true) + create or replace function %1$s_OWNER(entity %1$s, assumed boolean = true) returns rbac.RoleDescriptor language plpgsql strict as $f$ begin - return rbac.roleDescriptorOf('%2$s', entity.uuid, 'OWNER', assumed); + return rbac.roleDescriptorOf('%1$s', entity.uuid, 'OWNER', assumed); end; $f$; - create or replace function %1$sAdmin(entity %2$s, assumed boolean = true) + create or replace function %1$s_ADMIN(entity %1$s, assumed boolean = true) returns rbac.RoleDescriptor language plpgsql strict as $f$ begin - return rbac.roleDescriptorOf('%2$s', entity.uuid, 'ADMIN', assumed); + return rbac.roleDescriptorOf('%1$s', entity.uuid, 'ADMIN', assumed); end; $f$; - create or replace function %1$sAgent(entity %2$s, assumed boolean = true) + create or replace function %1$s_AGENT(entity %1$s, assumed boolean = true) returns rbac.RoleDescriptor language plpgsql strict as $f$ begin - return rbac.roleDescriptorOf('%2$s', entity.uuid, 'AGENT', assumed); + return rbac.roleDescriptorOf('%1$s', entity.uuid, 'AGENT', assumed); end; $f$; - create or replace function %1$sTenant(entity %2$s, assumed boolean = true) + create or replace function %1$s_TENANT(entity %1$s, assumed boolean = true) returns rbac.RoleDescriptor language plpgsql strict as $f$ begin - return rbac.roleDescriptorOf('%2$s', entity.uuid, 'TENANT', assumed); + return rbac.roleDescriptorOf('%1$s', entity.uuid, 'TENANT', assumed); end; $f$; -- TODO: remove guest role - create or replace function %1$sGuest(entity %2$s, assumed boolean = true) + create or replace function %1$s_GUEST(entity %1$s, assumed boolean = true) returns rbac.RoleDescriptor language plpgsql strict as $f$ begin - return rbac.roleDescriptorOf('%2$s', entity.uuid, 'GUEST', assumed); + return rbac.roleDescriptorOf('%1$s', entity.uuid, 'GUEST', assumed); end; $f$; - create or replace function %1$sReferrer(entity %2$s) + create or replace function %1$s_REFERRER(entity %1$s) returns rbac.RoleDescriptor language plpgsql strict as $f$ begin - return rbac.roleDescriptorOf('%2$s', entity.uuid, 'REFERRER'); + return rbac.roleDescriptorOf('%1$s', entity.uuid, 'REFERRER'); end; $f$; - $sql$, prefix, targetTable); + $sql$, targetTable); + raise exception 'generated-SQL: %', sql; execute sql; end; $$; --// diff --git a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql index d7104eff..02022c11 100644 --- a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql +++ b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql @@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('rbactest.customer'); -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:rbactest-customer-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRoleDescriptors('testCustomer', 'rbactest.customer'); +call rbac.generateRbacRoleDescriptors('rbactest.customer'); --// diff --git a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql index 91dd207b..72a5d33e 100644 --- a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql +++ b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql @@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('rbactest.package'); -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:rbactest-package-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRoleDescriptors('testPackage', 'rbactest.package'); +call rbac.generateRbacRoleDescriptors('rbactest.package'); --// diff --git a/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql b/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql index b20d12d6..7aada58b 100644 --- a/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql +++ b/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql @@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('rbactest.domain'); -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:rbactest-domain-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRoleDescriptors('testDomain', 'rbactest.domain'); +call rbac.generateRbacRoleDescriptors('rbactest.domain'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql b/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql index 39976f0e..fad804a1 100644 --- a/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql @@ -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'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql b/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql index 8e0d7a31..2a0f1a42 100644 --- a/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql @@ -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'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql b/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql index 85301c32..1d750626 100644 --- a/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql @@ -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'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql index 7ead6151..79dab51e 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql @@ -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'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql index a6209110..27b2f489 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql @@ -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'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql index 02775bf1..3257b0a0 100644 --- a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql @@ -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'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql index dd3abfa8..255aa486 100644 --- a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql @@ -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'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql index f9e4ef66..300729d8 100644 --- a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql @@ -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'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql index 18d53198..8ee6d6e4 100644 --- a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql @@ -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'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql index 66df3a08..83e86775 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql @@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_office.coopsharestransaction'); -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:hs-office-coopsharestransaction-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRoleDescriptors('hsOfficeCoopSharesTransaction', 'hs_office.coopsharestransaction'); +call rbac.generateRbacRoleDescriptors('hs_office.coopsharestransaction'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql index d7dbc2b5..fcbd5cbc 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql @@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_office.coopassetstransaction'); -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:hs-office-coopassetstransaction-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRoleDescriptors('hsOfficeCoopAssetsTransaction', 'hs_office.coopassetstransaction'); +call rbac.generateRbacRoleDescriptors('hs_office.coopassetstransaction'); --// diff --git a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql index 527a12e8..72809815 100644 --- a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql @@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_booking.project'); -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:hs-booking-project-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRoleDescriptors('hsBookingProject', 'hs_booking.project'); +call rbac.generateRbacRoleDescriptors('hs_booking.project'); --// diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql index f357da1f..483fcdd3 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql @@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_booking.item'); -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:hs-booking-item-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRoleDescriptors('hsBookingItem', 'hs_booking.item'); +call rbac.generateRbacRoleDescriptors('hs_booking.item'); --// diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql index 2c739bf5..ef7849db 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql @@ -12,7 +12,7 @@ call rbac.generateRelatedRbacObject('hs_hosting.asset'); -- ============================================================================ --changeset RbacRoleDescriptorsGenerator:hs-hosting-asset-rbac-ROLE-DESCRIPTORS endDelimiter:--// -- ---------------------------------------------------------------------------- -call rbac.generateRbacRoleDescriptors('hsHostingAsset', 'hs_hosting.asset'); +call rbac.generateRbacRoleDescriptors('hs_hosting.asset'); --// diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 923c62e9..b4945a0f 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -7,7 +7,7 @@ spring: url-tc: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers url-tcx: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers?TC_REUSABLE=true&TC_DAEMON=true url-local: jdbc:postgresql://localhost:5432/postgres - url: ${spring.datasource.url-tc} + url: ${spring.datasource.url-local} username: postgres password: password -- 2.39.5 From 632bf7d29ba70a597f3f33ddb2795b8551dca9db Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 19 Sep 2024 12:14:13 +0200 Subject: [PATCH 06/14] rename customerOwner -> rbactest.customer_OWNER etc. --- doc/rbac-performance-analysis.md | 4 +-- .../changelog/1-rbac/1058-rbac-generators.sql | 1 - .../2013-rbactest-customer-rbac.sql | 10 +++--- .../2018-rbactest-customer-test-data.sql | 4 +-- .../2023-rbactest-package-rbac.sql | 26 +++++++------- .../2028-rbactest-package-test-data.sql | 4 +-- .../2033-rbactest-domain-rbac.sql | 28 +++++++-------- .../5013-hs-office-contact-rbac.sql | 10 +++--- .../502-person/5023-hs-office-person-rbac.sql | 10 +++--- .../5033-hs-office-relation-rbac.sql | 36 +++++++++---------- .../5043-hs-office-partner-rbac.sql | 36 +++++++++---------- .../5053-hs-office-bankaccount-rbac.sql | 10 +++--- .../5063-hs-office-debitor-rbac.sql | 16 ++++----- .../5073-hs-office-sepamandate-rbac.sql | 28 +++++++-------- .../5103-hs-office-membership-rbac.sql | 16 ++++----- .../5113-hs-office-coopshares-rbac.sql | 8 ++--- .../5123-hs-office-coopassets-rbac.sql | 8 ++--- .../6203-hs-booking-project-rbac.sql | 22 ++++++------ .../6303-hs-booking-item-rbac.sql | 28 +++++++-------- .../7013-hs-hosting-asset-rbac.sql | 34 +++++++++--------- src/test/resources/application.yml | 2 +- 21 files changed, 170 insertions(+), 171 deletions(-) diff --git a/doc/rbac-performance-analysis.md b/doc/rbac-performance-analysis.md index 39037b8d..2033e160 100644 --- a/doc/rbac-performance-analysis.md +++ b/doc/rbac-performance-analysis.md @@ -338,8 +338,8 @@ Now, the longest running queries are these: | 6 | 123.740 | 3 | 2 | with recursive grants as ( select descendantUuid, ascendantUuid from RbacGrants where descendantUuid = grantedId union all select "grant".descendantUuid, "grant".ascendantUuid from RbacGrants "grant" inner join grants recur on recur.ascendantUuid = "grant".descendantUuid ) select exists ( select $3 from grants where ascendantUuid = any(granteeIds) ) or grantedId = any(granteeIds) | | 7 | 497 | 2 | 259 | select hoce1_0.uuid,hoce1_0.caption,hoce1_0.emailaddresses,hoce1_0.phonenumbers,hoce1_0.postaladdress,hoce1_0.version from public.hs_office.contact_rv hoce1_0 where hoce1_0.uuid=$1 | | 8 | 497 | 2 | 255 | select hope1_0.uuid,hope1_0.familyname,hope1_0.givenname,hope1_0.persontype,hope1_0.salutation,hope1_0.title,hope1_0.tradename,hope1_0.version from public.hs_office.person_rv hope1_0 where hope1_0.uuid=$1 | -| 9 | 13.144 | 1 | 8 | SELECT createRoleWithGrants( hsHostingAssetTENANT(NEW), permissions => array[$7], incomingSuperRoles => array[ hsHostingAssetAGENT(NEW), hsOfficeContactADMIN(newAlarmContact)], outgoingSubRoles => array[ hsBookingItemTENANT(newBookingItem), hsHostingAssetTENANT(newParentAsset)] ) | -| 10 | 13.144 | 1 | 5 | SELECT createRoleWithGrants( hsHostingAssetADMIN(NEW), permissions => array[$7], incomingSuperRoles => array[ hsBookingItemAGENT(newBookingItem), hsHostingAssetAGENT(newParentAsset), hsHostingAssetOWNER(NEW)] ) | +| 9 | 13.144 | 1 | 8 | SELECT createRoleWithGrants( hs_hosting.asset_TENANT(NEW), permissions => array[$7], incomingSuperRoles => array[ hs_hosting.asset_AGENT(NEW), hs_office.contact_ADMIN(newAlarmContact)], outgoingSubRoles => array[ hs_booking.item_TENANT(newBookingItem), hs_hosting.asset_TENANT(newParentAsset)] ) | +| 10 | 13.144 | 1 | 5 | SELECT createRoleWithGrants( hs_hosting.asset_ADMIN(NEW), permissions => array[$7], incomingSuperRoles => array[ hs_booking.item_AGENT(newBookingItem), hs_hosting.asset_AGENT(newParentAsset), hs_hosting.asset_OWNER(NEW)] ) | That the `INSERT into hs_hosting.asset` (No. 1) takes up the most time, seems to be normal, and 21ms for each call is also fine. diff --git a/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql b/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql index e7e4db47..852a023e 100644 --- a/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql +++ b/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql @@ -105,7 +105,6 @@ begin end; $f$; $sql$, targetTable); - raise exception 'generated-SQL: %', sql; execute sql; end; $$; --// diff --git a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql index 02022c11..f46fdecf 100644 --- a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql +++ b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql @@ -35,22 +35,22 @@ begin call rbac.enterTriggerForObjectUuid(NEW.uuid); perform rbac.defineRoleWithGrants( - testCustomerOWNER(NEW), + rbactest.customer_OWNER(NEW), permissions => array['DELETE'], incomingSuperRoles => array[rbac.globalADMIN(rbac.unassumed())], subjectUuids => array[rbac.currentSubjectUuid()] ); perform rbac.defineRoleWithGrants( - testCustomerADMIN(NEW), + rbactest.customer_ADMIN(NEW), permissions => array['UPDATE'], - incomingSuperRoles => array[testCustomerOWNER(NEW)] + incomingSuperRoles => array[rbactest.customer_OWNER(NEW)] ); perform rbac.defineRoleWithGrants( - testCustomerTENANT(NEW), + rbactest.customer_TENANT(NEW), permissions => array['SELECT'], - incomingSuperRoles => array[testCustomerADMIN(NEW)] + incomingSuperRoles => array[rbactest.customer_ADMIN(NEW)] ); call rbac.leaveTriggerForObjectUuid(NEW.uuid); diff --git a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql index af57b169..6fbd5d90 100644 --- a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql +++ b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql @@ -41,8 +41,8 @@ begin select * into newCust from rbactest.customer where reference=custReference; call rbac.grantRoleToSubject( - rbac.getRoleId(testCustomerOwner(newCust)), - rbac.getRoleId(testCustomerAdmin(newCust)), + rbac.getRoleId(rbactest.customer_OWNER(newCust)), + rbac.getRoleId(rbactest.customer_ADMIN(newCust)), custAdminUuid, true); end; $$; diff --git a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql index 72a5d33e..6cd43f38 100644 --- a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql +++ b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql @@ -40,21 +40,21 @@ begin perform rbac.defineRoleWithGrants( - testPackageOWNER(NEW), + rbactest.package_OWNER(NEW), permissions => array['DELETE', 'UPDATE'], - incomingSuperRoles => array[testCustomerADMIN(newCustomer)] + incomingSuperRoles => array[rbactest.customer_ADMIN(newCustomer)] ); perform rbac.defineRoleWithGrants( - testPackageADMIN(NEW), - incomingSuperRoles => array[testPackageOWNER(NEW)] + rbactest.package_ADMIN(NEW), + incomingSuperRoles => array[rbactest.package_OWNER(NEW)] ); perform rbac.defineRoleWithGrants( - testPackageTENANT(NEW), + rbactest.package_TENANT(NEW), permissions => array['SELECT'], - incomingSuperRoles => array[testPackageADMIN(NEW)], - outgoingSubRoles => array[testCustomerTENANT(newCustomer)] + incomingSuperRoles => array[rbactest.package_ADMIN(NEW)], + outgoingSubRoles => array[rbactest.customer_TENANT(newCustomer)] ); call rbac.leaveTriggerForObjectUuid(NEW.uuid); @@ -110,11 +110,11 @@ begin if NEW.customerUuid <> OLD.customerUuid then - call rbac.revokeRoleFromRole(testPackageOWNER(OLD), testCustomerADMIN(oldCustomer)); - call rbac.grantRoleToRole(testPackageOWNER(NEW), testCustomerADMIN(newCustomer)); + call rbac.revokeRoleFromRole(rbactest.package_OWNER(OLD), rbactest.customer_ADMIN(oldCustomer)); + call rbac.grantRoleToRole(rbactest.package_OWNER(NEW), rbactest.customer_ADMIN(newCustomer)); - call rbac.revokeRoleFromRole(testCustomerTENANT(oldCustomer), testPackageTENANT(OLD)); - call rbac.grantRoleToRole(testCustomerTENANT(newCustomer), testPackageTENANT(NEW)); + call rbac.revokeRoleFromRole(rbactest.customer_TENANT(oldCustomer), rbactest.package_TENANT(OLD)); + call rbac.grantRoleToRole(rbactest.customer_TENANT(newCustomer), rbactest.package_TENANT(NEW)); end if; @@ -161,7 +161,7 @@ do language plpgsql $$ LOOP call rbac.grantPermissionToRole( rbac.createPermission(row.uuid, 'INSERT', 'rbactest.package'), - testCustomerADMIN(row)); + rbactest.customer_ADMIN(row)); END LOOP; end; $$; @@ -177,7 +177,7 @@ begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( rbac.createPermission(NEW.uuid, 'INSERT', 'rbactest.package'), - testCustomerADMIN(NEW)); + rbactest.customer_ADMIN(NEW)); -- end. return NEW; end; $$; diff --git a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql index 4b227df2..c86f5aba 100644 --- a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql +++ b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql @@ -30,8 +30,8 @@ begin returning * into pac; call rbac.grantRoleToSubject( - rbac.getRoleId(testCustomerAdmin(cust)), - rbac.findRoleId(testPackageAdmin(pac)), + rbac.getRoleId(rbactest.customer_ADMIN(cust)), + rbac.findRoleId(rbactest.package_ADMIN(pac)), rbac.create_subject('pac-admin-' || pacName || '@' || cust.prefix || '.example.com'), true); diff --git a/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql b/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql index 7aada58b..4d5ff601 100644 --- a/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql +++ b/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql @@ -40,17 +40,17 @@ begin perform rbac.defineRoleWithGrants( - testDomainOWNER(NEW), + rbactest.domain_OWNER(NEW), permissions => array['DELETE', 'UPDATE'], - incomingSuperRoles => array[testPackageADMIN(newPackage)], - outgoingSubRoles => array[testPackageTENANT(newPackage)] + incomingSuperRoles => array[rbactest.package_ADMIN(newPackage)], + outgoingSubRoles => array[rbactest.package_TENANT(newPackage)] ); perform rbac.defineRoleWithGrants( - testDomainADMIN(NEW), + rbactest.domain_ADMIN(NEW), permissions => array['SELECT'], - incomingSuperRoles => array[testDomainOWNER(NEW)], - outgoingSubRoles => array[testPackageTENANT(newPackage)] + incomingSuperRoles => array[rbactest.domain_OWNER(NEW)], + outgoingSubRoles => array[rbactest.package_TENANT(newPackage)] ); call rbac.leaveTriggerForObjectUuid(NEW.uuid); @@ -106,14 +106,14 @@ begin if NEW.packageUuid <> OLD.packageUuid then - call rbac.revokeRoleFromRole(testDomainOWNER(OLD), testPackageADMIN(oldPackage)); - call rbac.grantRoleToRole(testDomainOWNER(NEW), testPackageADMIN(newPackage)); + call rbac.revokeRoleFromRole(rbactest.domain_OWNER(OLD), rbactest.package_ADMIN(oldPackage)); + call rbac.grantRoleToRole(rbactest.domain_OWNER(NEW), rbactest.package_ADMIN(newPackage)); - call rbac.revokeRoleFromRole(testPackageTENANT(oldPackage), testDomainOWNER(OLD)); - call rbac.grantRoleToRole(testPackageTENANT(newPackage), testDomainOWNER(NEW)); + call rbac.revokeRoleFromRole(rbactest.package_TENANT(oldPackage), rbactest.domain_OWNER(OLD)); + call rbac.grantRoleToRole(rbactest.package_TENANT(newPackage), rbactest.domain_OWNER(NEW)); - call rbac.revokeRoleFromRole(testPackageTENANT(oldPackage), testDomainADMIN(OLD)); - call rbac.grantRoleToRole(testPackageTENANT(newPackage), testDomainADMIN(NEW)); + call rbac.revokeRoleFromRole(rbactest.package_TENANT(oldPackage), rbactest.domain_ADMIN(OLD)); + call rbac.grantRoleToRole(rbactest.package_TENANT(newPackage), rbactest.domain_ADMIN(NEW)); end if; @@ -160,7 +160,7 @@ do language plpgsql $$ LOOP call rbac.grantPermissionToRole( rbac.createPermission(row.uuid, 'INSERT', 'rbactest.domain'), - testPackageADMIN(row)); + rbactest.package_ADMIN(row)); END LOOP; end; $$; @@ -176,7 +176,7 @@ begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( rbac.createPermission(NEW.uuid, 'INSERT', 'rbactest.domain'), - testPackageADMIN(NEW)); + rbactest.package_ADMIN(NEW)); -- end. return NEW; end; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql b/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql index fad804a1..12c2517e 100644 --- a/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql @@ -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()], 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); diff --git a/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql b/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql index 2a0f1a42..0a7fabb5 100644 --- a/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql @@ -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()], 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); diff --git a/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql b/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql index 1d750626..b390f638 100644 --- a/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql @@ -48,42 +48,42 @@ begin perform rbac.defineRoleWithGrants( - hsOfficeRelationOWNER(NEW), + hs_office.relation_OWNER(NEW), permissions => array['DELETE'], incomingSuperRoles => array[rbac.globalADMIN()], 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; $$; @@ -186,7 +186,7 @@ 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; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql index 79dab51e..c490423b 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql @@ -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; diff --git a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql index 3257b0a0..0726cc38 100644 --- a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql @@ -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()], 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); diff --git a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql index 255aa486..449d42fd 100644 --- a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql @@ -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; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql index 300729d8..9f60b327 100644 --- a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql @@ -48,34 +48,34 @@ begin perform rbac.defineRoleWithGrants( - hsOfficeSepaMandateOWNER(NEW), + hs_office.sepamandate_OWNER(NEW), permissions => array['DELETE'], incomingSuperRoles => array[rbac.globalADMIN()], 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; $$; @@ -137,7 +137,7 @@ 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; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql index 8ee6d6e4..855b0870 100644 --- a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql @@ -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); diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql index 83e86775..dabbe8f6 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql @@ -38,8 +38,8 @@ 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; $$; @@ -84,7 +84,7 @@ do language plpgsql $$ LOOP call rbac.grantPermissionToRole( rbac.createPermission(row.uuid, 'INSERT', 'hs_office.coopsharestransaction'), - hsOfficeMembershipADMIN(row)); + hs_office.membership_ADMIN(row)); END LOOP; end; $$; @@ -100,7 +100,7 @@ begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.coopsharestransaction'), - hsOfficeMembershipADMIN(NEW)); + hs_office.membership_ADMIN(NEW)); -- end. return NEW; end; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql index fcbd5cbc..20530fb9 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql @@ -38,8 +38,8 @@ 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; $$; @@ -84,7 +84,7 @@ do language plpgsql $$ LOOP call rbac.grantPermissionToRole( rbac.createPermission(row.uuid, 'INSERT', 'hs_office.coopassetstransaction'), - hsOfficeMembershipADMIN(row)); + hs_office.membership_ADMIN(row)); END LOOP; end; $$; @@ -100,7 +100,7 @@ begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.coopassetstransaction'), - hsOfficeMembershipADMIN(NEW)); + hs_office.membership_ADMIN(NEW)); -- end. return NEW; end; $$; diff --git a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql index 72809815..7417338e 100644 --- a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql @@ -48,26 +48,26 @@ begin perform rbac.defineRoleWithGrants( - hsBookingProjectOWNER(NEW), - incomingSuperRoles => array[hsOfficeRelationAGENT(newDebitorRel, rbac.unassumed())] + hs_booking.project_OWNER(NEW), + incomingSuperRoles => array[hs_office.relation_AGENT(newDebitorRel, rbac.unassumed())] ); perform rbac.defineRoleWithGrants( - hsBookingProjectADMIN(NEW), + hs_booking.project_ADMIN(NEW), permissions => array['UPDATE'], - incomingSuperRoles => array[hsBookingProjectOWNER(NEW)] + incomingSuperRoles => array[hs_booking.project_OWNER(NEW)] ); perform rbac.defineRoleWithGrants( - hsBookingProjectAGENT(NEW), - incomingSuperRoles => array[hsBookingProjectADMIN(NEW)] + hs_booking.project_AGENT(NEW), + incomingSuperRoles => array[hs_booking.project_ADMIN(NEW)] ); perform rbac.defineRoleWithGrants( - hsBookingProjectTENANT(NEW), + hs_booking.project_TENANT(NEW), permissions => array['SELECT'], - incomingSuperRoles => array[hsBookingProjectAGENT(NEW)], - outgoingSubRoles => array[hsOfficeRelationTENANT(newDebitorRel)] + incomingSuperRoles => array[hs_booking.project_AGENT(NEW)], + outgoingSubRoles => array[hs_office.relation_TENANT(newDebitorRel)] ); call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'DELETE'), rbac.globalAdmin()); @@ -115,7 +115,7 @@ do language plpgsql $$ LOOP call rbac.grantPermissionToRole( rbac.createPermission(row.uuid, 'INSERT', 'hs_booking.project'), - hsOfficeRelationADMIN(row)); + hs_office.relation_ADMIN(row)); END LOOP; end; $$; @@ -131,7 +131,7 @@ begin if NEW.type = 'DEBITOR' then call rbac.grantPermissionToRole( rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking.project'), - hsOfficeRelationADMIN(NEW)); + hs_office.relation_ADMIN(NEW)); end if; return NEW; end; $$; diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql index 483fcdd3..6a955014 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql @@ -41,30 +41,30 @@ begin SELECT * FROM hs_booking.item WHERE uuid = NEW.parentItemUuid INTO newParentItem; perform rbac.defineRoleWithGrants( - hsBookingItemOWNER(NEW), + hs_booking.item_OWNER(NEW), incomingSuperRoles => array[ - hsBookingItemAGENT(newParentItem), - hsBookingProjectAGENT(newProject)] + hs_booking.item_AGENT(newParentItem), + hs_booking.project_AGENT(newProject)] ); perform rbac.defineRoleWithGrants( - hsBookingItemADMIN(NEW), + hs_booking.item_ADMIN(NEW), permissions => array['UPDATE'], - incomingSuperRoles => array[hsBookingItemOWNER(NEW)] + incomingSuperRoles => array[hs_booking.item_OWNER(NEW)] ); perform rbac.defineRoleWithGrants( - hsBookingItemAGENT(NEW), - incomingSuperRoles => array[hsBookingItemADMIN(NEW)] + hs_booking.item_AGENT(NEW), + incomingSuperRoles => array[hs_booking.item_ADMIN(NEW)] ); perform rbac.defineRoleWithGrants( - hsBookingItemTENANT(NEW), + hs_booking.item_TENANT(NEW), permissions => array['SELECT'], - incomingSuperRoles => array[hsBookingItemAGENT(NEW)], + incomingSuperRoles => array[hs_booking.item_AGENT(NEW)], outgoingSubRoles => array[ - hsBookingItemTENANT(newParentItem), - hsBookingProjectTENANT(newProject)] + hs_booking.item_TENANT(newParentItem), + hs_booking.project_TENANT(newProject)] ); @@ -157,7 +157,7 @@ do language plpgsql $$ LOOP call rbac.grantPermissionToRole( rbac.createPermission(row.uuid, 'INSERT', 'hs_booking.item'), - hsBookingProjectADMIN(row)); + hs_booking.project_ADMIN(row)); END LOOP; end; $$; @@ -173,7 +173,7 @@ begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking.item'), - hsBookingProjectADMIN(NEW)); + hs_booking.project_ADMIN(NEW)); -- end. return NEW; end; $$; @@ -200,7 +200,7 @@ begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking.item'), - hsBookingItemADMIN(NEW)); + hs_booking.item_ADMIN(NEW)); -- end. return NEW; end; $$; diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql index ef7849db..fc3492c7 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql @@ -47,43 +47,43 @@ begin SELECT * FROM hs_hosting.asset WHERE uuid = NEW.parentAssetUuid INTO newParentAsset; perform rbac.defineRoleWithGrants( - hsHostingAssetOWNER(NEW), + hs_hosting.asset_OWNER(NEW), permissions => array['DELETE'], incomingSuperRoles => array[ - hsBookingItemADMIN(newBookingItem), - hsHostingAssetADMIN(newParentAsset), + hs_booking.item_ADMIN(newBookingItem), + hs_hosting.asset_ADMIN(newParentAsset), rbac.globalADMIN(rbac.unassumed())], subjectUuids => array[rbac.currentSubjectUuid()] ); perform rbac.defineRoleWithGrants( - hsHostingAssetADMIN(NEW), + hs_hosting.asset_ADMIN(NEW), permissions => array['UPDATE'], incomingSuperRoles => array[ - hsBookingItemAGENT(newBookingItem), - hsHostingAssetAGENT(newParentAsset), - hsHostingAssetOWNER(NEW)] + hs_booking.item_AGENT(newBookingItem), + hs_hosting.asset_AGENT(newParentAsset), + hs_hosting.asset_OWNER(NEW)] ); perform rbac.defineRoleWithGrants( - hsHostingAssetAGENT(NEW), + hs_hosting.asset_AGENT(NEW), incomingSuperRoles => array[ - hsHostingAssetADMIN(NEW), - hsHostingAssetAGENT(newAssignedToAsset)], + hs_hosting.asset_ADMIN(NEW), + hs_hosting.asset_AGENT(newAssignedToAsset)], outgoingSubRoles => array[ - hsHostingAssetTENANT(newAssignedToAsset), - hsOfficeContactREFERRER(newAlarmContact)] + hs_hosting.asset_TENANT(newAssignedToAsset), + hs_office.contact_REFERRER(newAlarmContact)] ); perform rbac.defineRoleWithGrants( - hsHostingAssetTENANT(NEW), + hs_hosting.asset_TENANT(NEW), permissions => array['SELECT'], incomingSuperRoles => array[ - hsHostingAssetAGENT(NEW), - hsOfficeContactADMIN(newAlarmContact)], + hs_hosting.asset_AGENT(NEW), + hs_office.contact_ADMIN(newAlarmContact)], outgoingSubRoles => array[ - hsBookingItemTENANT(newBookingItem), - hsHostingAssetTENANT(newParentAsset)] + hs_booking.item_TENANT(newBookingItem), + hs_hosting.asset_TENANT(newParentAsset)] ); IF NEW.type = 'DOMAIN_SETUP' THEN diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index b4945a0f..923c62e9 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -7,7 +7,7 @@ spring: url-tc: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers url-tcx: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers?TC_REUSABLE=true&TC_DAEMON=true url-local: jdbc:postgresql://localhost:5432/postgres - url: ${spring.datasource.url-local} + url: ${spring.datasource.url-tc} username: postgres password: password -- 2.39.5 From 7decf28293cb948444cccda056beb21381270509 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 19 Sep 2024 13:24:08 +0200 Subject: [PATCH 07/14] rename customerOwner -> rbactest.customer_OWNER etc. -- generated --- ...sive-cte-experiments-for-accessible-uuids.sql | 2 +- .../relation/HsOfficeRelationRbacRepository.java | 2 +- .../relation/HsOfficeRelationRealRepository.java | 2 +- .../rbac/generator/InsertTriggerGenerator.java | 2 +- .../hsadminng/rbac/generator/RbacView.java | 5 +++++ .../RolesGrantsAndPermissionsGenerator.java | 16 +++++----------- .../db/changelog/1-rbac/1080-rbac-global.sql | 8 ++++---- .../2013-rbactest-customer-rbac.sql | 6 +++--- .../501-contact/5013-hs-office-contact-rbac.sql | 2 +- .../502-person/5020-hs-office-person.sql | 6 +++--- .../502-person/5023-hs-office-person-rbac.sql | 2 +- .../5028-hs-office-person-test-data.sql | 2 +- .../503-relation/5030-hs-office-relation.sql | 6 +++--- .../5033-hs-office-relation-rbac.sql | 2 +- .../5038-hs-office-relation-test-data.sql | 2 +- .../504-partner/5043-hs-office-partner-rbac.sql | 4 ++-- .../5044-hs-office-partner-details-rbac.sql | 4 ++-- .../5053-hs-office-bankaccount-rbac.sql | 2 +- .../506-debitor/5063-hs-office-debitor-rbac.sql | 4 ++-- .../5073-hs-office-sepamandate-rbac.sql | 2 +- .../5103-hs-office-membership-rbac.sql | 4 ++-- .../511-coopshares/5110-hs-office-coopshares.sql | 6 +++--- .../512-coopassets/5120-hs-office-coopassets.sql | 6 +++--- .../6203-hs-booking-project-rbac.sql | 2 +- .../630-booking-item/6300-hs-booking-item.sql | 6 +++--- .../6303-hs-booking-item-rbac.sql | 6 +++--- .../701-hosting-asset/7010-hs-hosting-asset.sql | 14 +++++++------- .../7013-hs-hosting-asset-rbac.sql | 2 +- .../hs/migration/ImportHostingAssets.java | 2 +- ...HsOfficeRelationControllerAcceptanceTest.java | 3 --- 30 files changed, 64 insertions(+), 68 deletions(-) diff --git a/sql/recursive-cte-experiments-for-accessible-uuids.sql b/sql/recursive-cte-experiments-for-accessible-uuids.sql index bb86d6ec..5988c6d6 100644 --- a/sql/recursive-cte-experiments-for-accessible-uuids.sql +++ b/sql/recursive-cte-experiments-for-accessible-uuids.sql @@ -151,7 +151,7 @@ end transaction; alter table rbacobject -- just for performance testing, we would need a joined enum or a varchar(16) which would make it slow - add column type hs_hosting.hshostingassettype; + add column type hs_hosting.AssetType; -- and fill the type column with hs_hosting.asset types: diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java index e12d0256..3c89a0b7 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRbacRepository.java @@ -24,7 +24,7 @@ public interface HsOfficeRelationRbacRepository extends Repository findRelationRelatedToPersonUuidAndRelationTypeString(@NotNull UUID personUuid, String relationType); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRealRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRealRepository.java index 220ea6f4..9cf58b86 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRealRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationRealRepository.java @@ -24,7 +24,7 @@ public interface HsOfficeRelationRealRepository extends Repository findRelationRelatedToPersonUuidAndRelationTypeString(@NotNull UUID personUuid, String relationType); diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java b/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java index 1654bbc7..8ab6a70d 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java @@ -325,7 +325,7 @@ public class InsertTriggerGenerator { private String toRoleDescriptor(final RbacView.RbacRoleDefinition roleDef, final String ref) { - final var functionName = toVar(roleDef); + final var functionName = roleDef.descriptorFunctionName(); if (roleDef.getEntityAlias().isGlobal()) { return functionName + "()"; } diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java index 2c2d339a..c2bc687d 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java @@ -29,6 +29,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.RbacGrantDefinit import static net.hostsharing.hsadminng.rbac.generator.RbacView.RbacSubjectReference.UserRole.CREATOR; import static net.hostsharing.hsadminng.rbac.generator.RbacView.SQL.Part.AUTO_FETCH; import static org.apache.commons.collections4.SetUtils.hashSet; +import static org.apache.commons.lang3.StringUtils.capitalize; import static org.apache.commons.lang3.StringUtils.uncapitalize; @Getter @@ -830,6 +831,10 @@ public class RbacView { public boolean isGlobal(final Role role) { return entityAlias.isGlobal() && this.role == role; } + + public String descriptorFunctionName() { + return entityAlias.getRawTableNameWithSchema() + "_" + capitalize(role.name()); + } } public RbacSubjectReference findUserRef(final RbacSubjectReference.UserRole userRole) { diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RolesGrantsAndPermissionsGenerator.java b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RolesGrantsAndPermissionsGenerator.java index 22a9b9d3..6d880144 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RolesGrantsAndPermissionsGenerator.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RolesGrantsAndPermissionsGenerator.java @@ -20,7 +20,6 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.RbacGrantDefinit import static net.hostsharing.hsadminng.rbac.generator.RbacView.Role.*; import static net.hostsharing.hsadminng.rbac.generator.StringWriter.with; import static org.apache.commons.lang3.StringUtils.capitalize; -import static org.apache.commons.lang3.StringUtils.uncapitalize; class RolesGrantsAndPermissionsGenerator { @@ -362,11 +361,10 @@ class RolesGrantsAndPermissionsGenerator { System.out.println("null"); } if (roleDef.getEntityAlias().isGlobal()) { - return "rbac.globalAdmin()"; + return "rbac.global_ADMIN()"; } final String entityRefVar = entityRefVar(rootRefVar, roleDef.getEntityAlias()); - return roleDef.getEntityAlias().simpleName() + capitalize(roleDef.getRole().name()) - + "(" + entityRefVar + ")"; + return roleDef.descriptorFunctionName() + "(" + entityRefVar + ")"; } private String entityRefVar( @@ -389,8 +387,8 @@ class RolesGrantsAndPermissionsGenerator { plPgSql.writeLn(); plPgSql.writeLn("perform rbac.defineRoleWithGrants("); plPgSql.indented(() -> { - plPgSql.writeLn("${simpleVarName)${roleSuffix}(NEW)," - .replace("${simpleVarName)", simpleEntityVarName) + plPgSql.writeLn("${qualifiedRawTableName)_${roleSuffix}(NEW)," + .replace("${qualifiedRawTableName)", qualifiedRawTableName) .replace("${roleSuffix}", capitalize(role.name()))); generatePermissionsForRole(plPgSql, role); @@ -593,16 +591,12 @@ class RolesGrantsAndPermissionsGenerator { final RbacView.RbacRoleDefinition roleDef, final boolean assumed) { final var assumedArg = assumed ? "" : ", rbac.unassumed()"; - return toRoleRef(roleDef) + + return roleDef.descriptorFunctionName() + (roleDef.getEntityAlias().isGlobal() ? ( assumed ? "()" : "(rbac.unassumed())") : rbacDef.isRootEntityAlias(roleDef.getEntityAlias()) ? ("(" + triggerRef.name() + ")") : "(" + toTriggerReference(triggerRef, roleDef.getEntityAlias()) + assumedArg + ")"); } - private static String toRoleRef(final RbacView.RbacRoleDefinition roleDef) { - return uncapitalize(roleDef.getEntityAlias().simpleName()) + capitalize(roleDef.getRole().name()); - } - private static String toTriggerReference( final PostgresTriggerReference triggerRef, final RbacView.EntityAlias entityAlias) { diff --git a/src/main/resources/db/changelog/1-rbac/1080-rbac-global.sql b/src/main/resources/db/changelog/1-rbac/1080-rbac-global.sql index cf62891f..a5514401 100644 --- a/src/main/resources/db/changelog/1-rbac/1080-rbac-global.sql +++ b/src/main/resources/db/changelog/1-rbac/1080-rbac-global.sql @@ -30,7 +30,7 @@ create or replace function rbac.isGlobalAdmin() returns boolean language plpgsql as $$ begin - return rbac.isGranted(rbac.currentSubjectOrAssumedRolesUuids(), rbac.findRoleId(rbac.globalAdmin())); + return rbac.isGranted(rbac.currentSubjectOrAssumedRolesUuids(), rbac.findRoleId(rbac.global_ADMIN())); end; $$; --// @@ -109,7 +109,7 @@ commit; /* A rbac.Global administrator role. */ -create or replace function rbac.globalAdmin(assumed boolean = true) +create or replace function rbac.global_ADMIN(assumed boolean = true) returns rbac.RoleDescriptor returns null on null input stable -- leakproof @@ -119,7 +119,7 @@ $$; begin transaction; call base.defineContext('creating role:rbac.global#global:ADMIN', null, null, null); - select rbac.createRole(rbac.globalAdmin()); + select rbac.createRole(rbac.global_ADMIN()); commit; --// @@ -157,7 +157,7 @@ do language plpgsql $$ begin call base.defineContext('creating fake test-realm admin users', null, null, null); - admins = rbac.findRoleId(rbac.globalAdmin()); + admins = rbac.findRoleId(rbac.global_ADMIN()); call rbac.grantRoleToSubjectUnchecked(admins, admins, rbac.create_subject('superuser-alex@hostsharing.net')); call rbac.grantRoleToSubjectUnchecked(admins, admins, rbac.create_subject('superuser-fran@hostsharing.net')); perform rbac.create_subject('selfregistered-user-drew@hostsharing.org'); diff --git a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql index f46fdecf..69bc70b3 100644 --- a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql +++ b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql @@ -37,7 +37,7 @@ begin perform rbac.defineRoleWithGrants( rbactest.customer_OWNER(NEW), permissions => array['DELETE'], - incomingSuperRoles => array[rbac.globalADMIN(rbac.unassumed())], + incomingSuperRoles => array[rbac.global_ADMIN(rbac.unassumed())], subjectUuids => array[rbac.currentSubjectUuid()] ); @@ -96,7 +96,7 @@ do language plpgsql $$ LOOP call rbac.grantPermissionToRole( rbac.createPermission(row.uuid, 'INSERT', 'rbactest.customer'), - rbac.globalADMIN()); + rbac.global_ADMIN()); END LOOP; end; $$; @@ -112,7 +112,7 @@ begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( rbac.createPermission(NEW.uuid, 'INSERT', 'rbactest.customer'), - rbac.globalADMIN()); + rbac.global_ADMIN()); -- end. return NEW; end; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql b/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql index 12c2517e..08bdcfc3 100644 --- a/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/501-contact/5013-hs-office-contact-rbac.sql @@ -37,7 +37,7 @@ begin perform rbac.defineRoleWithGrants( hs_office.contact_OWNER(NEW), permissions => array['DELETE'], - incomingSuperRoles => array[rbac.globalADMIN()], + incomingSuperRoles => array[rbac.global_ADMIN()], subjectUuids => array[rbac.currentSubjectUuid()] ); diff --git a/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql b/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql index 81245561..a2e72952 100644 --- a/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql +++ b/src/main/resources/db/changelog/5-hs-office/502-person/5020-hs-office-person.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:hs-office-person-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -CREATE TYPE hs_office.HsOfficePersonType AS ENUM ( +CREATE TYPE hs_office.PersonType AS ENUM ( '??', -- unknown 'NP', -- natural person 'LP', -- legal person @@ -12,13 +12,13 @@ CREATE TYPE hs_office.HsOfficePersonType AS ENUM ( 'UF', -- unincorporated firm 'PI'); -- public institution -CREATE CAST (character varying as hs_office.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 hs_office.HsOfficePersonType not null, + personType hs_office.PersonType not null, tradeName varchar(96), salutation varchar(30), title varchar(20), diff --git a/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql b/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql index 0a7fabb5..2f8df513 100644 --- a/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/502-person/5023-hs-office-person-rbac.sql @@ -37,7 +37,7 @@ begin perform rbac.defineRoleWithGrants( hs_office.person_OWNER(NEW), permissions => array['DELETE'], - incomingSuperRoles => array[rbac.globalADMIN()], + incomingSuperRoles => array[rbac.global_ADMIN()], subjectUuids => array[rbac.currentSubjectUuid()] ); diff --git a/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql b/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql index ae02d0d3..26aaae99 100644 --- a/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql @@ -9,7 +9,7 @@ Creates a single person test record. */ create or replace procedure createHsOfficePersonTestData( - newPersonType hs_office.HsOfficePersonType, + newPersonType hs_office.PersonType, newTradeName varchar, newFamilyName varchar = null, newGivenName varchar = null diff --git a/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql b/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql index 8c946f66..a1498fb3 100644 --- a/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql +++ b/src/main/resources/db/changelog/5-hs-office/503-relation/5030-hs-office-relation.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:hs-office-relation-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -CREATE TYPE hs_office.HsOfficeRelationType AS ENUM ( +CREATE TYPE hs_office.RelationType AS ENUM ( 'UNKNOWN', 'PARTNER', 'EX_PARTNER', @@ -14,7 +14,7 @@ CREATE TYPE hs_office.HsOfficeRelationType AS ENUM ( 'OPERATIONS', 'SUBSCRIBER'); -CREATE CAST (character varying as hs_office.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 hs_office.HsOfficeRelationType not null, + type hs_office.RelationType not null, mark varchar(24) ); --// diff --git a/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql b/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql index b390f638..d23d0d09 100644 --- a/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql @@ -50,7 +50,7 @@ begin perform rbac.defineRoleWithGrants( hs_office.relation_OWNER(NEW), permissions => array['DELETE'], - incomingSuperRoles => array[rbac.globalADMIN()], + incomingSuperRoles => array[rbac.global_ADMIN()], subjectUuids => array[rbac.currentSubjectUuid()] ); diff --git a/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql b/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql index 0de446e8..d3d97683 100644 --- a/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql @@ -10,7 +10,7 @@ */ create or replace procedure createHsOfficeRelationTestData( holderPersonName varchar, - relationType hs_office.HsOfficeRelationType, + relationType hs_office.RelationType, anchorPersonName varchar, contactCaption varchar, mark varchar default null) diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql index c490423b..9186dd7d 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql @@ -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; $$; @@ -189,7 +189,7 @@ 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; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql index 27b2f489..50c7dc92 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql @@ -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; $$; @@ -93,7 +93,7 @@ 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; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql index 0726cc38..e283c13f 100644 --- a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5053-hs-office-bankaccount-rbac.sql @@ -37,7 +37,7 @@ begin perform rbac.defineRoleWithGrants( hs_office.bankaccount_OWNER(NEW), permissions => array['DELETE'], - incomingSuperRoles => array[rbac.globalADMIN()], + incomingSuperRoles => array[rbac.global_ADMIN()], subjectUuids => array[rbac.currentSubjectUuid()] ); diff --git a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql index 449d42fd..7f23e273 100644 --- a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql @@ -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; $$; @@ -162,7 +162,7 @@ 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; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql index 9f60b327..5a693add 100644 --- a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql @@ -50,7 +50,7 @@ begin perform rbac.defineRoleWithGrants( hs_office.sepamandate_OWNER(NEW), permissions => array['DELETE'], - incomingSuperRoles => array[rbac.globalADMIN()], + incomingSuperRoles => array[rbac.global_ADMIN()], subjectUuids => array[rbac.currentSubjectUuid()] ); diff --git a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql index 855b0870..6ad7515f 100644 --- a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql @@ -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; $$; @@ -124,7 +124,7 @@ 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; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql index 5cf3ef82..b2bd2441 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql @@ -4,16 +4,16 @@ --changeset michael.hoennig:hs-office-coopshares-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -CREATE TYPE hs_office.HsOfficeCoopSharesTransactionType AS ENUM ('ADJUSTMENT', 'SUBSCRIPTION', 'CANCELLATION'); +CREATE TYPE hs_office.CoopSharesTransactionType AS ENUM ('ADJUSTMENT', 'SUBSCRIPTION', 'CANCELLATION'); -CREATE CAST (character varying as hs_office.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 ( 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 hs_office.HsOfficeCoopSharesTransactionType not null, + transactionType hs_office.CoopSharesTransactionType not null, valueDate date not null, shareCount integer not null, reference varchar(48) not null, diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql index 4da4e0bd..3407247f 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:hs-office-coopassets-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -CREATE TYPE hs_office.HsOfficeCoopAssetsTransactionType AS ENUM ('ADJUSTMENT', +CREATE TYPE hs_office.CoopAssetsTransactionType AS ENUM ('ADJUSTMENT', 'DEPOSIT', 'DISBURSAL', 'TRANSFER', @@ -13,14 +13,14 @@ CREATE TYPE hs_office.HsOfficeCoopAssetsTransactionType AS ENUM ('ADJUSTMENT', 'LOSS', 'LIMITATION'); -CREATE CAST (character varying as hs_office.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 ( 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 hs_office.HsOfficeCoopAssetsTransactionType not null, + transactionType hs_office.CoopAssetsTransactionType not null, valueDate date not null, assetValue money not null, reference varchar(48) not null, diff --git a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql index 7417338e..80a3403e 100644 --- a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql @@ -70,7 +70,7 @@ begin outgoingSubRoles => array[hs_office.relation_TENANT(newDebitorRel)] ); - call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'DELETE'), rbac.globalAdmin()); + call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'DELETE'), rbac.global_ADMIN()); call rbac.leaveTriggerForObjectUuid(NEW.uuid); end; $$; diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql index ad56e436..cf19aa32 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6300-hs-booking-item.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:booking-item-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -create type hs_booking.HsBookingItemType as enum ( +create type hs_booking.ItemType as enum ( 'PRIVATE_CLOUD', 'CLOUD_SERVER', 'MANAGED_SERVER', @@ -12,14 +12,14 @@ create type hs_booking.HsBookingItemType as enum ( 'DOMAIN_SETUP' ); -CREATE CAST (character varying as hs_booking.HsBookingItemType) WITH INOUT AS IMPLICIT; +CREATE CAST (character varying as hs_booking.ItemType) WITH INOUT AS IMPLICIT; create table if not exists hs_booking.item ( uuid uuid unique references rbac.object (uuid), version int not null default 0, projectUuid uuid null references hs_booking.project(uuid), - type hs_booking.HsBookingItemType not null, + type hs_booking.ItemType not null, parentItemUuid uuid null references hs_booking.item(uuid) initially deferred, validity daterange not null, caption varchar(80) not null, diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql index 6a955014..097d5671 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql @@ -69,7 +69,7 @@ begin - call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'DELETE'), rbac.globalAdmin()); + call rbac.grantPermissionToRole(rbac.createPermission(NEW.uuid, 'DELETE'), rbac.global_ADMIN()); call rbac.leaveTriggerForObjectUuid(NEW.uuid); end; $$; @@ -114,7 +114,7 @@ do language plpgsql $$ LOOP call rbac.grantPermissionToRole( rbac.createPermission(row.uuid, 'INSERT', 'hs_booking.item'), - rbac.globalADMIN()); + rbac.global_ADMIN()); END LOOP; end; $$; @@ -130,7 +130,7 @@ begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( rbac.createPermission(NEW.uuid, 'INSERT', 'hs_booking.item'), - rbac.globalADMIN()); + rbac.global_ADMIN()); -- end. return NEW; end; $$; diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql index 30b4b79a..304e7337 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql @@ -4,7 +4,7 @@ --changeset michael.hoennig:hosting-asset-MAIN-TABLE endDelimiter:--// -- ---------------------------------------------------------------------------- -create type hs_hosting.HsHostingAssetType as enum ( +create type hs_hosting.AssetType as enum ( 'CLOUD_SERVER', 'MANAGED_SERVER', 'MANAGED_WEBSPACE', @@ -26,14 +26,14 @@ create type hs_hosting.HsHostingAssetType as enum ( 'IPV6_NUMBER' ); -CREATE CAST (character varying as hs_hosting.HsHostingAssetType) WITH INOUT AS IMPLICIT; +CREATE CAST (character varying as hs_hosting.AssetType) WITH INOUT AS IMPLICIT; create table if not exists hs_hosting.asset ( uuid uuid unique references rbac.object (uuid), version int not null default 0, bookingItemUuid uuid null references hs_booking.item(uuid), - type hs_hosting.HsHostingAssetType not null, + type hs_hosting.AssetType not null, parentAssetUuid uuid null references hs_hosting.asset(uuid) initially deferred, assignedToAssetUuid uuid null references hs_hosting.asset(uuid) initially deferred, identifier varchar(80) not null, @@ -58,8 +58,8 @@ create or replace function hs_hosting.asset_type_hierarchy_check_tf() returns trigger language plpgsql as $$ declare - actualParentType hs_hosting.HsHostingAssetType; - expectedParentType hs_hosting.HsHostingAssetType; + actualParentType hs_hosting.AssetType; + expectedParentType hs_hosting.AssetType; begin if NEW.parentAssetUuid is not null then actualParentType := (select type @@ -134,8 +134,8 @@ create or replace function hs_hosting.asset_booking_item_hierarchy_check_tf() returns trigger language plpgsql as $$ declare - actualBookingItemType hs_booking.HsBookingItemType; - expectedBookingItemType hs_booking.HsBookingItemType; + actualBookingItemType hs_booking.ItemType; + expectedBookingItemType hs_booking.ItemType; begin actualBookingItemType := (select type from hs_booking.item diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql index fc3492c7..4e2137af 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql @@ -52,7 +52,7 @@ begin incomingSuperRoles => array[ hs_booking.item_ADMIN(newBookingItem), hs_hosting.asset_ADMIN(newParentAsset), - rbac.globalADMIN(rbac.unassumed())], + rbac.global_ADMIN(rbac.unassumed())], subjectUuids => array[rbac.currentSubjectUuid()] ); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java index 2fd29b56..9d73ac89 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java @@ -1145,7 +1145,7 @@ public class ImportHostingAssets extends BaseOfficeDataImport { final int expectedCountInTestDataCount, final int minCountExpectedInProdData) { final var q = em.createNativeQuery( - "select count(*) from hs_hosting.asset where type = cast(:type as hs_hosting.HsHostingAssetType)", + "select count(*) from hs_hosting.asset where type = cast(:type as hs_hosting.AssetType)", Integer.class); q.setParameter("type", assetType.name()); final var count = (Integer) q.getSingleResult(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java index 44605216..25e1629e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/relation/HsOfficeRelationControllerAcceptanceTest.java @@ -39,9 +39,6 @@ class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithClean @Autowired Context context; - @Autowired - Context contextMock; - @Autowired HsOfficeRelationRealRepository relationrealRepo; -- 2.39.5 From 7563f322151c6f15c1fc618103c78b0e347134a2 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 20 Sep 2024 08:44:35 +0200 Subject: [PATCH 08/14] move legacy_id trigger-functions to module schema --- .../501-contact/5016-hs-office-contact-migration.sql | 12 ++++++------ .../504-partner/5046-hs-office-partner-migration.sql | 12 ++++++------ .../5076-hs-office-sepamandate-migration.sql | 12 ++++++------ .../5116-hs-office-coopshares-migration.sql | 12 ++++++------ .../5126-hs-office-coopassets-migration.sql | 12 ++++++------ .../7016-hs-hosting-asset-migration.sql | 12 ++++++------ src/test/resources/application.yml | 2 +- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/main/resources/db/changelog/5-hs-office/501-contact/5016-hs-office-contact-migration.sql b/src/main/resources/db/changelog/5-hs-office/501-contact/5016-hs-office-contact-migration.sql index ae41ee0f..4e0683a8 100644 --- a/src/main/resources/db/changelog/5-hs-office/501-contact/5016-hs-office-contact-migration.sql +++ b/src/main/resources/db/changelog/5-hs-office/501-contact/5016-hs-office-contact-migration.sql @@ -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(); --/ diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5046-hs-office-partner-migration.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5046-hs-office-partner-migration.sql index 5e79ecf8..0a4da2cd 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5046-hs-office-partner-migration.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5046-hs-office-partner-migration.sql @@ -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(); --/ diff --git a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5076-hs-office-sepamandate-migration.sql b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5076-hs-office-sepamandate-migration.sql index 2446eff9..977bd8d0 100644 --- a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5076-hs-office-sepamandate-migration.sql +++ b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5076-hs-office-sepamandate-migration.sql @@ -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(); --/ diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5116-hs-office-coopshares-migration.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5116-hs-office-coopshares-migration.sql index 40912e0c..1aaf2f0a 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5116-hs-office-coopshares-migration.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5116-hs-office-coopshares-migration.sql @@ -49,7 +49,7 @@ INSERT INTO hs_office.coopsharestransaction_legacy_id(uuid, member_share_id) -- ============================================================================ --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 +create trigger insert_legacy_id_mapping_tg after insert on hs_office.coopsharestransaction 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 +create trigger delete_legacy_id_mapping_tg before delete on hs_office.coopsharestransaction for each row - execute procedure deleteCoopSharesLegacyIdMapping(); + execute procedure hs_office.coopsharetx_delete_legacy_id_mapping_tf(); --/ diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5126-hs-office-coopassets-migration.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5126-hs-office-coopassets-migration.sql index 3919b13c..841ca6e6 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5126-hs-office-coopassets-migration.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5126-hs-office-coopassets-migration.sql @@ -49,7 +49,7 @@ INSERT INTO hs_office.coopassetstransaction_legacy_id(uuid, member_asset_id) -- ============================================================================ --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 $$ @@ -64,17 +64,17 @@ begin return NEW; end; $$; -create trigger createCoopAssetsLegacyIdMapping +create trigger insert_legacy_id_mapping_tg after insert on hs_office.coopassetstransaction 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 $$ @@ -89,8 +89,8 @@ begin return OLD; end; $$; -create trigger removeCoopAssetsLegacyIdMapping +create trigger delete_legacy_id_mapping_tg before delete on hs_office.coopassetstransaction for each row - execute procedure deleteCoopAssetsLegacyIdMapping(); + execute procedure hs_office.coopassettx_delete_legacy_id_mapping_tf(); --/ diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7016-hs-hosting-asset-migration.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7016-hs-hosting-asset-migration.sql index 1aff9f5e..b6edea34 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7016-hs-hosting-asset-migration.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7016-hs-hosting-asset-migration.sql @@ -49,7 +49,7 @@ INSERT INTO hs_hosting.asset_legacy_id(uuid, legacy_id) -- ============================================================================ --changeset hs-hosting-asset-MIGRATION-insert-trigger:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -create or replace function insertassetLegacyIdMapping() +create or replace function hs_hosting.asset_insert_legacy_id_mapping_tf() returns trigger language plpgsql strict as $$ @@ -64,17 +64,17 @@ begin return NEW; end; $$; -create trigger createassetLegacyIdMapping +create trigger insert_legacy_id_mapping_tg after insert on hs_hosting.asset for each row - execute procedure insertassetLegacyIdMapping(); + execute procedure hs_hosting.asset_insert_legacy_id_mapping_tf(); --/ -- ============================================================================ --changeset hs-hosting-asset-MIGRATION-delete-trigger:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -create or replace function deleteassetLegacyIdMapping_tf() +create or replace function hs_hosting.asset_delete_legacy_id_mapping_tf() returns trigger language plpgsql strict as $$ @@ -89,8 +89,8 @@ begin return OLD; end; $$; -create trigger deleteassetLegacyIdMapping_tg +create trigger delete_legacy_id_mapping_tg before delete on hs_hosting.asset for each row - execute procedure deleteassetLegacyIdMapping_tf(); + execute procedure hs_hosting.asset_delete_legacy_id_mapping_tf(); --/ diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 923c62e9..b4945a0f 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -7,7 +7,7 @@ spring: url-tc: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers url-tcx: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers?TC_REUSABLE=true&TC_DAEMON=true url-local: jdbc:postgresql://localhost:5432/postgres - url: ${spring.datasource.url-tc} + url: ${spring.datasource.url-local} username: postgres password: password -- 2.39.5 From bdf2ab6a2484e45fc1745454192aa18bb1f24b44 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 20 Sep 2024 08:51:42 +0200 Subject: [PATCH 09/14] move check-functions to module schemas --- .../5-hs-office/511-coopshares/5110-hs-office-coopshares.sql | 4 ++-- .../5-hs-office/512-coopassets/5120-hs-office-coopassets.sql | 4 ++-- src/test/resources/application.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql index b2bd2441..ade1156a 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql @@ -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 @@ -56,7 +56,7 @@ end; $$; alter table hs_office.coopsharestransaction add constraint check_positive_total_shares_count - check ( checkSharesByMembershipUuid(membershipUuid, shareCount) ); + check ( hs_office.coopsharestx_check_positive_total(membershipUuid, shareCount) ); --// diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql index 3407247f..0cefb464 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql @@ -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 @@ -64,7 +64,7 @@ end; $$; alter table hs_office.coopassetstransaction add constraint check_positive_total - check ( checkAssetsByMembershipUuid(membershipUuid, assetValue) ); + check ( hs_office.coopassetstx_check_positive_total(membershipUuid, assetValue) ); --// diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index b4945a0f..923c62e9 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -7,7 +7,7 @@ spring: url-tc: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers url-tcx: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers?TC_REUSABLE=true&TC_DAEMON=true url-local: jdbc:postgresql://localhost:5432/postgres - url: ${spring.datasource.url-local} + url: ${spring.datasource.url-tc} username: postgres password: password -- 2.39.5 From 3c326680531b96e3571a6736ac54ca39abab2add Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 20 Sep 2024 10:04:53 +0200 Subject: [PATCH 10/14] aling test-data-generation function names and fix some missing scopes --- .../2018-rbactest-customer-test-data.sql | 14 +++--- .../2028-rbactest-package-test-data.sql | 12 ++--- .../2038-rbactest-domain-test-data.sql | 24 +++++----- .../5018-hs-office-contact-test-data.sql | 30 ++++++------- .../5028-hs-office-person-test-data.sql | 45 ++++++------------- .../5038-hs-office-relation-test-data.sql | 36 +++++++-------- .../5048-hs-office-partner-test-data.sql | 12 ++--- .../5058-hs-office-bankaccount-test-data.sql | 18 ++++---- .../5068-hs-office-debitor-test-data.sql | 8 ++-- .../5078-hs-office-sepamandate-test-data.sql | 8 ++-- .../5108-hs-office-membership-test-data.sql | 8 ++-- .../5118-hs-office-coopshares-test-data.sql | 8 ++-- .../5128-hs-office-coopassets-test-data.sql | 8 ++-- .../6208-hs-booking-project-test-data.sql | 8 ++-- .../6308-hs-booking-item-test-data.sql | 8 ++-- .../7018-hs-hosting-asset-test-data.sql | 12 ++--- 16 files changed, 121 insertions(+), 138 deletions(-) diff --git a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql index 6fbd5d90..18c23fe4 100644 --- a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql +++ b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2018-rbactest-customer-test-data.sql @@ -7,7 +7,7 @@ /* Generates a customer reference number for a given test data counter. */ -create or replace function rbactest.testCustomerReference(customerCount integer) +create or replace function rbactest.customer_create_test_data(customerCount integer) returns integer returns null on null input language plpgsql as $$ @@ -19,7 +19,7 @@ end; $$; /* Creates a single customer test record with dist. */ -create or replace procedure rbactest.createTestCustomerTestData( +create or replace procedure rbactest.customer_create_test_data( custReference integer, custPrefix varchar ) @@ -51,7 +51,7 @@ end; $$; /* Creates a range of test customers for mass data generation. */ -create or replace procedure rbactest.createTestCustomerTestData( +create or replace procedure rbactest.customer_create_test_data( startCount integer, -- count of auto generated rows before the run endCount integer -- count of auto generated rows after the run ) @@ -59,7 +59,7 @@ create or replace procedure rbactest.createTestCustomerTestData( begin for t in startCount..endCount loop - call rbactest.createTestCustomerTestData(rbactest.testCustomerReference(t), base.intToVarChar(t, 3)); + call rbactest.customer_create_test_data(rbactest.testCustomerReference(t), base.intToVarChar(t, 3)); commit; end loop; end; $$; @@ -74,9 +74,9 @@ do language plpgsql $$ begin call base.defineContext('creating RBAC test customer', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN'); - call rbactest.createTestCustomerTestData(99901, 'xxx'); - call rbactest.createTestCustomerTestData(99902, 'yyy'); - call rbactest.createTestCustomerTestData(99903, 'zzz'); + call rbactest.customer_create_test_data(99901, 'xxx'); + call rbactest.customer_create_test_data(99902, 'yyy'); + call rbactest.customer_create_test_data(99903, 'zzz'); end; $$; --// diff --git a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql index c86f5aba..eae1342f 100644 --- a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql +++ b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2028-rbactest-package-test-data.sql @@ -6,7 +6,7 @@ /* Creates the given number of test packages for the given customer. */ -create or replace procedure rbactest.createPackageTestData(customerPrefix varchar, pacCount int) +create or replace procedure rbactest.package_create_test_data(customerPrefix varchar, pacCount int) language plpgsql as $$ declare cust rbactest.customer; @@ -41,7 +41,7 @@ end; $$; /* Creates a range of test packages for mass data generation. */ -create or replace procedure rbactest.createPackageTestData() +create or replace procedure rbactest.package_create_test_data() language plpgsql as $$ declare cust rbactest.customer; @@ -49,7 +49,7 @@ begin for cust in (select * from rbactest.customer) loop continue when cust.reference >= 90000; -- reserved for functional testing - call rbactest.createPackageTestData(cust.prefix, 3); + call rbactest.package_create_test_data(cust.prefix, 3); end loop; commit; @@ -64,9 +64,9 @@ $$; do language plpgsql $$ begin - call rbactest.createPackageTestData('xxx', 3); - call rbactest.createPackageTestData('yyy', 3); - call rbactest.createPackageTestData('zzz', 3); + call rbactest.package_create_test_data('xxx', 3); + call rbactest.package_create_test_data('yyy', 3); + call rbactest.package_create_test_data('zzz', 3); end; $$; --// diff --git a/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2038-rbactest-domain-test-data.sql b/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2038-rbactest-domain-test-data.sql index 23ce972c..5fbbfa8c 100644 --- a/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2038-rbactest-domain-test-data.sql +++ b/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2038-rbactest-domain-test-data.sql @@ -6,7 +6,7 @@ /* Creates the given count of test unix users for a single package. */ -create or replace procedure rbactest.createDomainTestData( packageName varchar, domainCount int ) +create or replace procedure rbactest.domain_create_test_data( packageName varchar, domainCount int ) language plpgsql as $$ declare pac record; @@ -32,7 +32,7 @@ end; $$; /* Creates a range of unix users for mass data generation. */ -create or replace procedure rbactest.createDomainTestData( domainPerPackage integer ) +create or replace procedure rbactest.domain_create_test_data( domainPerPackage integer ) language plpgsql as $$ declare pac record; @@ -43,7 +43,7 @@ begin join rbactest.customer c on p.customeruuid = c.uuid where c.reference < 90000) -- reserved for functional testing loop - call rbactest.createdomainTestData(pac.name, 2); + call rbactest.domain_create_test_data(pac.name, 2); commit; end loop; @@ -57,17 +57,17 @@ end; $$; do language plpgsql $$ begin - call rbactest.createDomainTestData('xxx00', 2); - call rbactest.createDomainTestData('xxx01', 2); - call rbactest.createDomainTestData('xxx02', 2); + call rbactest.domain_create_test_data('xxx00', 2); + call rbactest.domain_create_test_data('xxx01', 2); + call rbactest.domain_create_test_data('xxx02', 2); - call rbactest.createDomainTestData('yyy00', 2); - call rbactest.createDomainTestData('yyy01', 2); - call rbactest.createDomainTestData('yyy02', 2); + call rbactest.domain_create_test_data('yyy00', 2); + call rbactest.domain_create_test_data('yyy01', 2); + call rbactest.domain_create_test_data('yyy02', 2); - call rbactest.createDomainTestData('zzz00', 2); - call rbactest.createDomainTestData('zzz01', 2); - call rbactest.createDomainTestData('zzz02', 2); + call rbactest.domain_create_test_data('zzz00', 2); + call rbactest.domain_create_test_data('zzz01', 2); + call rbactest.domain_create_test_data('zzz02', 2); end; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/501-contact/5018-hs-office-contact-test-data.sql b/src/main/resources/db/changelog/5-hs-office/501-contact/5018-hs-office-contact-test-data.sql index 5acd8e4f..db621862 100644 --- a/src/main/resources/db/changelog/5-hs-office/501-contact/5018-hs-office-contact-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/501-contact/5018-hs-office-contact-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single contact test record. */ -create or replace procedure hs_office.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 hs_office.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 hs_office.createHsOfficeContactTestData( begin for t in startCount..endCount loop - call hs_office.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 hs_office.createHsOfficeContactTestData('first contact'); - call hs_office.createHsOfficeContactTestData('second contact'); - call hs_office.createHsOfficeContactTestData('third contact'); - call hs_office.createHsOfficeContactTestData('fourth contact'); - call hs_office.createHsOfficeContactTestData('fifth contact'); - call hs_office.createHsOfficeContactTestData('sixth contact'); - call hs_office.createHsOfficeContactTestData('seventh contact'); - call hs_office.createHsOfficeContactTestData('eighth contact'); - call hs_office.createHsOfficeContactTestData('ninth contact'); - call hs_office.createHsOfficeContactTestData('tenth contact'); - call hs_office.createHsOfficeContactTestData('eleventh contact'); - call hs_office.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; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql b/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql index 26aaae99..2408602e 100644 --- a/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/502-person/5028-hs-office-person-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single person test record. */ -create or replace procedure createHsOfficePersonTestData( +create or replace procedure hs_office.person_create_test_data( newPersonType hs_office.PersonType, newTradeName varchar, newFamilyName 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; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql b/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql index d3d97683..8813ac7e 100644 --- a/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/503-relation/5038-hs-office-relation-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single relation test record. */ -create or replace procedure createHsOfficeRelationTestData( +create or replace procedure hs_office.relation_create_test_data( holderPersonName varchar, relationType hs_office.RelationType, anchorPersonName varchar, @@ -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; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5048-hs-office-partner-test-data.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5048-hs-office-partner-test-data.sql index f8239efc..b0e9e345 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5048-hs-office-partner-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5048-hs-office-partner-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single partner test record. */ -create or replace procedure hs_office.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 hs_office.createHsOfficePartnerTestData('Hostsharing eG', 10001, 'First GmbH', 'first contact'); - call hs_office.createHsOfficePartnerTestData('Hostsharing eG', 10002, 'Second e.K.', 'second contact'); - call hs_office.createHsOfficePartnerTestData('Hostsharing eG', 10003, 'Third OHG', 'third contact'); - call hs_office.createHsOfficePartnerTestData('Hostsharing eG', 10004, 'Fourth eG', 'fourth contact'); - call hs_office.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; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5058-hs-office-bankaccount-test-data.sql b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5058-hs-office-bankaccount-test-data.sql index f8233c48..15f1035d 100644 --- a/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5058-hs-office-bankaccount-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/505-bankaccount/5058-hs-office-bankaccount-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single bankaccount test record. */ -create or replace procedure hs_office.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 hs_office.createHsOfficeBankAccountTestData('First GmbH', 'DE02120300000000202051', 'BYLADEM1001'); - call hs_office.createHsOfficeBankAccountTestData('Peter Smith', 'DE02500105170137075030', 'INGDDEFF'); - call hs_office.createHsOfficeBankAccountTestData('Second e.K.', 'DE02100500000054540402', 'BELADEBE'); - call hs_office.createHsOfficeBankAccountTestData('Third OHG', 'DE02300209000106531065', 'CMCIDEDD'); - call hs_office.createHsOfficeBankAccountTestData('Fourth eG', 'DE02200505501015871393', 'HASPDEHH'); - call hs_office.createHsOfficeBankAccountTestData('Mel Bessler', 'DE02100100100006820101', 'PBNKDEFF'); - call hs_office.createHsOfficeBankAccountTestData('Anita Bessler', 'DE02300606010002474689', 'DAAEDEDD'); - call hs_office.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; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/506-debitor/5068-hs-office-debitor-test-data.sql b/src/main/resources/db/changelog/5-hs-office/506-debitor/5068-hs-office-debitor-test-data.sql index db4bc66e..1b30b8f1 100644 --- a/src/main/resources/db/changelog/5-hs-office/506-debitor/5068-hs-office-debitor-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/506-debitor/5068-hs-office-debitor-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single debitor test record. */ -create or replace procedure hs_office.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 hs_office.createHsOfficeDebitorTestData(11, 'First GmbH', 'first contact', 'fir'); - call hs_office.createHsOfficeDebitorTestData(12, 'Second e.K.', 'second contact', 'sec'); - call hs_office.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; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5078-hs-office-sepamandate-test-data.sql b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5078-hs-office-sepamandate-test-data.sql index 2de78d7a..4bed9841 100644 --- a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5078-hs-office-sepamandate-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5078-hs-office-sepamandate-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single sepaMandate test record. */ -create or replace procedure hs_office.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 hs_office.createHsOfficeSepaMandateTestData(10001, '11', 'DE02120300000000202051', 'ref-10001-11'); - call hs_office.createHsOfficeSepaMandateTestData(10002, '12', 'DE02100500000054540402', 'ref-10002-12'); - call hs_office.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; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/510-membership/5108-hs-office-membership-test-data.sql b/src/main/resources/db/changelog/5-hs-office/510-membership/5108-hs-office-membership-test-data.sql index 34cb07d5..f67424a9 100644 --- a/src/main/resources/db/changelog/5-hs-office/510-membership/5108-hs-office-membership-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/510-membership/5108-hs-office-membership-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single membership test record. */ -create or replace procedure hs_office.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 hs_office.createHsOfficeMembershipTestData(10001, '01'); - call hs_office.createHsOfficeMembershipTestData(10002, '02'); - call hs_office.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; $$; --// diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql index bfddf0c7..9769be94 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single coopSharesTransaction test record. */ -create or replace procedure hs_office.createHsOfficeCoopSharesTransactionTestData( +create or replace procedure hs_office.coopsharetx_create_test_data( givenPartnerNumber numeric, givenMemberNumberSuffix char(2) ) @@ -46,8 +46,8 @@ do language plpgsql $$ call base.defineContext('creating coopSharesTransaction test-data'); SET CONSTRAINTS ALL DEFERRED; - call hs_office.createHsOfficeCoopSharesTransactionTestData(10001, '01'); - call hs_office.createHsOfficeCoopSharesTransactionTestData(10002, '02'); - call hs_office.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; $$; diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql index da9265d8..3f2a35a6 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single coopAssetsTransaction test record. */ -create or replace procedure hs_office.createHsOfficeCoopAssetsTransactionTestData( +create or replace procedure hs_office.coopassettx_create_test_data( givenPartnerNumber numeric, givenMemberNumberSuffix char(2) ) @@ -46,8 +46,8 @@ do language plpgsql $$ call base.defineContext('creating coopAssetsTransaction test-data'); SET CONSTRAINTS ALL DEFERRED; - call hs_office.createHsOfficeCoopAssetsTransactionTestData(10001, '01'); - call hs_office.createHsOfficeCoopAssetsTransactionTestData(10002, '02'); - call hs_office.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; $$; diff --git a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6208-hs-booking-project-test-data.sql b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6208-hs-booking-project-test-data.sql index 3a8a2981..a5dd9596 100644 --- a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6208-hs-booking-project-test-data.sql +++ b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6208-hs-booking-project-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single hs_booking.project test record. */ -create or replace procedure createHsBookingProjectTransactionTestData( +create or replace procedure hs_booking.project_create_test_data( givenPartnerNumber numeric, givenDebitorSuffix char(2) ) @@ -41,9 +41,9 @@ do language plpgsql $$ begin call base.defineContext('creating booking-project test-data', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN'); - call createHsBookingProjectTransactionTestData(10001, '11'); - call createHsBookingProjectTransactionTestData(10002, '12'); - call createHsBookingProjectTransactionTestData(10003, '13'); + call hs_booking.project_create_test_data(10001, '11'); + call hs_booking.project_create_test_data(10002, '12'); + call hs_booking.project_create_test_data(10003, '13'); end; $$; --// diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql index 03c89b6a..a0b7470a 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6308-hs-booking-item-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single hs_booking.item test record. */ -create or replace procedure hs_booking.createHsBookingItemTransactionTestData( +create or replace procedure hs_booking.item_create_test_data( givenPartnerNumber numeric, givenDebitorSuffix char(2) ) @@ -49,9 +49,9 @@ do language plpgsql $$ begin call base.defineContext('creating booking-item test-data', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN'); - call hs_booking.createHsBookingItemTransactionTestData(10001, '11'); - call hs_booking.createHsBookingItemTransactionTestData(10002, '12'); - call hs_booking.createHsBookingItemTransactionTestData(10003, '13'); + call hs_booking.item_create_test_data(10001, '11'); + call hs_booking.item_create_test_data(10002, '12'); + call hs_booking.item_create_test_data(10003, '13'); end; $$; --// diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql index e9574b14..99b9f6f7 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql @@ -8,7 +8,7 @@ /* Creates a single hs_hosting.asset test record. */ -create or replace procedure hs_office.createHsHostingAssetTestData(givenProjectCaption varchar) +create or replace procedure hs_hosting.asset_create_test_data(givenProjectCaption varchar) language plpgsql as $$ declare relatedProject hs_booking.project; @@ -21,8 +21,8 @@ declare defaultPrefix varchar; managedServerUuid uuid; managedWebspaceUuid uuid; - webUnixSubjectUuid uuid; - mboxUnixSubjectUuid uuid; + webUnixSubjectUuid uuid; + mboxUnixSubjectUuid uuid; domainSetupUuid uuid; domainMBoxSetupUuid uuid; mariaDbInstanceUuid uuid; @@ -112,9 +112,9 @@ do language plpgsql $$ begin call base.defineContext('creating hosting-asset test-data', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN'); - call hs_office.createHsHostingAssetTestData('D-1000111 default project'); - call hs_office.createHsHostingAssetTestData('D-1000212 default project'); - call hs_office.createHsHostingAssetTestData('D-1000313 default project'); + call hs_hosting.asset_create_test_data('D-1000111 default project'); + call hs_hosting.asset_create_test_data('D-1000212 default project'); + call hs_hosting.asset_create_test_data('D-1000313 default project'); end; $$; --// -- 2.39.5 From 12d74a75cae675221e5d303b86c52d0781ff6a7b Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 20 Sep 2024 12:21:58 +0200 Subject: [PATCH 11/14] create or replace function base.findObjectUuidByIdName(objectTable varchar, objectIdName varchar) create or replace function base.findObjectUuidByIdName(objectTable varchar, objectIdName varchar) create or replace function base.findObjectUuidByIdName(objectTable varchar, objectIdName varchar) move findObjectUuidByIdName+findIdNameByObjectUuid from base to rbac and related naming issues --- .../db/changelog/0-base/010-context.sql | 39 ---------------- .../db/changelog/1-rbac/1050-rbac-base.sql | 46 ++++++++++++++++++- .../db/changelog/1-rbac/1054-rbac-context.sql | 2 +- .../db/changelog/1-rbac/1055-rbac-views.sql | 22 ++++----- .../changelog/1-rbac/1058-rbac-generators.sql | 4 +- .../db/changelog/1-rbac/1080-rbac-global.sql | 8 ++-- 6 files changed, 63 insertions(+), 58 deletions(-) diff --git a/src/main/resources/db/changelog/0-base/010-context.sql b/src/main/resources/db/changelog/0-base/010-context.sql index 6340850b..abafe3b6 100644 --- a/src/main/resources/db/changelog/0-base/010-context.sql +++ b/src/main/resources/db/changelog/0-base/010-context.sql @@ -168,45 +168,6 @@ begin return cleanIdentifier; end; $$; -create or replace function base.findObjectUuidByIdName(objectTable varchar, objectIdName varchar) - returns uuid - returns null on null input - language plpgsql as $$ -declare - sql varchar; - uuid uuid; -begin - objectTable := base.pureIdentifier(objectTable); - objectIdName := base.pureIdentifier(objectIdName); - sql := format('select * from %sUuidByIdName(%L);', objectTable, objectIdName); - begin - execute sql into uuid; - exception - when others then - raise exception 'function %UuidByIdName(...) not found, add identity view support for table %', objectTable, objectTable; - end; - return uuid; -end ; $$; - -create or replace function base.findIdNameByObjectUuid(objectTable varchar, objectUuid uuid) - returns varchar - returns null on null input - language plpgsql as $$ -declare - sql varchar; - idName varchar; -begin - objectTable := base.pureIdentifier(objectTable); - sql := format('select * from %sIdNameByUuid(%L::uuid);', objectTable, objectUuid); - begin - execute sql into idName; - exception - when others then - raise exception 'function %IdNameByUuid(...) not found, add identity view support for table %', objectTable, objectTable; - end; - return idName; -end ; $$; - create or replace function base.currentSubjects() returns varchar(1023)[] stable -- leakproof diff --git a/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql b/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql index 6a403e08..82c43238 100644 --- a/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql +++ b/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql @@ -233,6 +233,50 @@ $$; --// +-- ============================================================================ +--changeset michael.hoennig:rbac-base-IDNAME-FUNCTIONS endDelimiter:--// +-- ---------------------------------------------------------------------------- +create or replace function rbac.findObjectUuidByIdName(objectTable varchar, objectIdName varchar) + returns uuid + returns null on null input + language plpgsql as $$ +declare + sql varchar; + uuid uuid; +begin + objectTable := base.pureIdentifier(objectTable); + objectIdName := base.pureIdentifier(objectIdName); + sql := format('select * from %s_uuid_by_id_name(%L);', objectTable, objectIdName); + begin + execute sql into uuid; + exception + when others then + raise exception 'function %_uuid_by_id_name(...) not found, add identity view support for table %', objectTable, objectTable; + end; + return uuid; +end ; $$; + +create or replace function rbac.findIdNameByObjectUuid(objectTable varchar, objectUuid uuid) + returns varchar + returns null on null input + language plpgsql as $$ +declare + sql varchar; + idName varchar; +begin + objectTable := base.pureIdentifier(objectTable); + sql := format('select * from %s_id_name_by_uuid(%L::uuid);', objectTable, objectUuid); + begin + execute sql into idName; + exception + when others then + raise exception 'function %_id_name_by_uuid(...) not found, add identity view support for table %', objectTable, objectTable; + end; + return idName; +end ; $$; +--// + + -- ============================================================================ --changeset michael.hoennig:rbac-base-ROLE-FUNCTIONS endDelimiter:--// -- ---------------------------------------------------------------------------- @@ -262,7 +306,7 @@ begin objectTableFromRoleIdName = split_part(roleParts, '#', 1); objectNameFromRoleIdName = split_part(roleParts, '#', 2); roleTypeFromRoleIdName = split_part(roleParts, '#', 3); - objectUuidOfRole = base.findObjectUuidByIdName(objectTableFromRoleIdName, objectNameFromRoleIdName); + objectUuidOfRole = rbac.findObjectUuidByIdName(objectTableFromRoleIdName, objectNameFromRoleIdName); select uuid from rbac.role diff --git a/src/main/resources/db/changelog/1-rbac/1054-rbac-context.sql b/src/main/resources/db/changelog/1-rbac/1054-rbac-context.sql index afede6ac..892b5933 100644 --- a/src/main/resources/db/changelog/1-rbac/1054-rbac-context.sql +++ b/src/main/resources/db/changelog/1-rbac/1054-rbac-context.sql @@ -55,7 +55,7 @@ begin objectNameToAssume = split_part(roleNameParts, '#', 2); roleTypeToAssume = split_part(roleNameParts, '#', 3); - objectUuidToAssume = base.findObjectUuidByIdName(objectTableToAssume, objectNameToAssume); + objectUuidToAssume = rbac.findObjectUuidByIdName(objectTableToAssume, objectNameToAssume); if objectUuidToAssume is null then raise exception '[401] object % cannot be found in table % (from roleNameParts=%)', objectNameToAssume, objectTableToAssume, roleNameParts; end if; diff --git a/src/main/resources/db/changelog/1-rbac/1055-rbac-views.sql b/src/main/resources/db/changelog/1-rbac/1055-rbac-views.sql index e1ea0c1e..c68099dc 100644 --- a/src/main/resources/db/changelog/1-rbac/1055-rbac-views.sql +++ b/src/main/resources/db/changelog/1-rbac/1055-rbac-views.sql @@ -13,7 +13,7 @@ select (objectTable || '#' || objectIdName || ':' || roleType) as roleIdName, * -- @formatter:off from ( select r.*, - o.objectTable, base.findIdNameByObjectUuid(o.objectTable, o.uuid) as objectIdName + o.objectTable, rbac.findIdNameByObjectUuid(o.objectTable, o.uuid) as objectIdName from rbac.role as r join rbac.object as o on o.uuid = r.objectuuid ) as unordered @@ -34,7 +34,7 @@ select * -- @formatter:off from ( select r.*, o.objectTable, - base.findIdNameByObjectUuid(o.objectTable, o.uuid) as objectIdName + rbac.findIdNameByObjectUuid(o.objectTable, o.uuid) as objectIdName from rbac.role as r join rbac.object as o on o.uuid = r.objectuuid where rbac.isGranted(rbac.currentSubjectOrAssumedRolesUuids(), r.uuid) @@ -57,7 +57,7 @@ create or replace view rbac.grants_ev as -- @formatter:off select x.grantUuid as uuid, x.grantedByTriggerOf as grantedByTriggerOf, - go.objectTable || '#' || base.findIdNameByObjectUuid(go.objectTable, go.uuid) || ':' || r.roletype as grantedByRoleIdName, + go.objectTable || '#' || rbac.findIdNameByObjectUuid(go.objectTable, go.uuid) || ':' || r.roletype as grantedByRoleIdName, x.ascendingIdName as ascendantIdName, x.descendingIdName as descendantIdName, x.grantedByRoleUuid, @@ -72,15 +72,15 @@ create or replace view rbac.grants_ev as coalesce( 'user:' || au.name, - 'role:' || aro.objectTable || '#' || base.findIdNameByObjectUuid(aro.objectTable, aro.uuid) || ':' || ar.roletype + 'role:' || aro.objectTable || '#' || rbac.findIdNameByObjectUuid(aro.objectTable, aro.uuid) || ':' || ar.roletype ) as ascendingIdName, aro.objectTable, aro.uuid, ( case when dro is not null - then ('role:' || dro.objectTable || '#' || base.findIdNameByObjectUuid(dro.objectTable, dro.uuid) || ':' || dr.roletype) + then ('role:' || dro.objectTable || '#' || rbac.findIdNameByObjectUuid(dro.objectTable, dro.uuid) || ':' || dr.roletype) when dp.op = 'INSERT' - then 'perm:' || dpo.objecttable || '#' || base.findIdNameByObjectUuid(dpo.objectTable, dpo.uuid) || ':' || dp.op || '>' || dp.opTableName - else 'perm:' || dpo.objecttable || '#' || base.findIdNameByObjectUuid(dpo.objectTable, dpo.uuid) || ':' || dp.op + then 'perm:' || dpo.objecttable || '#' || rbac.findIdNameByObjectUuid(dpo.objectTable, dpo.uuid) || ':' || dp.op || '>' || dp.opTableName + else 'perm:' || dpo.objecttable || '#' || rbac.findIdNameByObjectUuid(dpo.objectTable, dpo.uuid) || ':' || dp.op end ) as descendingIdName, dro.objectTable, dro.uuid, @@ -114,14 +114,14 @@ create or replace view rbac.grants_ev as */ create or replace view rbac.grants_rv as -- @formatter:off -select o.objectTable || '#' || base.findIdNameByObjectUuid(o.objectTable, o.uuid) || ':' || r.roletype as grantedByRoleIdName, +select o.objectTable || '#' || rbac.findIdNameByObjectUuid(o.objectTable, o.uuid) || ':' || r.roletype as grantedByRoleIdName, g.objectTable || '#' || g.objectIdName || ':' || g.roletype as grantedRoleIdName, g.userName, g.assumed, g.grantedByRoleUuid, g.descendantUuid as grantedRoleUuid, g.ascendantUuid as subjectUuid, g.objectTable, g.objectUuid, g.objectIdName, g.roleType as grantedRoleType from ( select g.grantedbyroleuuid, g.ascendantuuid, g.descendantuuid, g.assumed, u.name as userName, o.objecttable, r.objectuuid, r.roletype, - base.findIdNameByObjectUuid(o.objectTable, o.uuid) as objectIdName + rbac.findIdNameByObjectUuid(o.objectTable, o.uuid) as objectIdName from rbac.grants as g join rbac.role as r on r.uuid = g.descendantUuid join rbac.object o on o.uuid = r.objectuuid @@ -363,10 +363,10 @@ begin xp.permissionObjectTable, xp.permissionObjectIdName, xp.permissionObjectUuid from (select r.uuid as roleUuid, r.roletype, ro.objectTable as roleObjectTable, - base.findIdNameByObjectUuid(ro.objectTable, ro.uuid) as roleObjectIdName, + rbac.findIdNameByObjectUuid(ro.objectTable, ro.uuid) as roleObjectIdName, p.uuid as permissionUuid, p.op, p.opTableName, po.objecttable as permissionObjectTable, - base.findIdNameByObjectUuid(po.objectTable, po.uuid) as permissionObjectIdName, + rbac.findIdNameByObjectUuid(po.objectTable, po.uuid) as permissionObjectIdName, po.uuid as permissionObjectUuid from rbac.queryPermissionsGrantedToSubjectId( targetSubjectUuid) as p join rbac.grants as g on g.descendantUuid = p.uuid diff --git a/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql b/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql index 852a023e..b8af04f4 100644 --- a/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql +++ b/src/main/resources/db/changelog/1-rbac/1058-rbac-generators.sql @@ -130,7 +130,7 @@ begin -- creates a function which maps an idName to the objectUuid sql = format($sql$ - create or replace function %1$sUuidByIdName(givenIdName varchar) + create or replace function %1$s_uuid_by_id_name(givenIdName varchar) returns uuid language plpgsql as $f$ declare @@ -144,7 +144,7 @@ begin -- creates a function which maps an objectUuid to the related idName sql = format($sql$ - create or replace function %1$sIdNameByUuid(givenUuid uuid) + create or replace function %1$s_id_name_by_uuid(givenUuid uuid) returns varchar language sql strict as $f$ diff --git a/src/main/resources/db/changelog/1-rbac/1080-rbac-global.sql b/src/main/resources/db/changelog/1-rbac/1080-rbac-global.sql index a5514401..51cdb6c2 100644 --- a/src/main/resources/db/changelog/1-rbac/1080-rbac-global.sql +++ b/src/main/resources/db/changelog/1-rbac/1080-rbac-global.sql @@ -66,21 +66,21 @@ grant all privileges on rbac.global_iv to ${HSADMINNG_POSTGRES_RESTRICTED_USERNA /* Returns the objectUuid for a given identifying name (in this case the idName). */ -create or replace function rbac.globalUuidByIdName(idName varchar) +create or replace function rbac.global_uuid_by_id_name(idName varchar) returns uuid language sql strict as $$ -select uuid from rbac.global_iv iv where iv.idName = globalUuidByIdName.idName; +select uuid from rbac.global_iv iv where iv.idName = global_uuid_by_id_name.idName; $$; /* Returns the identifying name for a given objectUuid (in this case the idName). */ -create or replace function rbac.globalIdNameByUuid(uuid uuid) +create or replace function rbac.global_id_name_by_uuid(uuid uuid) returns varchar language sql strict as $$ -select idName from rbac.global_iv iv where iv.uuid = globalIdNameByUuid.uuid; +select idName from rbac.global_iv iv where iv.uuid = global_id_name_by_uuid.uuid; $$; --// -- 2.39.5 From 754df475a718bc26a8fddcf7b73ab655b8c92b70 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 20 Sep 2024 12:42:52 +0200 Subject: [PATCH 12/14] rename coopassetstransactions->coopassettx --- .../HsOfficeCoopAssetsTransactionEntity.java | 2 +- .../hsadminng/rbac/generator/RbacView.java | 4 +- .../5120-hs-office-coopassets.sql | 12 ++-- .../5123-hs-office-coopassets-rbac.sql | 62 +++++++++---------- .../5126-hs-office-coopassets-migration.sql | 26 ++++---- .../5128-hs-office-coopassets-test-data.sql | 2 +- .../hs/migration/BaseOfficeDataImport.java | 2 +- .../hsadminng/hs/migration/CsvDataImport.java | 6 +- ...tsTransactionControllerAcceptanceTest.java | 4 +- ...sTransactionRepositoryIntegrationTest.java | 30 ++++----- ...ceMembershipRepositoryIntegrationTest.java | 2 +- ...acGrantsDiagramServiceIntegrationTest.java | 2 +- 12 files changed, 76 insertions(+), 78 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java index 34ad2dae..0993b9e5 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionEntity.java @@ -34,7 +34,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @Entity -@Table(schema = "hs_office", name = "coopassetstransaction_rv") +@Table(schema = "hs_office", name = "coopassettx_rv") @Getter @Setter @Builder diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java index c2bc687d..ec95cc2b 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java @@ -992,9 +992,7 @@ public class RbacView { return getRawTableName() .replace("hs_office.", "hsof.") .replace("hs_booking.", "hsbk_") - .replace("hs_hosting.", "hsho_") - .replace("coopsharestransaction", "coopsharetx") - .replace("coopassetstransaction", "coopassettx"); + .replace("hs_hosting.", "hsho_"); } String dependsOnColumName() { diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql index 0cefb464..4e5568ad 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql @@ -15,7 +15,7 @@ CREATE TYPE hs_office.CoopAssetsTransactionType AS ENUM ('ADJUSTMENT', 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, @@ -24,7 +24,7 @@ create table if not exists hs_office.coopassetstransaction 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); @@ -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,7 +62,7 @@ begin return true; end; $$; -alter table hs_office.coopassetstransaction +alter table hs_office.coopassettx add constraint check_positive_total 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'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql index 20530fb9..b6459abd 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql @@ -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('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 $$ @@ -45,52 +45,52 @@ begin 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'), + 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() returns trigger @@ -99,53 +99,53 @@ create or replace function hs_office.new_coopassettx_grants_insert_to_membership begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( - rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.coopassetstransaction'), + 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 +create trigger z_new_coopassettx_grants_after_insert_tg after insert on hs_office.membership for each row execute procedure hs_office.new_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$, diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5126-hs-office-coopassets-migration.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5126-hs-office-coopassets-migration.sql index 841ca6e6..1bb0d500 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5126-hs-office-coopassets-migration.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5126-hs-office-coopassets-migration.sql @@ -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,8 +41,8 @@ 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; --/ @@ -58,14 +58,14 @@ 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 insert_legacy_id_mapping_tg - after insert on hs_office.coopassetstransaction + after insert on hs_office.coopassettx for each row execute procedure hs_office.coopassettx_insert_legacy_id_mapping_tf(); --/ @@ -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 delete_legacy_id_mapping_tg - before delete on hs_office.coopassetstransaction + before delete on hs_office.coopassettx for each row execute procedure hs_office.coopassettx_delete_legacy_id_mapping_tf(); --/ diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql index 3f2a35a6..ed824b12 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5128-hs-office-coopassets-test-data.sql @@ -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), diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java index 3bdd17b3..511647aa 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java @@ -677,7 +677,7 @@ public abstract class BaseOfficeDataImport extends CsvDataImport { jpaAttempt.transacted(() -> { context(rbacSuperuser); coopAssets.forEach(this::persist); - updateLegacyIds(coopAssets, "hs_office.coopassetstransaction_legacy_id", "member_asset_id"); + updateLegacyIds(coopAssets, "hs_office.coopassettx_legacy_id", "member_asset_id"); }).assertSuccessful(); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java index 3dd9a11f..8a4500a1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java @@ -254,8 +254,8 @@ public class CsvDataImport extends ContextBasedTest { em.createNativeQuery("delete from hs_booking.item_ex where true").executeUpdate(); em.createNativeQuery("delete from hs_booking.project where true").executeUpdate(); em.createNativeQuery("delete from hs_booking.project_ex where true").executeUpdate(); - em.createNativeQuery("delete from hs_office.coopassetstransaction where true").executeUpdate(); - em.createNativeQuery("delete from hs_office.coopassetstransaction_legacy_id where true").executeUpdate(); + em.createNativeQuery("delete from hs_office.coopassettx where true").executeUpdate(); + em.createNativeQuery("delete from hs_office.coopassettx_legacy_id where true").executeUpdate(); em.createNativeQuery("delete from hs_office.coopsharestransaction where true").executeUpdate(); em.createNativeQuery("delete from hs_office.coopsharestransaction_legacy_id where true").executeUpdate(); em.createNativeQuery("delete from hs_office.membership where true").executeUpdate(); @@ -275,7 +275,7 @@ public class CsvDataImport extends ContextBasedTest { jpaAttempt.transacted(() -> { context(rbacSuperuser); em.createNativeQuery("alter sequence hs_office.contact_legacy_id_seq restart with 1000000000;").executeUpdate(); - em.createNativeQuery("alter sequence hs_office.coopassetstransaction_legacy_id_seq restart with 1000000000;") + em.createNativeQuery("alter sequence hs_office.coopassettx_legacy_id_seq restart with 1000000000;") .executeUpdate(); em.createNativeQuery("alter sequence public.hs_office.coopsharestransaction_legacy_id_seq restart with 1000000000;") .executeUpdate(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerAcceptanceTest.java index 1ca91c75..e8766490 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionControllerAcceptanceTest.java @@ -391,9 +391,9 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased void cleanup() { jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net", null); - // HsOfficeCoopAssetsTransactionEntity respectively hs_office.coopassetstransaction_rv + // HsOfficeCoopAssetsTransactionEntity respectively hs_office.coopassettx_rv // cannot be deleted at all, but the underlying table record can be deleted. - em.createNativeQuery("delete from hs_office.coopassetstransaction where reference like 'temp %'") + em.createNativeQuery("delete from hs_office.coopassettx where reference like 'temp %'") .executeUpdate(); }).assertSuccessful(); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionRepositoryIntegrationTest.java index b13ff2f5..8f650fa9 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopassets/HsOfficeCoopAssetsTransactionRepositoryIntegrationTest.java @@ -112,8 +112,8 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase .map(s -> s.replace("hs_office.", "")) .containsExactlyInAnyOrder(Array.fromFormatted( initialGrantNames, - "{ grant perm:coopassetstransaction#temprefB:SELECT to role:membership#M-1000101:AGENT by system and assume }", - "{ grant perm:coopassetstransaction#temprefB:UPDATE to role:membership#M-1000101:ADMIN by system and assume }", + "{ grant perm:coopassettx#temprefB:SELECT to role:membership#M-1000101:AGENT by system and assume }", + "{ grant perm:coopassettx#temprefB:UPDATE to role:membership#M-1000101:ADMIN by system and assume }", null)); } @@ -222,7 +222,7 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase final var query = em.createNativeQuery(""" select currentTask, targetTable, targetOp, targetdelta->>'reference' from base.tx_journal_v - where targettable = 'hs_office.coopassetstransaction'; + where targettable = 'hs_office.coopassettx'; """); // when @@ -230,18 +230,18 @@ class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBase // then assertThat(customerLogEntries).map(Arrays::toString).contains( - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000101-1]", - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000101-2]", - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000101-3]", - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000101-3]", - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000202-1]", - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000202-2]", - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000202-3]", - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000202-3]", - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000303-1]", - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000303-2]", - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000303-3]", - "[creating coopAssetsTransaction test-data, hs_office.coopassetstransaction, INSERT, ref 1000303-3]"); + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000101-1]", + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000101-2]", + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000101-3]", + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000101-3]", + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000202-1]", + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000202-2]", + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000202-3]", + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000202-3]", + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000303-1]", + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000303-2]", + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000303-3]", + "[creating coopAssetsTransaction test-data, hs_office.coopassettx, INSERT, ref 1000303-3]"); } @BeforeEach diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipRepositoryIntegrationTest.java index 8192c705..ddceb536 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipRepositoryIntegrationTest.java @@ -118,7 +118,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl .containsExactlyInAnyOrder(Array.fromFormatted( initialGrantNames, // insert - "{ grant perm:membership#M-1000117:INSERT>coopassetstransaction to role:membership#M-1000117:ADMIN by system and assume }", + "{ grant perm:membership#M-1000117:INSERT>coopassettx to role:membership#M-1000117:ADMIN by system and assume }", "{ grant perm:membership#M-1000117:INSERT>coopsharestransaction to role:membership#M-1000117:ADMIN by system and assume }", // owner diff --git a/src/test/java/net/hostsharing/hsadminng/rbac/grant/RbacGrantsDiagramServiceIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/rbac/grant/RbacGrantsDiagramServiceIntegrationTest.java index f3ebb87f..b234e07b 100644 --- a/src/test/java/net/hostsharing/hsadminng/rbac/grant/RbacGrantsDiagramServiceIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/rbac/grant/RbacGrantsDiagramServiceIntegrationTest.java @@ -95,7 +95,7 @@ class RbacGrantsDiagramServiceIntegrationTest extends ContextBasedTestWithCleanu //final var graph = grantsMermaidService.allGrantsTocurrentSubject(EnumSet.of(Include.NON_TEST_ENTITIES, Include.PERMISSIONS)); - final var targetObject = (UUID) em.createNativeQuery("SELECT uuid FROM hs_office.coopassetstransaction WHERE reference='ref 1000101-1'").getSingleResult(); + final var targetObject = (UUID) em.createNativeQuery("SELECT uuid FROM hs_office.coopassettx WHERE reference='ref 1000101-1'").getSingleResult(); final var graph = grantsMermaidService.allGrantsFrom(targetObject, "view", EnumSet.of(Include.USERS)); RbacGrantsDiagramService.writeToFile(join(";", context.fetchAssumedRoles()), graph, "doc/all-grants.md"); -- 2.39.5 From 19cc787a4a4701f9ebda52f456ceb0d3e46878a8 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 20 Sep 2024 13:01:44 +0200 Subject: [PATCH 13/14] rename coopsharestransactions->coopsharetx --- .../HsOfficeCoopSharesTransactionEntity.java | 2 +- .../hsadminng/rbac/generator/RbacView.java | 2 +- .../5110-hs-office-coopshares.sql | 12 ++-- .../5113-hs-office-coopshares-rbac.sql | 62 +++++++++---------- .../5116-hs-office-coopshares-migration.sql | 8 +-- .../5118-hs-office-coopshares-test-data.sql | 2 +- .../hsadminng/hs/migration/CsvDataImport.java | 2 +- ...esTransactionControllerAcceptanceTest.java | 4 +- ...sTransactionRepositoryIntegrationTest.java | 30 ++++----- ...ceMembershipRepositoryIntegrationTest.java | 2 +- src/test/resources/application.yml | 2 +- 11 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java index d8486008..2bbf287d 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java @@ -32,7 +32,7 @@ import static net.hostsharing.hsadminng.rbac.generator.RbacView.rbacViewFor; import static net.hostsharing.hsadminng.stringify.Stringify.stringify; @Entity -@Table(schema = "hs_office", name = "coopsharestransaction_rv") +@Table(schema = "hs_office", name = "coopsharetx_rv") @Getter @Setter @Builder diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java index ec95cc2b..07838dad 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/generator/RbacView.java @@ -987,7 +987,7 @@ public class RbacView { String getRawTableShortName() { // TODO.impl: some combined function and trigger names are too long - // maybe we should shorten the table name e.g. hs_office.coopsharestransaction -> hsof.coopsharetx + // maybe we should shorten the table name e.g. hs_office.coopsharetx -> hsof.coopsharetx // this is just a workaround: return getRawTableName() .replace("hs_office.", "hsof.") diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql index ade1156a..213dd1cb 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql @@ -8,7 +8,7 @@ CREATE TYPE hs_office.CoopSharesTransactionType AS ENUM ('ADJUSTMENT', 'SUBSCRIP 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, @@ -17,7 +17,7 @@ create table if not exists hs_office.coopsharestransaction 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); @@ -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,7 +54,7 @@ begin return true; end; $$; -alter table hs_office.coopsharestransaction +alter table hs_office.coopsharetx add constraint check_positive_total_shares_count 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'); --// diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql index dabbe8f6..33ea130c 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql @@ -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('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 $$ @@ -45,52 +45,52 @@ begin 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'), + 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() returns trigger @@ -99,53 +99,53 @@ create or replace function hs_office.new_coopsharetx_grants_insert_to_membership begin -- unconditional for all rows in that table call rbac.grantPermissionToRole( - rbac.createPermission(NEW.uuid, 'INSERT', 'hs_office.coopsharestransaction'), + 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 +create trigger z_new_coopsharetx_grants_after_insert_tg after insert on hs_office.membership for each row execute procedure hs_office.new_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$, diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5116-hs-office-coopshares-migration.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5116-hs-office-coopshares-migration.sql index 1aaf2f0a..1e4efb42 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5116-hs-office-coopshares-migration.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5116-hs-office-coopshares-migration.sql @@ -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,7 +42,7 @@ 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; --/ @@ -65,7 +65,7 @@ begin end; $$; create trigger insert_legacy_id_mapping_tg - after insert on hs_office.coopsharestransaction + after insert on hs_office.coopsharetx for each row execute procedure hs_office.coopsharetx_insert_legacy_id_mapping_tf(); --/ @@ -90,7 +90,7 @@ begin end; $$; create trigger delete_legacy_id_mapping_tg - before delete on hs_office.coopsharestransaction + before delete on hs_office.coopsharetx for each row execute procedure hs_office.coopsharetx_delete_legacy_id_mapping_tf(); --/ diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql index 9769be94..0f148a90 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql @@ -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), diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java index 8a4500a1..7f1ac1f2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/CsvDataImport.java @@ -256,7 +256,7 @@ public class CsvDataImport extends ContextBasedTest { em.createNativeQuery("delete from hs_booking.project_ex where true").executeUpdate(); em.createNativeQuery("delete from hs_office.coopassettx where true").executeUpdate(); em.createNativeQuery("delete from hs_office.coopassettx_legacy_id where true").executeUpdate(); - em.createNativeQuery("delete from hs_office.coopsharestransaction where true").executeUpdate(); + em.createNativeQuery("delete from hs_office.coopsharetx where true").executeUpdate(); em.createNativeQuery("delete from hs_office.coopsharestransaction_legacy_id where true").executeUpdate(); em.createNativeQuery("delete from hs_office.membership where true").executeUpdate(); em.createNativeQuery("delete from hs_office.sepamandate where true").executeUpdate(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionControllerAcceptanceTest.java index a379c415..28a7723e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionControllerAcceptanceTest.java @@ -55,9 +55,9 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased void cleanup() { jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net", null); - // HsOfficeCoopSharesTransactionEntity respectively hs_office.coopsharestransaction_rv + // HsOfficeCoopSharesTransactionEntity respectively hs_office.coopsharetx_rv // cannot be deleted at all, but the underlying table record can be deleted. - em.createNativeQuery("delete from hs_office.coopsharestransaction where reference like 'temp %'").executeUpdate(); + em.createNativeQuery("delete from hs_office.coopsharetx where reference like 'temp %'").executeUpdate(); }).assertSuccessful(); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionRepositoryIntegrationTest.java index 6ef36d57..ac74bee6 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionRepositoryIntegrationTest.java @@ -111,8 +111,8 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase .map(s -> s.replace("hs_office.", "")) .containsExactlyInAnyOrder(Array.fromFormatted( initialGrantNames, - "{ grant perm:coopsharestransaction#temprefB:SELECT to role:membership#M-1000101:AGENT by system and assume }", - "{ grant perm:coopsharestransaction#temprefB:UPDATE to role:membership#M-1000101:ADMIN by system and assume }", + "{ grant perm:coopsharetx#temprefB:SELECT to role:membership#M-1000101:AGENT by system and assume }", + "{ grant perm:coopsharetx#temprefB:UPDATE to role:membership#M-1000101:ADMIN by system and assume }", null)); } @@ -221,7 +221,7 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase final var query = em.createNativeQuery(""" select currentTask, targetTable, targetOp, targetdelta->>'reference' from base.tx_journal_v - where targettable = 'hs_office.coopsharestransaction'; + where targettable = 'hs_office.coopsharetx'; """); // when @@ -229,18 +229,18 @@ class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBase // then assertThat(customerLogEntries).map(Arrays::toString).contains( - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000101-1]", - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000101-2]", - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000101-3]", - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000101-4]", - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000202-1]", - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000202-2]", - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000202-3]", - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000202-4]", - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000303-1]", - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000303-2]", - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000303-3]", - "[creating coopSharesTransaction test-data, hs_office.coopsharestransaction, INSERT, ref 1000303-4]"); + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000101-1]", + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000101-2]", + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000101-3]", + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000101-4]", + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000202-1]", + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000202-2]", + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000202-3]", + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000202-4]", + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000303-1]", + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000303-2]", + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000303-3]", + "[creating coopSharesTransaction test-data, hs_office.coopsharetx, INSERT, ref 1000303-4]"); } @BeforeEach diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipRepositoryIntegrationTest.java index ddceb536..0929f370 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipRepositoryIntegrationTest.java @@ -119,7 +119,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl initialGrantNames, // insert "{ grant perm:membership#M-1000117:INSERT>coopassettx to role:membership#M-1000117:ADMIN by system and assume }", - "{ grant perm:membership#M-1000117:INSERT>coopsharestransaction to role:membership#M-1000117:ADMIN by system and assume }", + "{ grant perm:membership#M-1000117:INSERT>coopsharetx to role:membership#M-1000117:ADMIN by system and assume }", // owner "{ grant perm:membership#M-1000117:DELETE to role:membership#M-1000117:ADMIN by system and assume }", diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 923c62e9..b4945a0f 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -7,7 +7,7 @@ spring: url-tc: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers url-tcx: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers?TC_REUSABLE=true&TC_DAEMON=true url-local: jdbc:postgresql://localhost:5432/postgres - url: ${spring.datasource.url-tc} + url: ${spring.datasource.url-local} username: postgres password: password -- 2.39.5 From 77c22d0e5518c44aecaf2e7058099ddb5a832a47 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 20 Sep 2024 13:14:10 +0200 Subject: [PATCH 14/14] remove new_... in tf --- .../generator/InsertTriggerGenerator.java | 8 +++---- .../2013-rbactest-customer-rbac.sql | 8 +++---- .../2023-rbactest-package-rbac.sql | 8 +++---- .../2033-rbactest-domain-rbac.sql | 8 +++---- .../5033-hs-office-relation-rbac.sql | 8 +++---- .../5043-hs-office-partner-rbac.sql | 8 +++---- .../5044-hs-office-partner-details-rbac.sql | 8 +++---- .../5063-hs-office-debitor-rbac.sql | 8 +++---- .../5073-hs-office-sepamandate-rbac.sql | 8 +++---- .../5103-hs-office-membership-rbac.sql | 8 +++---- .../5113-hs-office-coopshares-rbac.sql | 8 +++---- .../5123-hs-office-coopassets-rbac.sql | 8 +++---- .../6203-hs-booking-project-rbac.sql | 8 +++---- .../6303-hs-booking-item-rbac.sql | 24 +++++++++---------- src/test/resources/application.yml | 2 +- 15 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java b/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java index 8ab6a70d..27ede1d4 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java @@ -100,7 +100,7 @@ public class InsertTriggerGenerator { /** Grants ${rawSubTable} INSERT permission to specified role of new ${rawSuperTable} rows. */ - create or replace function ${rawSubTableSchemaPrefix}new_${rawSubTableShortName}_grants_insert_to_${rawSuperTableShortName}_tf() + create or replace function ${rawSubTableSchemaPrefix}${rawSubTableShortName}_grants_insert_to_${rawSuperTableShortName}_tf() returns trigger language plpgsql strict as $$ @@ -113,11 +113,11 @@ public class InsertTriggerGenerator { 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_${rawSubTableName}_grants_after_insert_tg + -- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist + create trigger ${rawSubTableName}_z_grants_after_insert_tg after insert on ${rawSuperTableWithSchema} for each row - execute procedure ${rawSubTableSchemaPrefix}new_${rawSubTableShortName}_grants_insert_to_${rawSuperTableShortName}_tf(); + execute procedure ${rawSubTableSchemaPrefix}${rawSubTableShortName}_grants_insert_to_${rawSuperTableShortName}_tf(); """, with("ifConditionThen", g.getSuperRoleDef().getEntityAlias().isCaseDependent() // TODO.impl: .type needs to be dynamically generated diff --git a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql index 69bc70b3..6451fd34 100644 --- a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql +++ b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql @@ -104,7 +104,7 @@ $$; /** Grants rbactest.customer INSERT permission to specified role of new global rows. */ -create or replace function rbactest.new_customer_grants_insert_to_global_tf() +create or replace function rbactest.customer_grants_insert_to_global_tf() returns trigger language plpgsql strict as $$ @@ -117,11 +117,11 @@ begin 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_customer_grants_after_insert_tg +-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist +create trigger customer_z_grants_after_insert_tg after insert on rbac.global for each row -execute procedure rbactest.new_customer_grants_insert_to_global_tf(); +execute procedure rbactest.customer_grants_insert_to_global_tf(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql index 6cd43f38..2d2e9804 100644 --- a/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql +++ b/src/main/resources/db/changelog/2-rbactest/202-rbactest-package/2023-rbactest-package-rbac.sql @@ -169,7 +169,7 @@ $$; /** Grants rbactest.package INSERT permission to specified role of new customer rows. */ -create or replace function rbactest.new_package_grants_insert_to_customer_tf() +create or replace function rbactest.package_grants_insert_to_customer_tf() returns trigger language plpgsql strict as $$ @@ -182,11 +182,11 @@ begin 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_package_grants_after_insert_tg +-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist +create trigger package_z_grants_after_insert_tg after insert on rbactest.customer for each row -execute procedure rbactest.new_package_grants_insert_to_customer_tf(); +execute procedure rbactest.package_grants_insert_to_customer_tf(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql b/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql index 4d5ff601..f2195485 100644 --- a/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql +++ b/src/main/resources/db/changelog/2-rbactest/203-rbactest-domain/2033-rbactest-domain-rbac.sql @@ -168,7 +168,7 @@ $$; /** Grants rbactest.domain INSERT permission to specified role of new package rows. */ -create or replace function rbactest.new_domain_grants_insert_to_package_tf() +create or replace function rbactest.domain_grants_insert_to_package_tf() returns trigger language plpgsql strict as $$ @@ -181,11 +181,11 @@ begin 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_domain_grants_after_insert_tg +-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist +create trigger domain_z_grants_after_insert_tg after insert on rbactest.package for each row -execute procedure rbactest.new_domain_grants_insert_to_package_tf(); +execute procedure rbactest.domain_grants_insert_to_package_tf(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql b/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql index d23d0d09..5c100b33 100644 --- a/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/503-relation/5033-hs-office-relation-rbac.sql @@ -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 $$ @@ -191,11 +191,11 @@ begin 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(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql index 9186dd7d..765c0f10 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql @@ -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 $$ @@ -194,11 +194,11 @@ begin 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(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql index 50c7dc92..eb1f7fd4 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql @@ -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 $$ @@ -98,11 +98,11 @@ begin 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(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql index 7f23e273..746dd38f 100644 --- a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql @@ -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 $$ @@ -167,11 +167,11 @@ begin 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(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql index 5a693add..15e7c589 100644 --- a/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/507-sepamandate/5073-hs-office-sepamandate-rbac.sql @@ -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 $$ @@ -142,11 +142,11 @@ begin 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(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql index 6ad7515f..41587e36 100644 --- a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql @@ -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 $$ @@ -129,11 +129,11 @@ begin 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(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql index 33ea130c..911faa94 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5113-hs-office-coopshares-rbac.sql @@ -92,7 +92,7 @@ $$; /** 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 $$ @@ -105,11 +105,11 @@ begin 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_coopsharetx_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(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql index b6459abd..1800b842 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5123-hs-office-coopassets-rbac.sql @@ -92,7 +92,7 @@ $$; /** 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 $$ @@ -105,11 +105,11 @@ begin 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_coopassettx_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(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql index 80a3403e..88a83fbe 100644 --- a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6203-hs-booking-project-rbac.sql @@ -123,7 +123,7 @@ $$; /** Grants hs_booking.project INSERT permission to specified role of new relation rows. */ -create or replace function hs_booking.new_project_grants_insert_to_relation_tf() +create or replace function hs_booking.project_grants_insert_to_relation_tf() returns trigger language plpgsql strict as $$ @@ -136,11 +136,11 @@ begin 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_project_grants_after_insert_tg +-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist +create trigger project_z_grants_after_insert_tg after insert on hs_office.relation for each row -execute procedure hs_booking.new_project_grants_insert_to_relation_tf(); +execute procedure hs_booking.project_grants_insert_to_relation_tf(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql index 097d5671..67173247 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql @@ -122,7 +122,7 @@ $$; /** Grants hs_booking.item INSERT permission to specified role of new global rows. */ -create or replace function hs_booking.new_item_grants_insert_to_global_tf() +create or replace function hs_booking.item_grants_insert_to_global_tf() returns trigger language plpgsql strict as $$ @@ -135,11 +135,11 @@ begin 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_item_grants_after_insert_tg +-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist +create trigger item_z_grants_after_insert_tg after insert on rbac.global for each row -execute procedure hs_booking.new_item_grants_insert_to_global_tf(); +execute procedure hs_booking.item_grants_insert_to_global_tf(); -- granting INSERT permission to hs_booking.project ---------------------------- @@ -165,7 +165,7 @@ $$; /** Grants hs_booking.item INSERT permission to specified role of new project rows. */ -create or replace function hs_booking.new_item_grants_insert_to_project_tf() +create or replace function hs_booking.item_grants_insert_to_project_tf() returns trigger language plpgsql strict as $$ @@ -178,11 +178,11 @@ begin 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_item_grants_after_insert_tg +-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist +create trigger item_z_grants_after_insert_tg after insert on hs_booking.project for each row -execute procedure hs_booking.new_item_grants_insert_to_project_tf(); +execute procedure hs_booking.item_grants_insert_to_project_tf(); -- granting INSERT permission to hs_booking.item ---------------------------- @@ -192,7 +192,7 @@ execute procedure hs_booking.new_item_grants_insert_to_project_tf(); /** Grants hs_booking.item INSERT permission to specified role of new item rows. */ -create or replace function hs_booking.new_item_grants_insert_to_item_tf() +create or replace function hs_booking.item_grants_insert_to_item_tf() returns trigger language plpgsql strict as $$ @@ -205,11 +205,11 @@ begin 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_item_grants_after_insert_tg +-- ..._z_... is to put it at the end of after insert triggers, to make sure the roles exist +create trigger item_z_grants_after_insert_tg after insert on hs_booking.item for each row -execute procedure hs_booking.new_item_grants_insert_to_item_tf(); +execute procedure hs_booking.item_grants_insert_to_item_tf(); -- ============================================================================ diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index b4945a0f..923c62e9 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -7,7 +7,7 @@ spring: url-tc: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers url-tcx: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers?TC_REUSABLE=true&TC_DAEMON=true url-local: jdbc:postgresql://localhost:5432/postgres - url: ${spring.datasource.url-local} + url: ${spring.datasource.url-tc} username: postgres password: password -- 2.39.5