fix debitor_iv and person.optionalPartner

This commit is contained in:
Michael Hoennig 2024-03-16 10:51:44 +01:00
parent 86148c3258
commit 690454d80f
6 changed files with 43 additions and 36 deletions

View File

@ -107,16 +107,16 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable {
public static RbacView rbac() { public static RbacView rbac() {
return rbacViewFor("debitor", HsOfficeDebitorEntity.class) return rbacViewFor("debitor", HsOfficeDebitorEntity.class)
.withIdentityView(SQL.query(""" .withIdentityView(SQL.query("""
SELECT debitor.uuid AS uuid, SELECT debitor.uuid AS uuid,
'D-' || (SELECT partner.partnerNumber 'D-' || (SELECT partner.partnerNumber
FROM hs_office_partner partner FROM hs_office_partner partner
JOIN hs_office_relationship partnerRel JOIN hs_office_relationship partnerRel
ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER' ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER'
JOIN hs_office_relationship debitorRel JOIN hs_office_relationship debitorRel
ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND partnerRel.relType = 'ACCOUNTING' ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND debitorRel.relType = 'ACCOUNTING'
WHERE debitorRel.uuid = debitor.debitorRelUuid) WHERE debitorRel.uuid = debitor.debitorRelUuid)
|| to_char(debitorNumberSuffix, 'fm00') as idName || to_char(debitorNumberSuffix, 'fm00') as idName
FROM hs_office_debitor AS debitor FROM hs_office_debitor AS debitor
""")) """))
.withRestrictedViewOrderBy(SQL.projection("defaultPrefix")) .withRestrictedViewOrderBy(SQL.projection("defaultPrefix"))
.withUpdatableColumns( .withUpdatableColumns(

View File

@ -59,14 +59,19 @@ public class HsOfficePersonEntity implements HasUuid, Stringifyable {
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne(cascade = CascadeType.ALL)
@JoinFormula( @JoinFormula(
referencedColumnName = "uuid", referencedColumnName = "uuid",
// FIXME: use _rv in sub-query
value = """ value = """
(SELECT partner.uuid AS uuid (
FROM hs_office_partner partner SELECT DISTINCT partner.uuid AS uuid
JOIN hs_office_relationship partnerRel FROM hs_office_partner partner
ON partnerRel.uuid = partner.partnerRoleUuid AND partnerRel.relType = 'PARTNER' JOIN hs_office_relationship partnerRel
WHERE partnerRel.relHolderUuid = h1_0.uuid) ON partnerRel.uuid = partner.partnerRoleUuid AND partnerRel.relType = 'PARTNER'
""") // FIXME: h1_0 is the generated self-reference, I should find a better solution WHERE partnerRel.relHolderUuid = personUuid
private HsOfficePartnerEntity optionalPartner; @Override ) -- uuid would be ambiguous with outer uuid
""")
private HsOfficePartnerEntity optionalPartner;
@Override
public String toString() { public String toString() {
return toString.apply(this); return toString.apply(this);
} }

View File

@ -17,6 +17,7 @@ CREATE CAST (character varying as HsOfficePersonType) WITH INOUT AS IMPLICIT;
create table if not exists hs_office_person create table if not exists hs_office_person
( (
uuid uuid unique references RbacObject (uuid) initially deferred, uuid uuid unique references RbacObject (uuid) initially deferred,
personUuid uuid GENERATED ALWAYS AS (uuid) stored, -- see usage in HsOfficePersonEntity
personType HsOfficePersonType not null, personType HsOfficePersonType not null,
tradeName varchar(96), tradeName varchar(96),
givenName varchar(48), givenName varchar(48),

View File

@ -1,6 +1,6 @@
### rbac debitor ### rbac debitor
This code generated was by RbacViewMermaidFlowchartGenerator at 2024-03-12T16:22:27.339854728. This code generated was by RbacViewMermaidFlowchartGenerator at 2024-03-16T10:26:46.080386825.
```mermaid ```mermaid
%%{init:{'flowchart':{'htmlLabels':false}}}%% %%{init:{'flowchart':{'htmlLabels':false}}}%%

View File

@ -1,5 +1,5 @@
--liquibase formatted sql --liquibase formatted sql
-- This code generated was by RbacViewPostgresGenerator at 2024-03-12T16:22:27.348469700. -- This code generated was by RbacViewPostgresGenerator at 2024-03-16T10:26:46.091076286.
-- ============================================================================ -- ============================================================================
@ -220,11 +220,12 @@ create or replace function hs_office_debitor_global_insert_tf()
strict as $$ strict as $$
begin begin
call grantPermissionToRole( call grantPermissionToRole(
globalAdmin(), createPermission(NEW.uuid, 'INSERT', 'hs_office_debitor'),
createPermission(NEW.uuid, 'INSERT', 'hs_office_debitor')); globalAdmin());
return NEW; return NEW;
end; $$; end; $$;
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
create trigger z_hs_office_debitor_global_insert_tg create trigger z_hs_office_debitor_global_insert_tg
after insert on global after insert on global
for each row for each row
@ -253,16 +254,16 @@ create trigger hs_office_debitor_insert_permission_check_tg
-- ---------------------------------------------------------------------------- -- ----------------------------------------------------------------------------
call generateRbacIdentityViewFromQuery('hs_office_debitor', $idName$ call generateRbacIdentityViewFromQuery('hs_office_debitor', $idName$
SELECT debitor.uuid AS uuid, SELECT debitor.uuid AS uuid,
'D-' || (SELECT partner.partnerNumber 'D-' || (SELECT partner.partnerNumber
FROM hs_office_partner partner FROM hs_office_partner partner
JOIN hs_office_relationship partnerRel JOIN hs_office_relationship partnerRel
ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER' ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER'
JOIN hs_office_relationship debitorRel JOIN hs_office_relationship debitorRel
ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND partnerRel.relType = 'ACCOUNTING' ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND debitorRel.relType = 'ACCOUNTING'
WHERE debitorRel.uuid = debitor.debitorRelUuid) WHERE debitorRel.uuid = debitor.debitorRelUuid)
|| to_char(debitorNumberSuffix, 'fm00') as idName || to_char(debitorNumberSuffix, 'fm00') as idName
FROM hs_office_debitor AS debitor FROM hs_office_debitor AS debitor
$idName$); $idName$);
--// --//

View File

@ -236,9 +236,9 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
// then // then
allTheseDebitorsAreReturned( allTheseDebitorsAreReturned(
result, result,
"debitor(D-1000111: P-10001, fir)", "debitor(D-1000111: rel(relAnchor='LP First GmbH', relType='ACCOUNTING', relHolder='LP First GmbH'), fir)",
"debitor(D-1000212: P-10002, sec)", "debitor(D-1000212: rel(relAnchor='LP Second e.K.', relType='ACCOUNTING', relHolder='LP Second e.K.'), sec)",
"debitor(D-1000313: P-10003, thi)"); "debitor(D-1000313: rel(relAnchor='IF Third OHG', relType='ACCOUNTING', relHolder='IF Third OHG'), thi)");
} }
@ParameterizedTest @ParameterizedTest
@ -302,7 +302,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
final var result = debitorRepo.findDebitorByOptionalNameLike("third contact"); final var result = debitorRepo.findDebitorByOptionalNameLike("third contact");
// then // then
exactlyTheseDebitorsAreReturned(result, "debitor(D-1000313: P-10003, thi)"); exactlyTheseDebitorsAreReturned(result, "debitor(D-1000313: rel(relAnchor='IF Third OHG', relType='ACCOUNTING', relHolder='IF Third OHG'), thi)");
} }
} }
@ -536,7 +536,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", "hs_office_debitor#1000420:FourtheG-fourthcontact.agent"); context("superuser-alex@hostsharing.net", "hs_office_debitor#D-1000420.agent");
assertThat(debitorRepo.findByUuid(givenDebitor.getUuid())).isPresent(); assertThat(debitorRepo.findByUuid(givenDebitor.getUuid())).isPresent();
debitorRepo.deleteByUuid(givenDebitor.getUuid()); debitorRepo.deleteByUuid(givenDebitor.getUuid());