From 7559b8ced3f4570a0042df31d996443afb648162 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sun, 7 Apr 2024 12:26:13 +0200 Subject: [PATCH] ignore self-representative relation in ImportOfficeData --- .../db/changelog/1-rbac/1050-rbac-base.sql | 24 -------------- .../hs/office/migration/ImportOfficeData.java | 32 +++++++++++++++---- 2 files changed, 26 insertions(+), 30 deletions(-) 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 bfe897a4..2b3147c9 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 @@ -659,30 +659,6 @@ begin on conflict do nothing; -- allow granting multiple times end; $$; -create or replace procedure grantRoleToRoleIfNotNull(subRole RbacRoleDescriptor, superRole RbacRoleDescriptor, doAssume bool = true) - language plpgsql as $$ -declare - superRoleId uuid; - subRoleId uuid; -begin - if ( superRoleId is null ) then return; end if; - superRoleId := findRoleId(superRole); - if ( subRoleId is null ) then return; end if; - subRoleId := findRoleId(subRole); - - perform assertReferenceType('superRoleId (ascendant)', superRoleId, 'RbacRole'); - perform assertReferenceType('subRoleId (descendant)', subRoleId, 'RbacRole'); - - if isGranted(subRoleId, superRoleId) then - call raiseDuplicateRoleGrantException(subRoleId, superRoleId); - end if; - - insert - into RbacGrants (grantedByTriggerOf, ascendantuuid, descendantUuid, assumed) - values (currentTriggerObjectUuid(), superRoleId, subRoleId, doAssume) - on conflict do nothing; -- allow granting multiple times -end; $$; - create or replace procedure revokeRoleFromRole(subRole RbacRoleDescriptor, superRole RbacRoleDescriptor) language plpgsql as $$ declare diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java index 14a41b66..7cbb0473 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/migration/ImportOfficeData.java @@ -421,14 +421,33 @@ public class ImportOfficeData extends ContextBasedTest { } @Test - @Order(2009) + @Order(3001) + void removeSelfRepresentativeRelations() { + assumeThatWeAreImportingControlledTestData(); + + // this happens if a natural person is marked as 'contractual' for itself + final var idsToRemove = new HashSet(); + relations.forEach( (id, r) -> { + if (r.getHolder() == r.getAnchor() ) { + idsToRemove.add(id); + } + }); + + // remove self-representatives + idsToRemove.forEach(id -> { + System.out.println("removing self representative relation: " + relations.get(id).toString()); + relations.remove(id); + }); + } + + @Test + @Order(3002) void removeEmptyRelations() { assumeThatWeAreImportingControlledTestData(); // avoid a error when persisting the deliberately invalid partner entry #99 final var idsToRemove = new HashSet(); relations.forEach( (id, r) -> { - // such a record if (r.getContact() == null || r.getContact().getLabel() == null || r.getHolder() == null || r.getHolder().getPersonType() == null ) { idsToRemove.add(id); @@ -443,7 +462,7 @@ public class ImportOfficeData extends ContextBasedTest { } @Test - @Order(2002) + @Order(3003) void removeEmptyPartners() { assumeThatWeAreImportingControlledTestData(); @@ -467,7 +486,7 @@ public class ImportOfficeData extends ContextBasedTest { } @Test - @Order(2003) + @Order(3004) void removeEmptyDebitors() { assumeThatWeAreImportingControlledTestData(); @@ -486,7 +505,7 @@ public class ImportOfficeData extends ContextBasedTest { } @Test - @Order(3000) + @Order(9000) @Commit void persistEntities() { @@ -512,6 +531,7 @@ public class ImportOfficeData extends ContextBasedTest { relations.forEach(this::persist); }).assertSuccessful(); + System.out.println("persisting " + partners.size() + " partners"); jpaAttempt.transacted(() -> { context(rbacSuperuser); partners.forEach((id, partner) -> { @@ -529,7 +549,7 @@ public class ImportOfficeData extends ContextBasedTest { context(rbacSuperuser); debitors.forEach((id, debitor) -> { debitor.setDebitorRel(em.merge(debitor.getDebitorRel())); - em.persist(debitor); + persist(id, debitor); }); }).assertSuccessful();