merging master aftermath, ImportOfficeData not fully working yet
This commit is contained in:
parent
6e663cf525
commit
37f00a19f0
@ -8,7 +8,7 @@ Vor einigen Wochen hatten wir schon einmal darüber geredet, ob wir dieses Gefle
|
||||
|
||||
Und nun gehe ich noch einen Schritt weiter: Könnte es nicht auch andersherum sein? Also wenn jemand z.B. SELECT-Recht am Partner hat, dass wir davon ausgehen können, dass derjenige auch die Partner-Personen- und Kontaktdaten sehen darf, und zwar implizit durch seine Partner-SELECT-Permission und ohne dass er explizit Rollen für diese Partner-Personen oder Kontaktdaten inne hat?
|
||||
|
||||
Im Halbschlaf kam mir nur die Idee, warum wir nicht einfach die komplexen JPA-Entitäten zwar auf die restricted View setzen, wie bisher, aber für die verknüpften Entitäten auf die direkten (bisher "Raw..." genannt) Entitäten gehen. Dann könnte jemand mit einer Rolle, welche die SELECT-Permission auf die komplexe JPA-Entität (z.B.) Partner inne hat, auch die dazugehörige Relation(ship) ["Relationship" wurde vor kurzem auf kurz "Relation" umbenannt] und die wiederum dazu gehörigen Personen- und Kontaktdaten lesen, ohne dass in einem INSERT- und UPDATE-Trigger der Partner-Entität die ganzen Grants mit den verknüpften Entäten aufgebaut und aktualisiert werden müssen.
|
||||
Im Halbschlaf kam mir nur die Idee, warum wir nicht einfach die komplexen JPA-Entitäten zwar auf die restricted View setzen, wie bisher, aber für die verknüpften Entitäten auf die direkten (bisher "Raw..." genannt) Entitäten gehen. Dann könnte jemand mit einer Rolle, welche die SELECT-Permission auf die komplexe JPA-Entität (z.B.) Partner inne hat, auch die dazugehörige Relation(ship) ["Relation" wurde vor kurzem auf kurz "Relation" umbenannt] und die wiederum dazu gehörigen Personen- und Kontaktdaten lesen, ohne dass in einem INSERT- und UPDATE-Trigger der Partner-Entität die ganzen Grants mit den verknüpften Entäten aufgebaut und aktualisiert werden müssen.
|
||||
|
||||
Beim Debitor ist das nämlich selbst mit Generator die Hölle, zumal eben auch Querverbindungen gegranted werden müssen, z.B. von der Debitor-Person zum Sema-Mandat - jedenfalls wenn man nicht Gefahr laufen wollte, dass jemand mit Admin-Rechten an der Partner-Person (also z.B. ein Repräsentant des Partners) die Sepa-Mandate der Debitoren gar nicht mehr sehen kann. Natürlich bräuchte man immer noch die Agent-Rolle am Partner und Debitor (evtl. repräsentiert durch die jeweils zugehörigen Relation - falls dieser Trick überhaupt noch nötig wäre), sowie ein Grant vom Partner-Agent auf den Debitor-Agent und vom Debitor-Agent auf die Sepa-Mandate-Admins, aber eben ohne filigran die ganzen Neben-Entäten (Personen- und Kontaktdaten von Partner und Debitor sowie Bank-Account) in jedem Trigger berücksichtigen zu müssen. Beim Refund-Bank-Account sogar besonders ätzend, weil der optional ist und dadurch zig "if ...refundBankAccountUuid is not null then ..." im Code enstehen (wenn der auch generiert ist).
|
||||
|
||||
|
@ -8,11 +8,11 @@ Das folgende Schema soll dabei unterstützen, die richtigen Permissions, Rollen
|
||||
|
||||
An einigen Stellen ist vom *Initiator* die Rede. Als *Initiator* gilt derjenige User, der die Operation (INSERT oder UPDATE) durchführt bzw. dessen primary assumed Rol. (TODO: bisher gibt es nur assumed roles, das Konzept einer primary assumed Role müsste noch eingeführt werden, derzeit nehmen wir dafür immer den `globalAdmin()`. Bevor Kunden aber selbst Objekte anlegen können, muss das geklärt sein.)
|
||||
|
||||
#### Typ Root: Objekte, welche nur eine Spezialisierung bzw. Zusatzdaten für andere Objekte bereitstellen (z.B. Partner für Relationships vom Typ Partner oder Partner Details für Partner)
|
||||
#### Typ Root: Objekte, welche nur eine Spezialisierung bzw. Zusatzdaten für andere Objekte bereitstellen (z.B. Partner für Relations vom Typ Partner oder Partner Details für Partner)
|
||||
|
||||
Objektorientiert gedacht, enthalten solche Objekte die Zusatzdaten einer Subklasse; die Daten im Partner erweitern also eine Relationship vom Typ `partner`.
|
||||
Objektorientiert gedacht, enthalten solche Objekte die Zusatzdaten einer Subklasse; die Daten im Partner erweitern also eine Relation vom Typ `partner`.
|
||||
|
||||
- Dann muss dieses Objekt zeitlich nach dem Objekt erzeugt werden, auf dass es sich bezieht, also z.B. zeitlich nach der Relationship.
|
||||
- Dann muss dieses Objekt zeitlich nach dem Objekt erzeugt werden, auf dass es sich bezieht, also z.B. zeitlich nach der Relation.
|
||||
- Es werden Delete (\*), Edit und View Permissions für dieses Objekt erzeugt.
|
||||
- Es werden **keine** Rollen für dieses Objekt erzeugt.
|
||||
- Statt eigener Rollen werden die o.g. Permissions passenden Rollen des Hauptobjekts zugewiesen (granted) bzw. aus denen entfernt (revoked).
|
||||
@ -33,7 +33,7 @@ Objektorientiert gedacht, enthalten solche Objekte die Zusatzdaten einer Subklas
|
||||
Anmerkung: Der Typ-Begriff *Root* bezieht sich auf die Rolle im fachlichen Datenmodell. Im Bezug auf den Teilgraphen eines fachlichen Kontexts ist dies auch eine Wurzel im Sinne der Graphentheorie. Aber in anderen fachlichen Kontexten können auch diese Objekte von anderen Teilgraphen referenziert werden und werden dann zum inneren Knoten.
|
||||
|
||||
|
||||
#### Typ Aggregator: Objekte, welche weitere Objekte zusammenfassen (z.B. Relationship fasst zwei Persons und einen Contact zusammen)
|
||||
#### Typ Aggregator: Objekte, welche weitere Objekte zusammenfassen (z.B. Relation fasst zwei Persons und einen Contact zusammen)
|
||||
|
||||
Solche Objekte verweisen üblicherweise auf Objekte vom Typ Leaf und werden oft von Objekten des Typs Root referenziert.
|
||||
|
||||
|
@ -5,8 +5,8 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeDebitors
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorInsertResource;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorResource;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
|
||||
import net.hostsharing.hsadminng.mapper.Mapper;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -21,7 +21,7 @@ import jakarta.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType.ACCOUNTING;
|
||||
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.DEBITOR;
|
||||
|
||||
@RestController
|
||||
|
||||
@ -37,7 +37,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
||||
private HsOfficeDebitorRepository debitorRepo;
|
||||
|
||||
@Autowired
|
||||
private HsOfficeRelationshipRepository relRepo;
|
||||
private HsOfficeRelationRepository relRepo;
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
@ -73,15 +73,15 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi {
|
||||
Validate.isTrue(body.getDebitorRel() != null || body.getDebitorRelUuid() != null,
|
||||
"ERROR: [400] exactly one of debitorRel and debitorRelUuid must be supplied, but found none");
|
||||
Validate.isTrue(body.getDebitorRel() == null ||
|
||||
body.getDebitorRel().getRelType() == null || ACCOUNTING.name().equals(body.getDebitorRel().getRelType()),
|
||||
"ERROR: [400] debitorRel.relType must be '"+ACCOUNTING.name()+"' or null for default");
|
||||
Validate.isTrue(body.getDebitorRel() == null || body.getDebitorRel().getRelMark() == null,
|
||||
"ERROR: [400] debitorRel.relMark must be null");
|
||||
body.getDebitorRel().getType() == null || DEBITOR.name().equals(body.getDebitorRel().getType()),
|
||||
"ERROR: [400] debitorRel.type must be '"+DEBITOR.name()+"' or null for default");
|
||||
Validate.isTrue(body.getDebitorRel() == null || body.getDebitorRel().getMark() == null,
|
||||
"ERROR: [400] debitorRel.mark must be null");
|
||||
|
||||
final var entityToSave = mapper.map(body, HsOfficeDebitorEntity.class);
|
||||
if ( body.getDebitorRel() != null ) {
|
||||
body.getDebitorRel().setRelType(ACCOUNTING.name());
|
||||
final var debitorRel = mapper.map(body.getDebitorRel(), HsOfficeRelationshipEntity.class);
|
||||
body.getDebitorRel().setType(DEBITOR.name());
|
||||
final var debitorRel = mapper.map(body.getDebitorRel(), HsOfficeRelationEntity.class);
|
||||
entityToSave.setDebitorRel(relRepo.save(debitorRel));
|
||||
// FIXME em.flush();
|
||||
} else {
|
||||
|
@ -3,8 +3,8 @@ package net.hostsharing.hsadminng.hs.office.debitor;
|
||||
import lombok.*;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.persistence.HasUuid;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
|
||||
@ -43,7 +43,7 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable {
|
||||
private static Stringify<HsOfficeDebitorEntity> stringify =
|
||||
stringify(HsOfficeDebitorEntity.class, "debitor")
|
||||
.withIdProp(HsOfficeDebitorEntity::toShortString)
|
||||
.withProp(e -> ofNullable(e.getDebitorRel()).map(HsOfficeRelationshipEntity::toShortString).orElse(null))
|
||||
.withProp(e -> ofNullable(e.getDebitorRel()).map(HsOfficeRelationEntity::toShortString).orElse(null))
|
||||
.withProp(HsOfficeDebitorEntity::getDefaultPrefix)
|
||||
.quotedValues(false);
|
||||
|
||||
@ -60,11 +60,11 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable {
|
||||
(
|
||||
SELECT DISTINCT partner.uuid
|
||||
FROM hs_office_partner partner
|
||||
JOIN hs_office_relationship dRel
|
||||
ON dRel.uuid = debitorreluuid AND dRel.relType = 'ACCOUNTING'
|
||||
JOIN hs_office_relationship pRel
|
||||
ON pRel.uuid = partner.partnerRoleUuid AND pRel.relType = 'PARTNER'
|
||||
WHERE pRel.relHolderUuid = dRel.relAnchorUuid
|
||||
JOIN hs_office_relation dRel
|
||||
ON dRel.uuid = debitorreluuid AND dRel.type = 'DEBITOR'
|
||||
JOIN hs_office_relation pRel
|
||||
ON pRel.uuid = partner.partnerRelUuid AND pRel.type = 'PARTNER'
|
||||
WHERE pRel.holderUuid = dRel.anchorUuid
|
||||
)
|
||||
""")
|
||||
@NotFound(action = NotFoundAction.IGNORE)
|
||||
@ -75,7 +75,7 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable {
|
||||
|
||||
@ManyToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "debitorreluuid", nullable = false)
|
||||
private HsOfficeRelationshipEntity debitorRel;
|
||||
private HsOfficeRelationEntity debitorRel;
|
||||
|
||||
@Column(name = "billable", nullable = false)
|
||||
private Boolean billable; // not a primitive because otherwise the default would be false
|
||||
@ -128,10 +128,10 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable {
|
||||
SELECT debitor.uuid AS uuid,
|
||||
'D-' || (SELECT partner.partnerNumber
|
||||
FROM hs_office_partner partner
|
||||
JOIN hs_office_relationship partnerRel
|
||||
ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER'
|
||||
JOIN hs_office_relationship debitorRel
|
||||
ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND debitorRel.relType = 'ACCOUNTING'
|
||||
JOIN hs_office_relation partnerRel
|
||||
ON partnerRel.uuid = partner.partnerRelUUid AND partnerRel.type = 'PARTNER'
|
||||
JOIN hs_office_relation debitorRel
|
||||
ON debitorRel.anchorUuid = partnerRel.holderUuid AND debitorRel.type = 'DEBITOR'
|
||||
WHERE debitorRel.uuid = debitor.debitorRelUuid)
|
||||
|| to_char(debitorNumberSuffix, 'fm00') as idName
|
||||
FROM hs_office_debitor AS debitor
|
||||
@ -148,11 +148,11 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable {
|
||||
"defaultPrefix" /* TODO: do we want that updatable? */)
|
||||
.toRole("global", ADMIN).grantPermission(INSERT)
|
||||
|
||||
.importRootEntityAliasProxy("debitorRel", HsOfficeRelationshipEntity.class,
|
||||
.importRootEntityAliasProxy("debitorRel", HsOfficeRelationEntity.class,
|
||||
fetchedBySql("""
|
||||
SELECT *
|
||||
FROM hs_office_relationship AS r
|
||||
WHERE r.relType = 'ACCOUNTING' AND r.uuid = ${REF}.debitorRelUuid
|
||||
FROM hs_office_relation AS r
|
||||
WHERE r.type = 'DEBITOR' AND r.uuid = ${REF}.debitorRelUuid
|
||||
"""),
|
||||
dependsOnColumn("debitorRelUuid"))
|
||||
.createPermission(DELETE).grantedTo("debitorRel", OWNER)
|
||||
@ -171,14 +171,14 @@ public class HsOfficeDebitorEntity implements HasUuid, Stringifyable {
|
||||
.toRole("refundBankAccount", ADMIN).grantRole("debitorRel", AGENT)
|
||||
.toRole("debitorRel", AGENT).grantRole("refundBankAccount", REFERRER)
|
||||
|
||||
.importEntityAlias("partnerRel", HsOfficeRelationshipEntity.class,
|
||||
.importEntityAlias("partnerRel", HsOfficeRelationEntity.class,
|
||||
dependsOnColumn("debitorRelUuid"),
|
||||
fetchedBySql("""
|
||||
SELECT partnerRel.*
|
||||
FROM hs_office_relationship AS partnerRel
|
||||
JOIN hs_office_relationship AS debitorRel
|
||||
ON debitorRel.relType = 'ACCOUNTING' AND debitorRel.relAnchorUuid = partnerRel.relHolderUuid
|
||||
WHERE partnerRel.relType = 'PARTNER'
|
||||
FROM hs_office_relation AS partnerRel
|
||||
JOIN hs_office_relation AS debitorRel
|
||||
ON debitorRel.type = 'DEBITOR' AND debitorRel.anchorUuid = partnerRel.holderUuid
|
||||
WHERE partnerRel.type = 'PARTNER'
|
||||
AND ${REF}.debitorRelUuid = debitorRel.uuid
|
||||
""")
|
||||
)
|
||||
|
@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.mapper.EntityPatcher;
|
||||
import net.hostsharing.hsadminng.mapper.OptionalFromJson;
|
||||
|
||||
@ -25,7 +25,7 @@ class HsOfficeDebitorEntityPatcher implements EntityPatcher<HsOfficeDebitorPatch
|
||||
public void apply(final HsOfficeDebitorPatchResource resource) {
|
||||
OptionalFromJson.of(resource.getDebitorRelUuid()).ifPresent(newValue -> {
|
||||
verifyNotNull(newValue, "debitorRel");
|
||||
entity.setDebitorRel(em.getReference(HsOfficeRelationshipEntity.class, newValue));
|
||||
entity.setDebitorRel(em.getReference(HsOfficeRelationEntity.class, newValue));
|
||||
});
|
||||
Optional.ofNullable(resource.getBillable()).ifPresent(entity::setBillable);
|
||||
OptionalFromJson.of(resource.getVatId()).ifPresent(entity::setVatId);
|
||||
|
@ -14,8 +14,8 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
|
||||
@Query("""
|
||||
SELECT debitor FROM HsOfficeDebitorEntity debitor
|
||||
JOIN HsOfficePartnerEntity partner
|
||||
ON partner.partnerRole.relHolder = debitor.debitorRel.relAnchor
|
||||
AND partner.partnerRole.relType = 'PARTNER' AND debitor.debitorRel.relType = 'ACCOUNTING'
|
||||
ON partner.partnerRel.holder = debitor.debitorRel.anchor
|
||||
AND partner.partnerRel.type = 'PARTNER' AND debitor.debitorRel.type = 'DEBITOR'
|
||||
WHERE cast(partner.partnerNumber as integer) = :partnerNumber
|
||||
AND cast(debitor.debitorNumberSuffix as integer) = :debitorNumberSuffix
|
||||
""")
|
||||
@ -28,14 +28,14 @@ public interface HsOfficeDebitorRepository extends Repository<HsOfficeDebitorEnt
|
||||
@Query("""
|
||||
SELECT debitor FROM HsOfficeDebitorEntity debitor
|
||||
JOIN HsOfficePartnerEntity partner
|
||||
ON partner.partnerRole.relHolder = debitor.debitorRel.relAnchor
|
||||
AND partner.partnerRole.relType = 'PARTNER' AND debitor.debitorRel.relType = 'ACCOUNTING'
|
||||
ON partner.partnerRel.holder = debitor.debitorRel.anchor
|
||||
AND partner.partnerRel.type = 'PARTNER' AND debitor.debitorRel.type = 'DEBITOR'
|
||||
JOIN HsOfficePersonEntity person
|
||||
ON person.uuid = partner.partnerRole.relHolder.uuid
|
||||
OR person.uuid = debitor.debitorRel.relHolder.uuid
|
||||
ON person.uuid = partner.partnerRel.holder.uuid
|
||||
OR person.uuid = debitor.debitorRel.holder.uuid
|
||||
JOIN HsOfficeContactEntity contact
|
||||
ON contact.uuid = debitor.debitorRel.contact.uuid
|
||||
OR contact.uuid = partner.partnerRole.contact.uuid
|
||||
OR contact.uuid = partner.partnerRel.contact.uuid
|
||||
WHERE :name is null
|
||||
OR partner.details.birthName like concat(cast(:name as text), '%')
|
||||
OR person.tradeName like concat(cast(:name as text), '%')
|
||||
|
@ -4,7 +4,7 @@ import com.vladmihalcea.hibernate.type.range.PostgreSQLRangeType;
|
||||
import com.vladmihalcea.hibernate.type.range.Range;
|
||||
import lombok.*;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.persistence.HasUuid;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
@ -128,12 +128,12 @@ public class HsOfficeMembershipEntity implements HasUuid, Stringifyable {
|
||||
.withRestrictedViewOrderBy(SQL.projection("validity"))
|
||||
.withUpdatableColumns("validity", "membershipFeeBillable", "reasonForTermination")
|
||||
|
||||
.importEntityAlias("partnerRel", HsOfficeRelationshipEntity.class,
|
||||
.importEntityAlias("partnerRel", HsOfficeRelationEntity.class,
|
||||
dependsOnColumn("partnerUuid"),
|
||||
fetchedBySql("""
|
||||
SELECT r.*
|
||||
FROM hs_office_partner AS p
|
||||
JOIN hs_office_relationship AS r ON r.uuid = p.partnerRoleUuid
|
||||
JOIN hs_office_relation AS r ON r.uuid = p.partnerRelUuid
|
||||
WHERE p.uuid = ${REF}.partnerUuid
|
||||
"""))
|
||||
.toRole("partnerRel", ADMIN).grantPermission(INSERT)
|
||||
|
@ -7,11 +7,11 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficePartners
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerInsertResource;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerResource;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerRoleInsertResource;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerRelInsertResource;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||
import net.hostsharing.hsadminng.mapper.Mapper;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -40,7 +40,7 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
||||
private HsOfficePartnerRepository partnerRepo;
|
||||
|
||||
@Autowired
|
||||
private HsOfficeRelationshipRepository relationshipRepo;
|
||||
private HsOfficeRelationRepository relationRepo;
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
@ -139,16 +139,16 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
||||
private HsOfficePartnerEntity createPartnerEntity(final HsOfficePartnerInsertResource body) {
|
||||
final var entityToSave = new HsOfficePartnerEntity();
|
||||
entityToSave.setPartnerNumber(body.getPartnerNumber());
|
||||
entityToSave.setPartnerRole(persistPartnerRole(body.getPartnerRole()));
|
||||
entityToSave.setPartnerRel(persistPartnerRel(body.getPartnerRel()));
|
||||
entityToSave.setDetails(mapper.map(body.getDetails(), HsOfficePartnerDetailsEntity.class));
|
||||
return entityToSave;
|
||||
}
|
||||
|
||||
private HsOfficeRelationshipEntity persistPartnerRole(final HsOfficePartnerRoleInsertResource resource) {
|
||||
final var entity = new HsOfficeRelationshipEntity();
|
||||
entity.setRelType(HsOfficeRelationshipType.PARTNER);
|
||||
entity.setRelAnchor(ref(HsOfficePersonEntity.class, resource.getRelAnchorUuid()));
|
||||
entity.setRelHolder(ref(HsOfficePersonEntity.class, resource.getRelHolderUuid()));
|
||||
private HsOfficeRelationEntity persistPartnerRel(final HsOfficePartnerRelInsertResource resource) {
|
||||
final var entity = new HsOfficeRelationEntity();
|
||||
entity.setType(HsOfficeRelationType.PARTNER);
|
||||
entity.setAnchor(ref(HsOfficePersonEntity.class, resource.getAnchorUuid()));
|
||||
entity.setHolder(ref(HsOfficePersonEntity.class, resource.getHolderUuid()));
|
||||
entity.setContact(ref(HsOfficeContactEntity.class, resource.getContactUuid()));
|
||||
em.persist(entity);
|
||||
return entity;
|
||||
|
@ -9,7 +9,7 @@ import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.persistence.HasUuid;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
|
||||
import net.hostsharing.hsadminng.stringify.Stringify;
|
||||
@ -51,12 +51,12 @@ public class HsOfficePartnerEntity implements Stringifyable, HasUuid {
|
||||
|
||||
private static Stringify<HsOfficePartnerEntity> stringify = stringify(HsOfficePartnerEntity.class, "partner")
|
||||
.withIdProp(HsOfficePartnerEntity::toShortString)
|
||||
.withProp(p -> ofNullable(p.getPartnerRole())
|
||||
.map(HsOfficeRelationshipEntity::getRelHolder)
|
||||
.withProp(p -> ofNullable(p.getPartnerRel())
|
||||
.map(HsOfficeRelationEntity::getHolder)
|
||||
.map(HsOfficePersonEntity::toShortString)
|
||||
.orElse(null))
|
||||
.withProp(p -> ofNullable(p.getPartnerRole())
|
||||
.map(HsOfficeRelationshipEntity::getContact)
|
||||
.withProp(p -> ofNullable(p.getPartnerRel())
|
||||
.map(HsOfficeRelationEntity::getContact)
|
||||
.map(HsOfficeContactEntity::toShortString)
|
||||
.orElse(null))
|
||||
.quotedValues(false);
|
||||
@ -69,8 +69,8 @@ public class HsOfficePartnerEntity implements Stringifyable, HasUuid {
|
||||
private Integer partnerNumber;
|
||||
|
||||
@ManyToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "partnerroleuuid", nullable = false)
|
||||
private HsOfficeRelationshipEntity partnerRole;
|
||||
@JoinColumn(name = "partnerReluuid", nullable = false)
|
||||
private HsOfficeRelationEntity partnerRel;
|
||||
|
||||
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH }, optional = true)
|
||||
@JoinColumn(name = "detailsuuid")
|
||||
@ -94,12 +94,12 @@ public class HsOfficePartnerEntity implements Stringifyable, HasUuid {
|
||||
public static RbacView rbac() {
|
||||
return rbacViewFor("partner", HsOfficePartnerEntity.class)
|
||||
.withIdentityView(SQL.projection("'P-' || partnerNumber"))
|
||||
.withUpdatableColumns("partnerRoleUuid")
|
||||
.toRole("global", ADMIN).grantPermission(INSERT) // FIXME: global -> partnerRel.relAnchor?
|
||||
.withUpdatableColumns("partnerRelUuid")
|
||||
.toRole("global", ADMIN).grantPermission(INSERT) // FIXME: global -> partnerRel.anchor?
|
||||
|
||||
.importRootEntityAliasProxy("partnerRel", HsOfficeRelationshipEntity.class,
|
||||
fetchedBySql("SELECT * FROM hs_office_relationship AS r WHERE r.uuid = ${ref}.partnerRoleUuid"),
|
||||
dependsOnColumn("partnerRoleUuid"))
|
||||
.importRootEntityAliasProxy("partnerRel", HsOfficeRelationEntity.class,
|
||||
fetchedBySql("SELECT * FROM hs_office_relation AS r WHERE r.uuid = ${ref}.partnerRelUuid"),
|
||||
dependsOnColumn("partnerRelUuid"))
|
||||
.createPermission(DELETE).grantedTo("partnerRel", ADMIN)
|
||||
.createPermission(UPDATE).grantedTo("partnerRel", AGENT)
|
||||
.createPermission(SELECT).grantedTo("partnerRel", TENANT)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.office.partner;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.mapper.EntityPatcher;
|
||||
import net.hostsharing.hsadminng.mapper.OptionalFromJson;
|
||||
|
||||
@ -19,9 +19,9 @@ class HsOfficePartnerEntityPatcher implements EntityPatcher<HsOfficePartnerPatch
|
||||
|
||||
@Override
|
||||
public void apply(final HsOfficePartnerPatchResource resource) {
|
||||
OptionalFromJson.of(resource.getPartnerRoleUuid()).ifPresent(newValue -> {
|
||||
verifyNotNull(newValue, "partnerRole");
|
||||
entity.setPartnerRole(em.getReference(HsOfficeRelationshipEntity.class, newValue));
|
||||
OptionalFromJson.of(resource.getPartnerRelUuid()).ifPresent(newValue -> {
|
||||
verifyNotNull(newValue, "partnerRel");
|
||||
entity.setPartnerRel(em.getReference(HsOfficeRelationEntity.class, newValue));
|
||||
});
|
||||
|
||||
new HsOfficePartnerDetailsEntityPatcher(em, entity.getDetails()).apply(resource.getDetails());
|
||||
|
@ -15,9 +15,9 @@ public interface HsOfficePartnerRepository extends Repository<HsOfficePartnerEnt
|
||||
|
||||
@Query("""
|
||||
SELECT partner FROM HsOfficePartnerEntity partner
|
||||
JOIN HsOfficeRelationshipEntity rel ON rel.uuid = partner.partnerRole.uuid
|
||||
JOIN HsOfficeRelationEntity rel ON rel.uuid = partner.partnerRel.uuid
|
||||
JOIN HsOfficeContactEntity contact ON contact.uuid = rel.contact.uuid
|
||||
JOIN HsOfficePersonEntity person ON person.uuid = rel.relHolder.uuid
|
||||
JOIN HsOfficePersonEntity person ON person.uuid = rel.holder.uuid
|
||||
WHERE :name is null
|
||||
OR partner.details.birthName like concat(cast(:name as text), '%')
|
||||
OR contact.label like concat(cast(:name as text), '%')
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.hostsharing.hsadminng.hs.office.relationship;
|
||||
package net.hostsharing.hsadminng.hs.office.relation;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
@ -24,49 +24,49 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor;
|
||||
import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
|
||||
@Entity
|
||||
@Table(name = "hs_office_relationship_rv")
|
||||
@Table(name = "hs_office_relation_rv")
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@FieldNameConstants
|
||||
public class HsOfficeRelationshipEntity implements HasUuid, Stringifyable {
|
||||
public class HsOfficeRelationEntity implements HasUuid, Stringifyable {
|
||||
|
||||
private static Stringify<HsOfficeRelationshipEntity> toString = stringify(HsOfficeRelationshipEntity.class, "rel")
|
||||
.withProp(Fields.relAnchor, HsOfficeRelationshipEntity::getRelAnchor)
|
||||
.withProp(Fields.relType, HsOfficeRelationshipEntity::getRelType)
|
||||
.withProp(Fields.relMark, HsOfficeRelationshipEntity::getRelMark)
|
||||
.withProp(Fields.relHolder, HsOfficeRelationshipEntity::getRelHolder)
|
||||
.withProp(Fields.contact, HsOfficeRelationshipEntity::getContact);
|
||||
private static Stringify<HsOfficeRelationEntity> toString = stringify(HsOfficeRelationEntity.class, "rel")
|
||||
.withProp(Fields.anchor, HsOfficeRelationEntity::getAnchor)
|
||||
.withProp(Fields.type, HsOfficeRelationEntity::getType)
|
||||
.withProp(Fields.mark, HsOfficeRelationEntity::getMark)
|
||||
.withProp(Fields.holder, HsOfficeRelationEntity::getHolder)
|
||||
.withProp(Fields.contact, HsOfficeRelationEntity::getContact);
|
||||
|
||||
private static Stringify<HsOfficeRelationshipEntity> toShortString = stringify(HsOfficeRelationshipEntity.class, "rel")
|
||||
.withProp(Fields.relAnchor, HsOfficeRelationshipEntity::getRelAnchor)
|
||||
.withProp(Fields.relType, HsOfficeRelationshipEntity::getRelType)
|
||||
.withProp(Fields.relHolder, HsOfficeRelationshipEntity::getRelHolder);
|
||||
private static Stringify<HsOfficeRelationEntity> toShortString = stringify(HsOfficeRelationEntity.class, "rel")
|
||||
.withProp(Fields.anchor, HsOfficeRelationEntity::getAnchor)
|
||||
.withProp(Fields.type, HsOfficeRelationEntity::getType)
|
||||
.withProp(Fields.holder, HsOfficeRelationEntity::getHolder);
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private UUID uuid;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "relanchoruuid")
|
||||
private HsOfficePersonEntity relAnchor;
|
||||
@JoinColumn(name = "anchoruuid")
|
||||
private HsOfficePersonEntity anchor;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "relholderuuid")
|
||||
private HsOfficePersonEntity relHolder;
|
||||
@JoinColumn(name = "holderuuid")
|
||||
private HsOfficePersonEntity holder;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "contactuuid")
|
||||
private HsOfficeContactEntity contact;
|
||||
|
||||
@Column(name = "reltype")
|
||||
@Column(name = "type")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private HsOfficeRelationshipType relType;
|
||||
private HsOfficeRelationType type;
|
||||
|
||||
@Column(name = "relmark")
|
||||
private String relMark;
|
||||
@Column(name = "mark")
|
||||
private String mark;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@ -79,22 +79,22 @@ public class HsOfficeRelationshipEntity implements HasUuid, Stringifyable {
|
||||
}
|
||||
|
||||
public static RbacView rbac() {
|
||||
return rbacViewFor("relationship", HsOfficeRelationshipEntity.class)
|
||||
return rbacViewFor("relation", HsOfficeRelationEntity.class)
|
||||
.withIdentityView(SQL.projection("""
|
||||
(select idName from hs_office_person_iv p where p.uuid = relAnchorUuid)
|
||||
|| '-with-' || target.relType || '-'
|
||||
|| (select idName from hs_office_person_iv p where p.uuid = relHolderUuid)
|
||||
(select idName from hs_office_person_iv p where p.uuid = anchorUuid)
|
||||
|| '-with-' || target.type || '-'
|
||||
|| (select idName from hs_office_person_iv p where p.uuid = holderUuid)
|
||||
"""))
|
||||
.withRestrictedViewOrderBy(SQL.expression(
|
||||
"(select idName from hs_office_person_iv p where p.uuid = target.relHolderUuid)"))
|
||||
"(select idName from hs_office_person_iv p where p.uuid = target.holderUuid)"))
|
||||
.withUpdatableColumns("contactUuid")
|
||||
.importEntityAlias("anchorPerson", HsOfficePersonEntity.class,
|
||||
dependsOnColumn("relAnchorUuid"),
|
||||
fetchedBySql("select * from hs_office_person as p where p.uuid = ${REF}.relAnchorUuid")
|
||||
dependsOnColumn("anchorUuid"),
|
||||
fetchedBySql("select * from hs_office_person as p where p.uuid = ${REF}.anchorUuid")
|
||||
)
|
||||
.importEntityAlias("holderPerson", HsOfficePersonEntity.class,
|
||||
dependsOnColumn("relHolderUuid"),
|
||||
fetchedBySql("select * from hs_office_person as p where p.uuid = ${REF}.relHolderUuid")
|
||||
dependsOnColumn("holderUuid"),
|
||||
fetchedBySql("select * from hs_office_person as p where p.uuid = ${REF}.holderUuid")
|
||||
)
|
||||
.importEntityAlias("contact", HsOfficeContactEntity.class,
|
||||
dependsOnColumn("contactUuid"),
|
||||
@ -129,6 +129,6 @@ public class HsOfficeRelationshipEntity implements HasUuid, Stringifyable {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
rbac().generateWithBaseFileName("223-hs-office-relationship-rbac");
|
||||
rbac().generateWithBaseFileName("223-hs-office-relation-rbac");
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import lombok.*;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.persistence.HasUuid;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
import net.hostsharing.hsadminng.stringify.Stringify;
|
||||
@ -103,11 +103,11 @@ public class HsOfficeSepaMandateEntity implements Stringifyable, HasUuid {
|
||||
.withRestrictedViewOrderBy(expression("validity"))
|
||||
.withUpdatableColumns("reference", "agreement", "validity")
|
||||
|
||||
.importEntityAlias("debitorRel", HsOfficeRelationshipEntity.class,
|
||||
.importEntityAlias("debitorRel", HsOfficeRelationEntity.class,
|
||||
dependsOnColumn("debitorUuid"),
|
||||
fetchedBySql("""
|
||||
SELECT debitorRel.*
|
||||
FROM hs_office_relationship debitorRel
|
||||
FROM hs_office_relation debitorRel
|
||||
JOIN hs_office_debitor debitor ON debitor.debitorRelUuid = debitorRel.uuid
|
||||
WHERE debitor.uuid = ${REF}.debitorUuid
|
||||
""")
|
||||
|
@ -10,7 +10,7 @@ components:
|
||||
type: string
|
||||
format: uuid
|
||||
debitorRel:
|
||||
$ref: './hs-office-relationship-schemas.yaml#/components/schemas/HsOfficeRelationship'
|
||||
$ref: './hs-office-relation-schemas.yaml#/components/schemas/HsOfficeRelation'
|
||||
debitorNumber:
|
||||
type: integer
|
||||
format: int32
|
||||
@ -76,7 +76,7 @@ components:
|
||||
type: object
|
||||
properties:
|
||||
debitorRel:
|
||||
$ref: './hs-office-relationship-schemas.yaml#/components/schemas/HsOfficeRelationshipInsert'
|
||||
$ref: './hs-office-relation-schemas.yaml#/components/schemas/HsOfficeRelationInsert'
|
||||
debitorRelUuid:
|
||||
type: string
|
||||
format: uuid
|
||||
|
@ -14,8 +14,8 @@ components:
|
||||
format: int8
|
||||
minimum: 10000
|
||||
maximum: 99999
|
||||
partnerRole:
|
||||
$ref: './hs-office-relationship-schemas.yaml#/components/schemas/HsOfficeRelationship'
|
||||
partnerRel:
|
||||
$ref: './hs-office-relation-schemas.yaml#/components/schemas/HsOfficeRelation'
|
||||
details:
|
||||
$ref: '#/components/schemas/HsOfficePartnerDetails'
|
||||
|
||||
@ -50,7 +50,7 @@ components:
|
||||
HsOfficePartnerPatch:
|
||||
type: object
|
||||
properties:
|
||||
partnerRoleUuid:
|
||||
partnerRelUuid:
|
||||
type: string
|
||||
format: uuid
|
||||
nullable: true
|
||||
@ -90,31 +90,31 @@ components:
|
||||
format: int8
|
||||
minimum: 10000
|
||||
maximum: 99999
|
||||
partnerRole:
|
||||
$ref: '#/components/schemas/HsOfficePartnerRoleInsert'
|
||||
partnerRel:
|
||||
$ref: '#/components/schemas/HsOfficePartnerRelInsert'
|
||||
details:
|
||||
$ref: '#/components/schemas/HsOfficePartnerDetailsInsert'
|
||||
required:
|
||||
- partnerNumber
|
||||
- partnerRole
|
||||
- partnerRel
|
||||
- details
|
||||
|
||||
HsOfficePartnerRoleInsert:
|
||||
HsOfficePartnerRelInsert:
|
||||
type: object
|
||||
nullable: false
|
||||
properties:
|
||||
relAnchorUuid:
|
||||
anchorUuid:
|
||||
type: string
|
||||
format: uuid
|
||||
relHolderUuid:
|
||||
holderUuid:
|
||||
type: string
|
||||
format: uuid
|
||||
contactUuid:
|
||||
type: string
|
||||
format: uuid
|
||||
required:
|
||||
- relAnchorUuid
|
||||
- relHolderUuid
|
||||
- anchorUuid
|
||||
- holderUuid
|
||||
- relContactUuid
|
||||
|
||||
HsOfficePartnerDetailsInsert:
|
||||
|
@ -1,5 +1,6 @@
|
||||
--liquibase formatted sql
|
||||
-- This code generated was by RbacViewPostgresGenerator at 2024-03-11T11:29:11.625353859.
|
||||
-- This code generated was by RbacViewPostgresGenerator at 2024-03-22T12:01:44.554331877.
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset test-package-rbac-OBJECT:1 endDelimiter:--//
|
||||
@ -33,9 +34,12 @@ declare
|
||||
|
||||
begin
|
||||
call enterTriggerForObjectUuid(NEW.uuid);
|
||||
|
||||
SELECT * FROM test_customer c
|
||||
WHERE c.uuid= NEW.customerUuid
|
||||
into newCustomer;
|
||||
INTO newCustomer;
|
||||
assert newCustomer.uuid is not null, format('newCustomer must not be null for NEW.customerUuid = %s', NEW.customerUuid);
|
||||
|
||||
|
||||
perform createRoleWithGrants(
|
||||
testPackageOwner(NEW),
|
||||
@ -75,9 +79,9 @@ create trigger insertTriggerForTestPackage_tg
|
||||
after insert on test_package
|
||||
for each row
|
||||
execute procedure insertTriggerForTestPackage_tf();
|
||||
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset test-package-rbac-update-trigger:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
@ -101,14 +105,18 @@ begin
|
||||
|
||||
SELECT * FROM test_customer c
|
||||
WHERE c.uuid= OLD.customerUuid
|
||||
into oldCustomer;
|
||||
INTO oldCustomer;
|
||||
assert oldCustomer.uuid is not null, format('oldCustomer must not be null for OLD.customerUuid = %s', OLD.customerUuid);
|
||||
|
||||
SELECT * FROM test_customer c
|
||||
WHERE c.uuid= NEW.customerUuid
|
||||
into newCustomer;
|
||||
INTO newCustomer;
|
||||
assert newCustomer.uuid is not null, format('newCustomer must not be null for NEW.customerUuid = %s', NEW.customerUuid);
|
||||
|
||||
|
||||
if NEW.customerUuid <> OLD.customerUuid then
|
||||
|
||||
call revokePermissionFromRole(findPermissionId(OLD.uuid, 'INSERT'), testCustomerAdmin(oldCustomer));
|
||||
call revokePermissionFromRole(getPermissionId(OLD.uuid, 'INSERT'), testCustomerAdmin(oldCustomer));
|
||||
|
||||
call revokeRoleFromRole(testPackageOwner(OLD), testCustomerAdmin(oldCustomer));
|
||||
call grantRoleToRole(testPackageOwner(NEW), testCustomerAdmin(newCustomer));
|
||||
@ -138,9 +146,9 @@ create trigger updateTriggerForTestPackage_tg
|
||||
after update on test_package
|
||||
for each row
|
||||
execute procedure updateTriggerForTestPackage_tf();
|
||||
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset test-package-rbac-INSERT:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
@ -179,29 +187,43 @@ 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_test_package_test_customer_insert_tg
|
||||
after insert on test_customer
|
||||
for each row
|
||||
execute procedure test_package_test_customer_insert_tf();
|
||||
|
||||
/**
|
||||
Checks if the user or assumed roles are allowed to insert a row to test_package.
|
||||
Checks if the user or assumed roles are allowed to insert a row to test_package,
|
||||
where the check is performed by an indirect role.
|
||||
|
||||
An indirect role is a role FIXME.
|
||||
*/
|
||||
create or replace function test_package_insert_permission_missing_tf()
|
||||
returns trigger
|
||||
language plpgsql as $$
|
||||
begin
|
||||
raise exception '[403] insert into test_package not allowed for current subjects % (%)',
|
||||
currentSubjects(), currentSubjectsUuids();
|
||||
if ( not hasInsertPermission(
|
||||
( SELECT customer.uuid FROM
|
||||
|
||||
(SELECT * FROM test_customer c
|
||||
WHERE c.uuid= NEW.customerUuid
|
||||
) AS customer
|
||||
|
||||
), 'INSERT', 'test_package') ) then
|
||||
raise exception
|
||||
'[403] insert into test_package not allowed for current subjects % (%)',
|
||||
currentSubjects(), currentSubjectsUuids();
|
||||
end if;
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger test_package_insert_permission_check_tg
|
||||
before insert on test_package
|
||||
for each row
|
||||
when ( not hasInsertPermission(NEW.customerUuid, 'INSERT', 'test_package') )
|
||||
execute procedure test_package_insert_permission_missing_tf();
|
||||
|
||||
--//
|
||||
|
||||
-- ============================================================================
|
||||
--changeset test-package-rbac-IDENTITY-VIEW:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
@ -209,13 +231,15 @@ create trigger test_package_insert_permission_check_tg
|
||||
call generateRbacIdentityViewFromProjection('test_package', $idName$
|
||||
name
|
||||
$idName$);
|
||||
|
||||
--//
|
||||
|
||||
-- ============================================================================
|
||||
--changeset test-package-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call generateRbacRestrictedView('test_package',
|
||||
'name',
|
||||
$orderBy$
|
||||
name
|
||||
$orderBy$,
|
||||
$updates$
|
||||
version = new.version,
|
||||
customerUuid = new.customerUuid,
|
||||
@ -223,4 +247,3 @@ call generateRbacRestrictedView('test_package',
|
||||
$updates$);
|
||||
--//
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
### rbac relationship
|
||||
### rbac relation
|
||||
|
||||
This code generated was by RbacViewMermaidFlowchartGenerator at 2024-03-15T17:17:00.854621634.
|
||||
|
||||
@ -45,31 +45,31 @@ subgraph contact["`**contact**`"]
|
||||
end
|
||||
end
|
||||
|
||||
subgraph relationship["`**relationship**`"]
|
||||
subgraph relation["`**relation**`"]
|
||||
direction TB
|
||||
style relationship fill:#dd4901,stroke:#274d6e,stroke-width:8px
|
||||
style relation fill:#dd4901,stroke:#274d6e,stroke-width:8px
|
||||
|
||||
subgraph relationship:roles[ ]
|
||||
style relationship:roles fill:#dd4901,stroke:white
|
||||
subgraph relation:roles[ ]
|
||||
style relation:roles fill:#dd4901,stroke:white
|
||||
|
||||
role:relationship:owner[[relationship:owner]]
|
||||
role:relationship:admin[[relationship:admin]]
|
||||
role:relationship:agent[[relationship:agent]]
|
||||
role:relationship:tenant[[relationship:tenant]]
|
||||
role:relation:owner[[relation:owner]]
|
||||
role:relation:admin[[relation:admin]]
|
||||
role:relation:agent[[relation:agent]]
|
||||
role:relation:tenant[[relation:tenant]]
|
||||
end
|
||||
|
||||
subgraph relationship:permissions[ ]
|
||||
style relationship:permissions fill:#dd4901,stroke:white
|
||||
subgraph relation:permissions[ ]
|
||||
style relation:permissions fill:#dd4901,stroke:white
|
||||
|
||||
perm:relationship:DELETE{{relationship:DELETE}}
|
||||
perm:relationship:UPDATE{{relationship:UPDATE}}
|
||||
perm:relationship:SELECT{{relationship:SELECT}}
|
||||
perm:relationship:INSERT{{relationship:INSERT}}
|
||||
perm:relation:DELETE{{relation:DELETE}}
|
||||
perm:relation:UPDATE{{relation:UPDATE}}
|
||||
perm:relation:SELECT{{relation:SELECT}}
|
||||
perm:relation:INSERT{{relation:INSERT}}
|
||||
end
|
||||
end
|
||||
|
||||
%% granting roles to users
|
||||
user:creator ==> role:relationship:owner
|
||||
user:creator ==> role:relation:owner
|
||||
|
||||
%% granting roles to roles
|
||||
role:global:admin -.-> role:anchorPerson:owner
|
||||
@ -81,22 +81,22 @@ role:holderPerson:admin -.-> role:holderPerson:referrer
|
||||
role:global:admin -.-> role:contact:owner
|
||||
role:contact:owner -.-> role:contact:admin
|
||||
role:contact:admin -.-> role:contact:referrer
|
||||
role:global:admin ==> role:relationship:owner
|
||||
role:relationship:owner ==> role:relationship:admin
|
||||
role:anchorPerson:admin ==> role:relationship:admin
|
||||
role:relationship:admin ==> role:relationship:agent
|
||||
role:holderPerson:admin ==> role:relationship:agent
|
||||
role:relationship:agent ==> role:relationship:tenant
|
||||
role:holderPerson:admin ==> role:relationship:tenant
|
||||
role:contact:admin ==> role:relationship:tenant
|
||||
role:relationship:tenant ==> role:anchorPerson:referrer
|
||||
role:relationship:tenant ==> role:holderPerson:referrer
|
||||
role:relationship:tenant ==> role:contact:referrer
|
||||
role:global:admin ==> role:relation:owner
|
||||
role:relation:owner ==> role:relation:admin
|
||||
role:anchorPerson:admin ==> role:relation:admin
|
||||
role:relation:admin ==> role:relation:agent
|
||||
role:holderPerson:admin ==> role:relation:agent
|
||||
role:relation:agent ==> role:relation:tenant
|
||||
role:holderPerson:admin ==> role:relation:tenant
|
||||
role:contact:admin ==> role:relation:tenant
|
||||
role:relation:tenant ==> role:anchorPerson:referrer
|
||||
role:relation:tenant ==> role:holderPerson:referrer
|
||||
role:relation:tenant ==> role:contact:referrer
|
||||
|
||||
%% granting permissions to roles
|
||||
role:relationship:owner ==> perm:relationship:DELETE
|
||||
role:relationship:admin ==> perm:relationship:UPDATE
|
||||
role:relationship:tenant ==> perm:relationship:SELECT
|
||||
role:anchorPerson:admin ==> perm:relationship:INSERT
|
||||
role:relation:owner ==> perm:relation:DELETE
|
||||
role:relation:admin ==> perm:relation:UPDATE
|
||||
role:relation:tenant ==> perm:relation:SELECT
|
||||
role:anchorPerson:admin ==> perm:relation:INSERT
|
||||
|
||||
```
|
||||
|
@ -3,29 +3,29 @@
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-office-relationship-rbac-OBJECT:1 endDelimiter:--//
|
||||
--changeset hs-office-relation-rbac-OBJECT:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call generateRelatedRbacObject('hs_office_relationship');
|
||||
call generateRelatedRbacObject('hs_office_relation');
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-office-relationship-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--//
|
||||
--changeset hs-office-relation-rbac-ROLE-DESCRIPTORS:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call generateRbacRoleDescriptors('hsOfficeRelationship', 'hs_office_relationship');
|
||||
call generateRbacRoleDescriptors('hsOfficeRelation', 'hs_office_relation');
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-office-relationship-rbac-insert-trigger:1 endDelimiter:--//
|
||||
--changeset hs-office-relation-rbac-insert-trigger:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Creates the roles, grants and permission for the AFTER INSERT TRIGGER.
|
||||
*/
|
||||
|
||||
create or replace procedure buildRbacSystemForHsOfficeRelationship(
|
||||
NEW hs_office_relationship
|
||||
create or replace procedure buildRbacSystemForHsOfficeRelation(
|
||||
NEW hs_office_relation
|
||||
)
|
||||
language plpgsql as $$
|
||||
|
||||
@ -37,43 +37,43 @@ declare
|
||||
begin
|
||||
call enterTriggerForObjectUuid(NEW.uuid);
|
||||
|
||||
select * from hs_office_person as p where p.uuid = NEW.relHolderUuid INTO newHolderPerson;
|
||||
assert newHolderPerson.uuid is not null, format('newHolderPerson must not be null for NEW.relHolderUuid = %s', NEW.relHolderUuid);
|
||||
select * from hs_office_person as p where p.uuid = NEW.holderUuid INTO newHolderPerson;
|
||||
assert newHolderPerson.uuid is not null, format('newHolderPerson must not be null for NEW.holderUuid = %s', NEW.holderUuid);
|
||||
|
||||
select * from hs_office_person as p where p.uuid = NEW.relAnchorUuid INTO newAnchorPerson;
|
||||
assert newAnchorPerson.uuid is not null, format('newAnchorPerson must not be null for NEW.relAnchorUuid = %s', NEW.relAnchorUuid);
|
||||
select * from hs_office_person as p where p.uuid = NEW.anchorUuid INTO newAnchorPerson;
|
||||
assert newAnchorPerson.uuid is not null, format('newAnchorPerson must not be null for NEW.anchorUuid = %s', NEW.anchorUuid);
|
||||
|
||||
select * from hs_office_contact as c where c.uuid = NEW.contactUuid INTO newContact;
|
||||
assert newContact.uuid is not null, format('newContact must not be null for NEW.contactUuid = %s', NEW.contactUuid);
|
||||
|
||||
|
||||
perform createRoleWithGrants(
|
||||
hsOfficeRelationshipOwner(NEW),
|
||||
hsOfficeRelationOwner(NEW),
|
||||
permissions => array['DELETE'],
|
||||
incomingSuperRoles => array[globalAdmin()],
|
||||
userUuids => array[currentUserUuid()]
|
||||
);
|
||||
|
||||
perform createRoleWithGrants(
|
||||
hsOfficeRelationshipAdmin(NEW),
|
||||
hsOfficeRelationAdmin(NEW),
|
||||
permissions => array['UPDATE'],
|
||||
incomingSuperRoles => array[
|
||||
hsOfficeRelationshipOwner(NEW),
|
||||
hsOfficeRelationOwner(NEW),
|
||||
hsOfficePersonAdmin(newAnchorPerson)]
|
||||
);
|
||||
|
||||
perform createRoleWithGrants(
|
||||
hsOfficeRelationshipAgent(NEW),
|
||||
hsOfficeRelationAgent(NEW),
|
||||
incomingSuperRoles => array[
|
||||
hsOfficePersonAdmin(newHolderPerson),
|
||||
hsOfficeRelationshipAdmin(NEW)]
|
||||
hsOfficeRelationAdmin(NEW)]
|
||||
);
|
||||
|
||||
perform createRoleWithGrants(
|
||||
hsOfficeRelationshipTenant(NEW),
|
||||
hsOfficeRelationTenant(NEW),
|
||||
permissions => array['SELECT'],
|
||||
incomingSuperRoles => array[
|
||||
hsOfficeRelationshipAgent(NEW),
|
||||
hsOfficeRelationAgent(NEW),
|
||||
hsOfficeContactAdmin(newContact),
|
||||
hsOfficePersonAdmin(newHolderPerson)],
|
||||
outgoingSubRoles => array[
|
||||
@ -86,36 +86,36 @@ begin
|
||||
end; $$;
|
||||
|
||||
/*
|
||||
AFTER INSERT TRIGGER to create the role+grant structure for a new hs_office_relationship row.
|
||||
AFTER INSERT TRIGGER to create the role+grant structure for a new hs_office_relation row.
|
||||
*/
|
||||
|
||||
create or replace function insertTriggerForHsOfficeRelationship_tf()
|
||||
create or replace function insertTriggerForHsOfficeRelation_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
begin
|
||||
call buildRbacSystemForHsOfficeRelationship(NEW);
|
||||
call buildRbacSystemForHsOfficeRelation(NEW);
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger insertTriggerForHsOfficeRelationship_tg
|
||||
after insert on hs_office_relationship
|
||||
create trigger insertTriggerForHsOfficeRelation_tg
|
||||
after insert on hs_office_relation
|
||||
for each row
|
||||
execute procedure insertTriggerForHsOfficeRelationship_tf();
|
||||
execute procedure insertTriggerForHsOfficeRelation_tf();
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-office-relationship-rbac-update-trigger:1 endDelimiter:--//
|
||||
--changeset hs-office-relation-rbac-update-trigger:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Called from the AFTER UPDATE TRIGGER to re-wire the grants.
|
||||
*/
|
||||
|
||||
create or replace procedure updateRbacRulesForHsOfficeRelationship(
|
||||
OLD hs_office_relationship,
|
||||
NEW hs_office_relationship
|
||||
create or replace procedure updateRbacRulesForHsOfficeRelation(
|
||||
OLD hs_office_relation,
|
||||
NEW hs_office_relation
|
||||
)
|
||||
language plpgsql as $$
|
||||
|
||||
@ -130,17 +130,17 @@ declare
|
||||
begin
|
||||
call enterTriggerForObjectUuid(NEW.uuid);
|
||||
|
||||
select * from hs_office_person as p where p.uuid = OLD.relHolderUuid INTO oldHolderPerson;
|
||||
assert oldHolderPerson.uuid is not null, format('oldHolderPerson must not be null for OLD.relHolderUuid = %s', OLD.relHolderUuid);
|
||||
select * from hs_office_person as p where p.uuid = OLD.holderUuid INTO oldHolderPerson;
|
||||
assert oldHolderPerson.uuid is not null, format('oldHolderPerson must not be null for OLD.holderUuid = %s', OLD.holderUuid);
|
||||
|
||||
select * from hs_office_person as p where p.uuid = NEW.relHolderUuid INTO newHolderPerson;
|
||||
assert newHolderPerson.uuid is not null, format('newHolderPerson must not be null for NEW.relHolderUuid = %s', NEW.relHolderUuid);
|
||||
select * from hs_office_person as p where p.uuid = NEW.holderUuid INTO newHolderPerson;
|
||||
assert newHolderPerson.uuid is not null, format('newHolderPerson must not be null for NEW.holderUuid = %s', NEW.holderUuid);
|
||||
|
||||
select * from hs_office_person as p where p.uuid = OLD.relAnchorUuid INTO oldAnchorPerson;
|
||||
assert oldAnchorPerson.uuid is not null, format('oldAnchorPerson must not be null for OLD.relAnchorUuid = %s', OLD.relAnchorUuid);
|
||||
select * from hs_office_person as p where p.uuid = OLD.anchorUuid INTO oldAnchorPerson;
|
||||
assert oldAnchorPerson.uuid is not null, format('oldAnchorPerson must not be null for OLD.anchorUuid = %s', OLD.anchorUuid);
|
||||
|
||||
select * from hs_office_person as p where p.uuid = NEW.relAnchorUuid INTO newAnchorPerson;
|
||||
assert newAnchorPerson.uuid is not null, format('newAnchorPerson must not be null for NEW.relAnchorUuid = %s', NEW.relAnchorUuid);
|
||||
select * from hs_office_person as p where p.uuid = NEW.anchorUuid INTO newAnchorPerson;
|
||||
assert newAnchorPerson.uuid is not null, format('newAnchorPerson must not be null for NEW.anchorUuid = %s', NEW.anchorUuid);
|
||||
|
||||
select * from hs_office_contact as c where c.uuid = OLD.contactUuid INTO oldContact;
|
||||
assert oldContact.uuid is not null, format('oldContact must not be null for OLD.contactUuid = %s', OLD.contactUuid);
|
||||
@ -151,11 +151,11 @@ begin
|
||||
|
||||
if NEW.contactUuid <> OLD.contactUuid then
|
||||
|
||||
call revokeRoleFromRole(hsOfficeRelationshipTenant(OLD), hsOfficeContactAdmin(oldContact));
|
||||
call grantRoleToRole(hsOfficeRelationshipTenant(NEW), hsOfficeContactAdmin(newContact));
|
||||
call revokeRoleFromRole(hsOfficeRelationTenant(OLD), hsOfficeContactAdmin(oldContact));
|
||||
call grantRoleToRole(hsOfficeRelationTenant(NEW), hsOfficeContactAdmin(newContact));
|
||||
|
||||
call revokeRoleFromRole(hsOfficeContactReferrer(oldContact), hsOfficeRelationshipTenant(OLD));
|
||||
call grantRoleToRole(hsOfficeContactReferrer(newContact), hsOfficeRelationshipTenant(NEW));
|
||||
call revokeRoleFromRole(hsOfficeContactReferrer(oldContact), hsOfficeRelationTenant(OLD));
|
||||
call grantRoleToRole(hsOfficeContactReferrer(newContact), hsOfficeRelationTenant(NEW));
|
||||
|
||||
end if;
|
||||
|
||||
@ -163,31 +163,31 @@ begin
|
||||
end; $$;
|
||||
|
||||
/*
|
||||
AFTER INSERT TRIGGER to re-wire the grant structure for a new hs_office_relationship row.
|
||||
AFTER INSERT TRIGGER to re-wire the grant structure for a new hs_office_relation row.
|
||||
*/
|
||||
|
||||
create or replace function updateTriggerForHsOfficeRelationship_tf()
|
||||
create or replace function updateTriggerForHsOfficeRelation_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
begin
|
||||
call updateRbacRulesForHsOfficeRelationship(OLD, NEW);
|
||||
call updateRbacRulesForHsOfficeRelation(OLD, NEW);
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger updateTriggerForHsOfficeRelationship_tg
|
||||
after update on hs_office_relationship
|
||||
create trigger updateTriggerForHsOfficeRelation_tg
|
||||
after update on hs_office_relation
|
||||
for each row
|
||||
execute procedure updateTriggerForHsOfficeRelationship_tf();
|
||||
execute procedure updateTriggerForHsOfficeRelation_tf();
|
||||
--//
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-office-relationship-rbac-INSERT:1 endDelimiter:--//
|
||||
--changeset hs-office-relation-rbac-INSERT:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Creates INSERT INTO hs_office_relationship permissions for the related hs_office_person rows.
|
||||
Creates INSERT INTO hs_office_relation permissions for the related hs_office_person rows.
|
||||
*/
|
||||
do language plpgsql $$
|
||||
declare
|
||||
@ -195,80 +195,80 @@ do language plpgsql $$
|
||||
permissionUuid uuid;
|
||||
roleUuid uuid;
|
||||
begin
|
||||
call defineContext('create INSERT INTO hs_office_relationship permissions for the related hs_office_person rows');
|
||||
call defineContext('create INSERT INTO hs_office_relation permissions for the related hs_office_person rows');
|
||||
|
||||
FOR row IN SELECT * FROM hs_office_person
|
||||
LOOP
|
||||
roleUuid := findRoleId(hsOfficePersonAdmin(row));
|
||||
permissionUuid := createPermission(row.uuid, 'INSERT', 'hs_office_relationship');
|
||||
permissionUuid := createPermission(row.uuid, 'INSERT', 'hs_office_relation');
|
||||
call grantPermissionToRole(permissionUuid, roleUuid);
|
||||
END LOOP;
|
||||
END;
|
||||
$$;
|
||||
|
||||
/**
|
||||
Adds hs_office_relationship INSERT permission to specified role of new hs_office_person rows.
|
||||
Adds hs_office_relation INSERT permission to specified role of new hs_office_person rows.
|
||||
*/
|
||||
create or replace function hs_office_relationship_hs_office_person_insert_tf()
|
||||
create or replace function hs_office_relation_hs_office_person_insert_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
begin
|
||||
call grantPermissionToRole(
|
||||
createPermission(NEW.uuid, 'INSERT', 'hs_office_relationship'),
|
||||
createPermission(NEW.uuid, 'INSERT', 'hs_office_relation'),
|
||||
hsOfficePersonAdmin(NEW));
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger z_hs_office_relationship_hs_office_person_insert_tg
|
||||
create trigger z_hs_office_relation_hs_office_person_insert_tg
|
||||
after insert on hs_office_person
|
||||
for each row
|
||||
execute procedure hs_office_relationship_hs_office_person_insert_tf();
|
||||
execute procedure hs_office_relation_hs_office_person_insert_tf();
|
||||
|
||||
/**
|
||||
Checks if the user or assumed roles are allowed to insert a row to hs_office_relationship.
|
||||
Checks if the user or assumed roles are allowed to insert a row to hs_office_relation.
|
||||
*/
|
||||
create or replace function hs_office_relationship_insert_permission_missing_tf()
|
||||
create or replace function hs_office_relation_insert_permission_missing_tf()
|
||||
returns trigger
|
||||
language plpgsql as $$
|
||||
begin
|
||||
if ( not hasInsertPermission(
|
||||
( SELECT anchorPerson.uuid FROM
|
||||
|
||||
(select * from hs_office_person as p where p.uuid = NEW.relAnchorUuid) AS anchorPerson
|
||||
(select * from hs_office_person as p where p.uuid = NEW.anchorUuid) AS anchorPerson
|
||||
|
||||
), 'INSERT', 'hs_office_relationship') ) then
|
||||
), 'INSERT', 'hs_office_relation') ) then
|
||||
raise exception
|
||||
'[403] insert into hs_office_relationship not allowed for current subjects % (%)',
|
||||
'[403] insert into hs_office_relation not allowed for current subjects % (%)',
|
||||
currentSubjects(), currentSubjectsUuids();
|
||||
end if;
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
create trigger hs_office_relationship_insert_permission_check_tg
|
||||
before insert on hs_office_relationship
|
||||
create trigger hs_office_relation_insert_permission_check_tg
|
||||
before insert on hs_office_relation
|
||||
for each row
|
||||
execute procedure hs_office_relationship_insert_permission_missing_tf();
|
||||
execute procedure hs_office_relation_insert_permission_missing_tf();
|
||||
--//
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-office-relationship-rbac-IDENTITY-VIEW:1 endDelimiter:--//
|
||||
--changeset hs-office-relation-rbac-IDENTITY-VIEW:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
call generateRbacIdentityViewFromProjection('hs_office_relationship', $idName$
|
||||
(select idName from hs_office_person_iv p where p.uuid = relAnchorUuid)
|
||||
|| '-with-' || target.relType || '-'
|
||||
|| (select idName from hs_office_person_iv p where p.uuid = relHolderUuid)
|
||||
call generateRbacIdentityViewFromProjection('hs_office_relation', $idName$
|
||||
(select idName from hs_office_person_iv p where p.uuid = anchorUuid)
|
||||
|| '-with-' || target.type || '-'
|
||||
|| (select idName from hs_office_person_iv p where p.uuid = holderUuid)
|
||||
|
||||
$idName$);
|
||||
--//
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-office-relationship-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
|
||||
--changeset hs-office-relation-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call generateRbacRestrictedView('hs_office_relationship',
|
||||
call generateRbacRestrictedView('hs_office_relation',
|
||||
$orderBy$
|
||||
(select idName from hs_office_person_iv p where p.uuid = target.relHolderUuid)
|
||||
(select idName from hs_office_person_iv p where p.uuid = target.holderUuid)
|
||||
$orderBy$,
|
||||
$updates$
|
||||
contactUuid = new.contactUuid
|
||||
|
@ -2,15 +2,15 @@
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-office-relationship-TEST-DATA-GENERATOR:1 endDelimiter:--//
|
||||
--changeset hs-office-relation-TEST-DATA-GENERATOR:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Creates a single relationship test record.
|
||||
Creates a single relation test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficeRelationshipTestData(
|
||||
create or replace procedure createHsOfficeRelationTestData(
|
||||
holderPersonName varchar,
|
||||
relationshipType HsOfficeRelationshipType,
|
||||
relationType HsOfficeRelationType,
|
||||
anchorPersonName varchar,
|
||||
contactLabel varchar,
|
||||
mark varchar default null)
|
||||
@ -24,7 +24,7 @@ declare
|
||||
|
||||
begin
|
||||
idName := cleanIdentifier( anchorPersonName || '-' || holderPersonName);
|
||||
currentTask := 'creating relationship test-data ' || idName;
|
||||
currentTask := 'creating relation test-data ' || idName;
|
||||
call defineContext(currentTask, null, 'superuser-alex@hostsharing.net', 'global#global.admin');
|
||||
execute format('set local hsadminng.currentTask to %L', currentTask);
|
||||
|
||||
@ -49,20 +49,20 @@ begin
|
||||
raise exception 'contact "%" not found', contactLabel;
|
||||
end if;
|
||||
|
||||
raise notice 'creating test relationship: %', idName;
|
||||
raise notice 'creating test relation: %', idName;
|
||||
raise notice '- using anchor person (%): %', anchorPerson.uuid, anchorPerson;
|
||||
raise notice '- using holder person (%): %', holderPerson.uuid, holderPerson;
|
||||
raise notice '- using contact (%): %', contact.uuid, contact;
|
||||
insert
|
||||
into hs_office_relationship (uuid, relanchoruuid, relholderuuid, reltype, relmark, contactUuid)
|
||||
values (uuid_generate_v4(), anchorPerson.uuid, holderPerson.uuid, relationshipType, mark, contact.uuid);
|
||||
into hs_office_relation (uuid, anchoruuid, holderuuid, type, mark, contactUuid)
|
||||
values (uuid_generate_v4(), anchorPerson.uuid, holderPerson.uuid, relationType, mark, contact.uuid);
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
/*
|
||||
Creates a range of test relationship for mass data generation.
|
||||
Creates a range of test relation for mass data generation.
|
||||
*/
|
||||
create or replace procedure createHsOfficeRelationshipTestData(
|
||||
create or replace procedure createHsOfficeRelationTestData(
|
||||
startCount integer, -- count of auto generated rows before the run
|
||||
endCount integer -- count of auto generated rows after the run
|
||||
)
|
||||
@ -76,7 +76,7 @@ begin
|
||||
select p.* from hs_office_person p where tradeName = intToVarChar(t, 4) into person;
|
||||
select c.* from hs_office_contact c where c.label = intToVarChar(t, 4) || '#' || t into contact;
|
||||
|
||||
call createHsOfficeRelationshipTestData(person.uuid, contact.uuid, 'REPRESENTATIVE');
|
||||
call createHsOfficeRelationTestData(person.uuid, contact.uuid, 'REPRESENTATIVE');
|
||||
commit;
|
||||
end loop;
|
||||
end; $$;
|
||||
@ -84,30 +84,30 @@ end; $$;
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset hs-office-relationship-TEST-DATA-GENERATION:1 –context=dev,tc endDelimiter:--//
|
||||
--changeset hs-office-relation-TEST-DATA-GENERATION:1 –context=dev,tc endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
do language plpgsql $$
|
||||
begin
|
||||
call createHsOfficeRelationshipTestData('First GmbH', 'PARTNER', 'Hostsharing eG', 'first contact');
|
||||
call createHsOfficeRelationshipTestData('Firby', 'REPRESENTATIVE', 'First GmbH', 'first contact');
|
||||
call createHsOfficeRelationshipTestData('First GmbH', 'ACCOUNTING', 'First GmbH', 'first contact');
|
||||
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 createHsOfficeRelationshipTestData('Second e.K.', 'PARTNER', 'Hostsharing eG', 'second contact');
|
||||
call createHsOfficeRelationshipTestData('Smith', 'REPRESENTATIVE', 'Second e.K.', 'second contact');
|
||||
call createHsOfficeRelationshipTestData('Second e.K.', 'ACCOUNTING', 'Second e.K.', 'second 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 createHsOfficeRelationshipTestData('Third OHG', 'PARTNER', 'Hostsharing eG', 'third contact');
|
||||
call createHsOfficeRelationshipTestData('Tucker', 'REPRESENTATIVE', 'Third OHG', 'third contact');
|
||||
call createHsOfficeRelationshipTestData('Third OHG', 'ACCOUNTING', 'Third OHG', 'third 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 createHsOfficeRelationshipTestData('Fourth eG', 'PARTNER', 'Hostsharing eG', 'fourth contact');
|
||||
call createHsOfficeRelationshipTestData('Fouler', 'REPRESENTATIVE', 'Third OHG', 'third contact');
|
||||
call createHsOfficeRelationshipTestData('Third OHG', 'ACCOUNTING', '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 createHsOfficeRelationshipTestData('Smith', 'PARTNER', 'Hostsharing eG', 'sixth contact');
|
||||
call createHsOfficeRelationshipTestData('Smith', 'ACCOUNTING', 'Smith', 'third contact');
|
||||
call createHsOfficeRelationshipTestData('Smith', 'SUBSCRIBER', 'Third OHG', 'third contact', 'members-announce');
|
||||
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');
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@ -33,7 +33,7 @@ create table hs_office_partner
|
||||
(
|
||||
uuid uuid unique references RbacObject (uuid) initially deferred,
|
||||
partnerNumber numeric(5) unique not null,
|
||||
partnerRoleUuid uuid not null references hs_office_relationship(uuid), -- TODO: delete in after delete trigger
|
||||
partnerRelUuid uuid not null references hs_office_relation(uuid), -- TODO: delete in after delete trigger
|
||||
detailsUuid uuid not null references hs_office_partner_details(uuid) -- deleted in after delete trigger
|
||||
);
|
||||
--//
|
||||
|
@ -30,24 +30,24 @@ create or replace procedure buildRbacSystemForHsOfficePartner(
|
||||
language plpgsql as $$
|
||||
|
||||
declare
|
||||
newPartnerRel hs_office_relationship;
|
||||
newPartnerRel hs_office_relation;
|
||||
newPartnerDetails hs_office_partner_details;
|
||||
|
||||
begin
|
||||
call enterTriggerForObjectUuid(NEW.uuid);
|
||||
|
||||
SELECT * FROM hs_office_relationship AS r WHERE r.uuid = NEW.partnerRoleUuid INTO newPartnerRel;
|
||||
assert newPartnerRel.uuid is not null, format('newPartnerRel must not be null for NEW.partnerRoleUuid = %s', NEW.partnerRoleUuid);
|
||||
SELECT * FROM hs_office_relation AS r WHERE r.uuid = NEW.partnerRelUuid INTO newPartnerRel;
|
||||
assert newPartnerRel.uuid is not null, format('newPartnerRel must not be null for NEW.partnerRelUuid = %s', NEW.partnerRelUuid);
|
||||
|
||||
SELECT * FROM hs_office_partner_details AS d WHERE d.uuid = NEW.detailsUuid INTO newPartnerDetails;
|
||||
assert newPartnerDetails.uuid is not null, format('newPartnerDetails must not be null for NEW.detailsUuid = %s', NEW.detailsUuid);
|
||||
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'DELETE'), hsOfficeRelationshipAdmin(newPartnerRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'SELECT'), hsOfficeRelationshipTenant(newPartnerRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'UPDATE'), hsOfficeRelationshipAgent(newPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'DELETE'), hsOfficeRelationshipAdmin(newPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'SELECT'), hsOfficeRelationshipAgent(newPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'UPDATE'), hsOfficeRelationshipAgent(newPartnerRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'DELETE'), hsOfficeRelationAdmin(newPartnerRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'SELECT'), hsOfficeRelationTenant(newPartnerRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'UPDATE'), hsOfficeRelationAgent(newPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'DELETE'), hsOfficeRelationAdmin(newPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'SELECT'), hsOfficeRelationAgent(newPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'UPDATE'), hsOfficeRelationAgent(newPartnerRel));
|
||||
|
||||
call leaveTriggerForObjectUuid(NEW.uuid);
|
||||
end; $$;
|
||||
@ -87,19 +87,19 @@ create or replace procedure updateRbacRulesForHsOfficePartner(
|
||||
language plpgsql as $$
|
||||
|
||||
declare
|
||||
oldPartnerRel hs_office_relationship;
|
||||
newPartnerRel hs_office_relationship;
|
||||
oldPartnerRel hs_office_relation;
|
||||
newPartnerRel hs_office_relation;
|
||||
oldPartnerDetails hs_office_partner_details;
|
||||
newPartnerDetails hs_office_partner_details;
|
||||
|
||||
begin
|
||||
call enterTriggerForObjectUuid(NEW.uuid);
|
||||
|
||||
SELECT * FROM hs_office_relationship AS r WHERE r.uuid = OLD.partnerRoleUuid INTO oldPartnerRel;
|
||||
assert oldPartnerRel.uuid is not null, format('oldPartnerRel must not be null for OLD.partnerRoleUuid = %s', OLD.partnerRoleUuid);
|
||||
SELECT * FROM hs_office_relation AS r WHERE r.uuid = OLD.partnerRelUuid INTO oldPartnerRel;
|
||||
assert oldPartnerRel.uuid is not null, format('oldPartnerRel must not be null for OLD.partnerRelUuid = %s', OLD.partnerRelUuid);
|
||||
|
||||
SELECT * FROM hs_office_relationship AS r WHERE r.uuid = NEW.partnerRoleUuid INTO newPartnerRel;
|
||||
assert newPartnerRel.uuid is not null, format('newPartnerRel must not be null for NEW.partnerRoleUuid = %s', NEW.partnerRoleUuid);
|
||||
SELECT * FROM hs_office_relation AS r WHERE r.uuid = NEW.partnerRelUuid INTO newPartnerRel;
|
||||
assert newPartnerRel.uuid is not null, format('newPartnerRel must not be null for NEW.partnerRelUuid = %s', NEW.partnerRelUuid);
|
||||
|
||||
SELECT * FROM hs_office_partner_details AS d WHERE d.uuid = OLD.detailsUuid INTO oldPartnerDetails;
|
||||
assert oldPartnerDetails.uuid is not null, format('oldPartnerDetails must not be null for OLD.detailsUuid = %s', OLD.detailsUuid);
|
||||
@ -108,31 +108,31 @@ begin
|
||||
assert newPartnerDetails.uuid is not null, format('newPartnerDetails must not be null for NEW.detailsUuid = %s', NEW.detailsUuid);
|
||||
|
||||
|
||||
if NEW.partnerRoleUuid <> OLD.partnerRoleUuid then
|
||||
if NEW.partnerRelUuid <> OLD.partnerRelUuid then
|
||||
|
||||
call revokePermissionFromRole(getPermissionId(OLD.uuid, 'DELETE'), hsOfficeRelationshipAdmin(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'DELETE'), hsOfficeRelationshipAdmin(newPartnerRel));
|
||||
call revokePermissionFromRole(getPermissionId(OLD.uuid, 'DELETE'), hsOfficeRelationAdmin(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'DELETE'), hsOfficeRelationAdmin(newPartnerRel));
|
||||
|
||||
call revokePermissionFromRole(getPermissionId(OLD.uuid, 'UPDATE'), hsOfficeRelationshipAgent(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'UPDATE'), hsOfficeRelationshipAgent(newPartnerRel));
|
||||
call revokePermissionFromRole(getPermissionId(OLD.uuid, 'UPDATE'), hsOfficeRelationAgent(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'UPDATE'), hsOfficeRelationAgent(newPartnerRel));
|
||||
|
||||
call revokePermissionFromRole(getPermissionId(OLD.uuid, 'SELECT'), hsOfficeRelationshipTenant(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'SELECT'), hsOfficeRelationshipTenant(newPartnerRel));
|
||||
call revokePermissionFromRole(getPermissionId(OLD.uuid, 'SELECT'), hsOfficeRelationTenant(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'SELECT'), hsOfficeRelationTenant(newPartnerRel));
|
||||
|
||||
call revokePermissionFromRole(getPermissionId(oldPartnerDetails.uuid, 'DELETE'), hsOfficeRelationshipAdmin(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'DELETE'), hsOfficeRelationshipAdmin(newPartnerRel));
|
||||
call revokePermissionFromRole(getPermissionId(oldPartnerDetails.uuid, 'DELETE'), hsOfficeRelationAdmin(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'DELETE'), hsOfficeRelationAdmin(newPartnerRel));
|
||||
|
||||
call revokePermissionFromRole(getPermissionId(oldPartnerDetails.uuid, 'UPDATE'), hsOfficeRelationshipAgent(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'UPDATE'), hsOfficeRelationshipAgent(newPartnerRel));
|
||||
call revokePermissionFromRole(getPermissionId(oldPartnerDetails.uuid, 'UPDATE'), hsOfficeRelationAgent(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'UPDATE'), hsOfficeRelationAgent(newPartnerRel));
|
||||
|
||||
call revokePermissionFromRole(getPermissionId(oldPartnerDetails.uuid, 'SELECT'), hsOfficeRelationshipAgent(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'SELECT'), hsOfficeRelationshipAgent(newPartnerRel));
|
||||
call revokePermissionFromRole(getPermissionId(oldPartnerDetails.uuid, 'SELECT'), hsOfficeRelationAgent(oldPartnerRel));
|
||||
call grantPermissionToRole(createPermission(newPartnerDetails.uuid, 'SELECT'), hsOfficeRelationAgent(newPartnerRel));
|
||||
|
||||
end if;
|
||||
|
||||
call leaveTriggerForObjectUuid(NEW.uuid);
|
||||
|
||||
-- raise exception 'RBAC updated from rel % to %', OLD.partnerroleuuid, NEW.partnerroleuuid;
|
||||
-- raise exception 'RBAC updated from rel % to %', OLD.partnerReluuid, NEW.partnerReluuid;
|
||||
end; $$;
|
||||
|
||||
|
||||
@ -143,20 +143,20 @@ create or replace procedure updateRbacRulesForHsOfficePartnerX(
|
||||
)
|
||||
language plpgsql as $$
|
||||
declare
|
||||
partnerRel hs_office_relationship;
|
||||
partnerRel hs_office_relation;
|
||||
grantCount int;
|
||||
|
||||
begin
|
||||
assert OLD.uuid = NEW.uuid, 'uuid did change, but should not';
|
||||
assert OLD.partnerroleuuid <> NEW.partnerroleuuid, 'partnerroleuuid did not change, but should have';
|
||||
assert OLD.partnerReluuid <> NEW.partnerReluuid, 'partnerReluuid did not change, but should have';
|
||||
|
||||
delete from rbacgrants where grantedbytriggerof = OLD.uuid;
|
||||
select count(*) from rbacgrants where grantedbytriggerof=NEW.uuid into grantCount;
|
||||
assert grantCount=0, format('unexpected grantCount>0: %d', grantCount);
|
||||
|
||||
call buildRbacSystemForHsOfficePartner(NEW);
|
||||
select * from hs_office_relationship where uuid=NEW.partnerroleuuid into partnerRel;
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'SELECT'), hsOfficeRelationshipTenant(partnerRel));
|
||||
select * from hs_office_relation where uuid=NEW.partnerReluuid into partnerRel;
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'SELECT'), hsOfficeRelationTenant(partnerRel));
|
||||
select count(*) from rbacgrants where grantedbytriggerof=NEW.uuid into grantCount;
|
||||
assert grantCount>0, format('unexpected grantCount=0: %d', grantCount);
|
||||
raise warning 'WARNING grantCount=%', grantCount;
|
||||
@ -262,7 +262,7 @@ call generateRbacRestrictedView('hs_office_partner',
|
||||
'P-' || partnerNumber
|
||||
$orderBy$,
|
||||
$updates$
|
||||
partnerRoleUuid = new.partnerRoleUuid
|
||||
partnerRelUuid = new.partnerRelUuid
|
||||
$updates$);
|
||||
--//
|
||||
|
||||
|
@ -18,7 +18,7 @@ declare
|
||||
currentTask varchar;
|
||||
idName varchar;
|
||||
mandantPerson hs_office_person;
|
||||
partnerRole hs_office_relationship;
|
||||
partnerRel hs_office_relation;
|
||||
relatedPerson hs_office_person;
|
||||
relatedDetailsUuid uuid;
|
||||
begin
|
||||
@ -38,16 +38,16 @@ begin
|
||||
where p.tradeName = partnerPersonName or p.familyName = partnerPersonName
|
||||
into relatedPerson;
|
||||
|
||||
select r.* from hs_office_relationship r
|
||||
where r.reltype = 'PARTNER'
|
||||
and r.relanchoruuid = mandantPerson.uuid and r.relholderuuid = relatedPerson.uuid
|
||||
into partnerRole;
|
||||
if partnerRole is null then
|
||||
raise exception 'partnerRole "%"-"%" not found', mandantPerson.tradename, partnerPersonName;
|
||||
select r.* from hs_office_relation r
|
||||
where r.type = 'PARTNER'
|
||||
and r.anchoruuid = mandantPerson.uuid and r.holderuuid = relatedPerson.uuid
|
||||
into partnerRel;
|
||||
if partnerRel is null then
|
||||
raise exception 'partnerRel "%"-"%" not found', mandantPerson.tradename, partnerPersonName;
|
||||
end if;
|
||||
|
||||
raise notice 'creating test partner: %', idName;
|
||||
raise notice '- using partnerRole (%): %', partnerRole.uuid, partnerRole;
|
||||
raise notice '- using partnerRel (%): %', partnerRel.uuid, partnerRel;
|
||||
raise notice '- using person (%): %', relatedPerson.uuid, relatedPerson;
|
||||
|
||||
if relatedPerson.persontype = 'NP' then
|
||||
@ -63,8 +63,8 @@ begin
|
||||
end if;
|
||||
|
||||
insert
|
||||
into hs_office_partner (uuid, partnerNumber, partnerRoleUuid, detailsUuid)
|
||||
values (uuid_generate_v4(), newPartnerNumber, partnerRole.uuid, relatedDetailsUuid);
|
||||
into hs_office_partner (uuid, partnerNumber, partnerRelUuid, detailsUuid)
|
||||
values (uuid_generate_v4(), newPartnerNumber, partnerRel.uuid, relatedDetailsUuid);
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
|
@ -31,7 +31,7 @@ create or replace procedure buildRbacSystemForHsOfficeSepaMandate(
|
||||
|
||||
declare
|
||||
newBankAccount hs_office_bankaccount;
|
||||
newDebitorRel hs_office_relationship;
|
||||
newDebitorRel hs_office_relation;
|
||||
|
||||
begin
|
||||
call enterTriggerForObjectUuid(NEW.uuid);
|
||||
@ -40,7 +40,7 @@ begin
|
||||
assert newBankAccount.uuid is not null, format('newBankAccount must not be null for NEW.bankAccountUuid = %s', NEW.bankAccountUuid);
|
||||
|
||||
SELECT debitorRel.*
|
||||
FROM hs_office_relationship debitorRel
|
||||
FROM hs_office_relation debitorRel
|
||||
JOIN hs_office_debitor debitor ON debitor.debitorRelUuid = debitorRel.uuid
|
||||
WHERE debitor.uuid = NEW.debitorUuid
|
||||
INTO newDebitorRel;
|
||||
@ -64,7 +64,7 @@ begin
|
||||
hsOfficeSepaMandateAgent(NEW),
|
||||
incomingSuperRoles => array[hsOfficeSepaMandateAdmin(NEW)],
|
||||
outgoingSubRoles => array[
|
||||
hsOfficeRelationshipAgent(newDebitorRel),
|
||||
hsOfficeRelationAgent(newDebitorRel),
|
||||
hsOfficeBankAccountReferrer(newBankAccount)]
|
||||
);
|
||||
|
||||
@ -74,8 +74,8 @@ begin
|
||||
incomingSuperRoles => array[
|
||||
hsOfficeSepaMandateAgent(NEW),
|
||||
hsOfficeBankAccountAdmin(newBankAccount),
|
||||
hsOfficeRelationshipAgent(newDebitorRel)],
|
||||
outgoingSubRoles => array[hsOfficeRelationshipTenant(newDebitorRel)]
|
||||
hsOfficeRelationAgent(newDebitorRel)],
|
||||
outgoingSubRoles => array[hsOfficeRelationTenant(newDebitorRel)]
|
||||
);
|
||||
|
||||
call leaveTriggerForObjectUuid(NEW.uuid);
|
||||
@ -106,19 +106,19 @@ execute procedure insertTriggerForHsOfficeSepaMandate_tf();
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Creates INSERT INTO hs_office_sepamandate permissions for the related hs_office_relationship rows.
|
||||
Creates INSERT INTO hs_office_sepamandate permissions for the related hs_office_relation rows.
|
||||
*/
|
||||
do language plpgsql $$
|
||||
declare
|
||||
row hs_office_relationship;
|
||||
row hs_office_relation;
|
||||
permissionUuid uuid;
|
||||
roleUuid uuid;
|
||||
begin
|
||||
call defineContext('create INSERT INTO hs_office_sepamandate permissions for the related hs_office_relationship rows');
|
||||
call defineContext('create INSERT INTO hs_office_sepamandate permissions for the related hs_office_relation rows');
|
||||
|
||||
FOR row IN SELECT * FROM hs_office_relationship
|
||||
FOR row IN SELECT * FROM hs_office_relation
|
||||
LOOP
|
||||
roleUuid := findRoleId(hsOfficeRelationshipAdmin(row));
|
||||
roleUuid := findRoleId(hsOfficeRelationAdmin(row));
|
||||
permissionUuid := createPermission(row.uuid, 'INSERT', 'hs_office_sepamandate');
|
||||
call grantPermissionToRole(permissionUuid, roleUuid);
|
||||
END LOOP;
|
||||
@ -126,24 +126,24 @@ do language plpgsql $$
|
||||
$$;
|
||||
|
||||
/**
|
||||
Adds hs_office_sepamandate INSERT permission to specified role of new hs_office_relationship rows.
|
||||
Adds hs_office_sepamandate INSERT permission to specified role of new hs_office_relation rows.
|
||||
*/
|
||||
create or replace function hs_office_sepamandate_hs_office_relationship_insert_tf()
|
||||
create or replace function hs_office_sepamandate_hs_office_relation_insert_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
begin
|
||||
call grantPermissionToRole(
|
||||
createPermission(NEW.uuid, 'INSERT', 'hs_office_sepamandate'),
|
||||
hsOfficeRelationshipAdmin(NEW));
|
||||
hsOfficeRelationAdmin(NEW));
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger z_hs_office_sepamandate_hs_office_relationship_insert_tg
|
||||
after insert on hs_office_relationship
|
||||
create trigger z_hs_office_sepamandate_hs_office_relation_insert_tg
|
||||
after insert on hs_office_relation
|
||||
for each row
|
||||
execute procedure hs_office_sepamandate_hs_office_relationship_insert_tf();
|
||||
execute procedure hs_office_sepamandate_hs_office_relation_insert_tf();
|
||||
|
||||
/**
|
||||
Checks if the user or assumed roles are allowed to insert a row to hs_office_sepamandate.
|
||||
@ -156,7 +156,7 @@ begin
|
||||
( SELECT debitorRel.uuid FROM
|
||||
|
||||
(SELECT debitorRel.*
|
||||
FROM hs_office_relationship debitorRel
|
||||
FROM hs_office_relation debitorRel
|
||||
JOIN hs_office_debitor debitor ON debitor.debitorRelUuid = debitorRel.uuid
|
||||
WHERE debitor.uuid = NEW.debitorUuid
|
||||
) AS debitorRel
|
||||
|
@ -25,9 +25,9 @@ begin
|
||||
|
||||
select debitor.* into relatedDebitor
|
||||
from hs_office_debitor debitor
|
||||
join hs_office_relationship debitorRel on debitorRel.uuid = debitor.debitorRelUuid
|
||||
join hs_office_relationship partnerRel on partnerRel.relHolderUuid = debitorRel.relAnchorUuid
|
||||
join hs_office_partner partner on partner.partnerRoleUuid = partnerRel.uuid
|
||||
join hs_office_relation debitorRel on debitorRel.uuid = debitor.debitorRelUuid
|
||||
join hs_office_relation partnerRel on partnerRel.holderUuid = debitorRel.anchorUuid
|
||||
join hs_office_partner partner on partner.partnerRelUuid = partnerRel.uuid
|
||||
where partner.partnerNumber = forPartnerNumber and debitor.debitorNumberSuffix = forDebitorSuffix;
|
||||
select b.* into relatedBankAccount
|
||||
from hs_office_bankAccount b where b.iban = forIban;
|
||||
|
@ -8,7 +8,7 @@ create table hs_office_debitor
|
||||
(
|
||||
uuid uuid unique references RbacObject (uuid) initially deferred,
|
||||
debitorNumberSuffix numeric(2) not null,
|
||||
debitorRelUuid uuid not null references hs_office_relationship(uuid),
|
||||
debitorRelUuid uuid not null references hs_office_relation(uuid),
|
||||
billable boolean not null default true,
|
||||
vatId varchar(24), -- TODO.spec: here or in person?
|
||||
vatCountryCode varchar(2),
|
||||
|
@ -30,25 +30,25 @@ create or replace procedure buildRbacSystemForHsOfficeDebitor(
|
||||
language plpgsql as $$
|
||||
|
||||
declare
|
||||
newPartnerRel hs_office_relationship;
|
||||
newDebitorRel hs_office_relationship;
|
||||
newPartnerRel hs_office_relation;
|
||||
newDebitorRel hs_office_relation;
|
||||
newRefundBankAccount hs_office_bankaccount;
|
||||
|
||||
begin
|
||||
call enterTriggerForObjectUuid(NEW.uuid);
|
||||
|
||||
SELECT partnerRel.*
|
||||
FROM hs_office_relationship AS partnerRel
|
||||
JOIN hs_office_relationship AS debitorRel
|
||||
ON debitorRel.relType = 'ACCOUNTING' AND debitorRel.relAnchorUuid = partnerRel.relHolderUuid
|
||||
WHERE partnerRel.relType = 'PARTNER'
|
||||
FROM hs_office_relation AS partnerRel
|
||||
JOIN hs_office_relation AS debitorRel
|
||||
ON debitorRel.type = 'DEBITOR' AND debitorRel.anchorUuid = partnerRel.holderUuid
|
||||
WHERE partnerRel.type = 'PARTNER'
|
||||
AND NEW.debitorRelUuid = debitorRel.uuid
|
||||
INTO newPartnerRel;
|
||||
assert newPartnerRel.uuid is not null, format('newPartnerRel must not be null for NEW.debitorRelUuid = %s', NEW.debitorRelUuid);
|
||||
|
||||
SELECT *
|
||||
FROM hs_office_relationship AS r
|
||||
WHERE r.relType = 'ACCOUNTING' AND r.uuid = NEW.debitorRelUuid
|
||||
FROM hs_office_relation AS r
|
||||
WHERE r.type = 'DEBITOR' AND r.uuid = NEW.debitorRelUuid
|
||||
INTO newDebitorRel;
|
||||
assert newDebitorRel.uuid is not null, format('newDebitorRel must not be null for NEW.debitorRelUuid = %s', NEW.debitorRelUuid);
|
||||
|
||||
@ -57,15 +57,15 @@ begin
|
||||
WHERE b.uuid = NEW.refundBankAccountUuid
|
||||
INTO newRefundBankAccount;
|
||||
|
||||
call grantRoleToRole(hsOfficeBankAccountReferrer(newRefundBankAccount), hsOfficeRelationshipAgent(newDebitorRel));
|
||||
call grantRoleToRole(hsOfficeRelationshipAdmin(newDebitorRel), hsOfficeRelationshipAdmin(newPartnerRel));
|
||||
call grantRoleToRole(hsOfficeRelationshipAgent(newDebitorRel), hsOfficeBankAccountAdmin(newRefundBankAccount));
|
||||
call grantRoleToRole(hsOfficeRelationshipAgent(newDebitorRel), hsOfficeRelationshipAgent(newPartnerRel));
|
||||
call grantRoleToRole(hsOfficeRelationshipTenant(newPartnerRel), hsOfficeRelationshipAgent(newDebitorRel));
|
||||
call grantRoleToRole(hsOfficeBankAccountReferrer(newRefundBankAccount), hsOfficeRelationAgent(newDebitorRel));
|
||||
call grantRoleToRole(hsOfficeRelationAdmin(newDebitorRel), hsOfficeRelationAdmin(newPartnerRel));
|
||||
call grantRoleToRole(hsOfficeRelationAgent(newDebitorRel), hsOfficeBankAccountAdmin(newRefundBankAccount));
|
||||
call grantRoleToRole(hsOfficeRelationAgent(newDebitorRel), hsOfficeRelationAgent(newPartnerRel));
|
||||
call grantRoleToRole(hsOfficeRelationTenant(newPartnerRel), hsOfficeRelationAgent(newDebitorRel));
|
||||
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'DELETE'), hsOfficeRelationshipOwner(newDebitorRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'SELECT'), hsOfficeRelationshipTenant(newDebitorRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'UPDATE'), hsOfficeRelationshipAdmin(newDebitorRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'DELETE'), hsOfficeRelationOwner(newDebitorRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'SELECT'), hsOfficeRelationTenant(newDebitorRel));
|
||||
call grantPermissionToRole(createPermission(NEW.uuid, 'UPDATE'), hsOfficeRelationAdmin(newDebitorRel));
|
||||
|
||||
call leaveTriggerForObjectUuid(NEW.uuid);
|
||||
end; $$;
|
||||
@ -202,10 +202,10 @@ create trigger hs_office_debitor_insert_permission_check_tg
|
||||
SELECT debitor.uuid AS uuid,
|
||||
'D-' || (SELECT partner.partnerNumber
|
||||
FROM hs_office_partner partner
|
||||
JOIN hs_office_relationship partnerRel
|
||||
ON partnerRel.uuid = partner.partnerRoleUUid AND partnerRel.relType = 'PARTNER'
|
||||
JOIN hs_office_relationship debitorRel
|
||||
ON debitorRel.relAnchorUuid = partnerRel.relHolderUuid AND debitorRel.relType = 'ACCOUNTING'
|
||||
JOIN hs_office_relation partnerRel
|
||||
ON partnerRel.uuid = partner.partnerRelUUid AND partnerRel.type = 'PARTNER'
|
||||
JOIN hs_office_relation debitorRel
|
||||
ON debitorRel.anchorUuid = partnerRel.holderUuid AND debitorRel.type = 'DEBITOR'
|
||||
WHERE debitorRel.uuid = debitor.debitorRelUuid)
|
||||
|| to_char(debitorNumberSuffix, 'fm00') as idName
|
||||
FROM hs_office_debitor AS debitor
|
||||
|
@ -28,10 +28,10 @@ begin
|
||||
|
||||
select debitorRel.uuid
|
||||
into relatedDebitorRelUuid
|
||||
from hs_office_relationship debitorRel
|
||||
join hs_office_person person on person.uuid = debitorRel.relHolderUuid
|
||||
from hs_office_relation debitorRel
|
||||
join hs_office_person person on person.uuid = debitorRel.holderUuid
|
||||
and (person.tradeName = forPartnerPersonName or person.familyName = forPartnerPersonName)
|
||||
where debitorRel.relType = 'ACCOUNTING';
|
||||
where debitorRel.type = 'DEBITOR';
|
||||
|
||||
select b.uuid
|
||||
into relatedBankAccountUuid
|
||||
|
@ -30,14 +30,14 @@ create or replace procedure buildRbacSystemForHsOfficeMembership(
|
||||
language plpgsql as $$
|
||||
|
||||
declare
|
||||
newPartnerRel hs_office_relationship;
|
||||
newPartnerRel hs_office_relation;
|
||||
|
||||
begin
|
||||
call enterTriggerForObjectUuid(NEW.uuid);
|
||||
|
||||
SELECT r.*
|
||||
FROM hs_office_partner AS p
|
||||
JOIN hs_office_relationship AS r ON r.uuid = p.partnerRoleUuid
|
||||
JOIN hs_office_relation AS r ON r.uuid = p.partnerRelUuid
|
||||
WHERE p.uuid = NEW.partnerUuid
|
||||
INTO newPartnerRel;
|
||||
assert newPartnerRel.uuid is not null, format('newPartnerRel must not be null for NEW.partnerUuid = %s', NEW.partnerUuid);
|
||||
@ -46,7 +46,7 @@ begin
|
||||
perform createRoleWithGrants(
|
||||
hsOfficeMembershipOwner(NEW),
|
||||
permissions => array['DELETE'],
|
||||
incomingSuperRoles => array[hsOfficeRelationshipAdmin(newPartnerRel)],
|
||||
incomingSuperRoles => array[hsOfficeRelationAdmin(newPartnerRel)],
|
||||
userUuids => array[currentUserUuid()]
|
||||
);
|
||||
|
||||
@ -55,14 +55,14 @@ begin
|
||||
permissions => array['UPDATE'],
|
||||
incomingSuperRoles => array[
|
||||
hsOfficeMembershipOwner(NEW),
|
||||
hsOfficeRelationshipAgent(newPartnerRel)]
|
||||
hsOfficeRelationAgent(newPartnerRel)]
|
||||
);
|
||||
|
||||
perform createRoleWithGrants(
|
||||
hsOfficeMembershipReferrer(NEW),
|
||||
permissions => array['SELECT'],
|
||||
incomingSuperRoles => array[hsOfficeMembershipAdmin(NEW)],
|
||||
outgoingSubRoles => array[hsOfficeRelationshipTenant(newPartnerRel)]
|
||||
outgoingSubRoles => array[hsOfficeRelationTenant(newPartnerRel)]
|
||||
);
|
||||
|
||||
call leaveTriggerForObjectUuid(NEW.uuid);
|
||||
@ -93,19 +93,19 @@ execute procedure insertTriggerForHsOfficeMembership_tf();
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Creates INSERT INTO hs_office_membership permissions for the related hs_office_relationship rows.
|
||||
Creates INSERT INTO hs_office_membership permissions for the related hs_office_relation rows.
|
||||
*/
|
||||
do language plpgsql $$
|
||||
declare
|
||||
row hs_office_relationship;
|
||||
row hs_office_relation;
|
||||
permissionUuid uuid;
|
||||
roleUuid uuid;
|
||||
begin
|
||||
call defineContext('create INSERT INTO hs_office_membership permissions for the related hs_office_relationship rows');
|
||||
call defineContext('create INSERT INTO hs_office_membership permissions for the related hs_office_relation rows');
|
||||
|
||||
FOR row IN SELECT * FROM hs_office_relationship
|
||||
FOR row IN SELECT * FROM hs_office_relation
|
||||
LOOP
|
||||
roleUuid := findRoleId(hsOfficeRelationshipAdmin(row));
|
||||
roleUuid := findRoleId(hsOfficeRelationAdmin(row));
|
||||
permissionUuid := createPermission(row.uuid, 'INSERT', 'hs_office_membership');
|
||||
call grantPermissionToRole(permissionUuid, roleUuid);
|
||||
END LOOP;
|
||||
@ -113,24 +113,24 @@ do language plpgsql $$
|
||||
$$;
|
||||
|
||||
/**
|
||||
Adds hs_office_membership INSERT permission to specified role of new hs_office_relationship rows.
|
||||
Adds hs_office_membership INSERT permission to specified role of new hs_office_relation rows.
|
||||
*/
|
||||
create or replace function hs_office_membership_hs_office_relationship_insert_tf()
|
||||
create or replace function hs_office_membership_hs_office_relation_insert_tf()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
begin
|
||||
call grantPermissionToRole(
|
||||
createPermission(NEW.uuid, 'INSERT', 'hs_office_membership'),
|
||||
hsOfficeRelationshipAdmin(NEW));
|
||||
hsOfficeRelationAdmin(NEW));
|
||||
return NEW;
|
||||
end; $$;
|
||||
|
||||
-- z_... is to put it at the end of after insert triggers, to make sure the roles exist
|
||||
create trigger z_hs_office_membership_hs_office_relationship_insert_tg
|
||||
after insert on hs_office_relationship
|
||||
create trigger z_hs_office_membership_hs_office_relation_insert_tg
|
||||
after insert on hs_office_relation
|
||||
for each row
|
||||
execute procedure hs_office_membership_hs_office_relationship_insert_tf();
|
||||
execute procedure hs_office_membership_hs_office_relation_insert_tf();
|
||||
|
||||
/**
|
||||
Checks if the user or assumed roles are allowed to insert a row to hs_office_membership.
|
||||
@ -144,7 +144,7 @@ begin
|
||||
|
||||
(SELECT r.*
|
||||
FROM hs_office_partner AS p
|
||||
JOIN hs_office_relationship AS r ON r.uuid = p.partnerRoleUuid
|
||||
JOIN hs_office_relation AS r ON r.uuid = p.partnerRelUuid
|
||||
WHERE p.uuid = NEW.partnerUuid
|
||||
) AS partnerRel
|
||||
|
||||
|
@ -8,8 +8,8 @@ import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountReposi
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.test.Accepts;
|
||||
import net.hostsharing.test.JpaAttempt;
|
||||
@ -27,7 +27,7 @@ import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType.ACCOUNTING;
|
||||
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.DEBITOR;
|
||||
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
|
||||
import static net.hostsharing.test.JsonMatcher.lenientlyEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -65,7 +65,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
HsOfficePersonRepository personRepo;
|
||||
|
||||
@Autowired
|
||||
HsOfficeRelationshipRepository relRepo;
|
||||
HsOfficeRelationRepository relRepo;
|
||||
|
||||
@Autowired
|
||||
JpaAttempt jpaAttempt;
|
||||
@ -93,20 +93,20 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
[
|
||||
{
|
||||
"debitorRel": {
|
||||
"relAnchor": {
|
||||
"anchor": {
|
||||
"personType": "LEGAL_PERSON",
|
||||
"tradeName": "First GmbH",
|
||||
"givenName": null,
|
||||
"familyName": null
|
||||
},
|
||||
"relHolder": {
|
||||
"holder": {
|
||||
"personType": "LEGAL_PERSON",
|
||||
"tradeName": "First GmbH",
|
||||
"givenName": null,
|
||||
"familyName": null
|
||||
},
|
||||
"relType": "ACCOUNTING",
|
||||
"relMark": null,
|
||||
"type": "DEBITOR",
|
||||
"mark": null,
|
||||
"contact": {
|
||||
"label": "first contact",
|
||||
"emailAddresses": "contact-admin@firstcontact.example.com",
|
||||
@ -117,21 +117,21 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
"debitorNumberSuffix": 11,
|
||||
"partner": {
|
||||
"partnerNumber": 10001,
|
||||
"partnerRole": {
|
||||
"relAnchor": {
|
||||
"partnerRel": {
|
||||
"anchor": {
|
||||
"personType": "LEGAL_PERSON",
|
||||
"tradeName": "Hostsharing eG",
|
||||
"givenName": null,
|
||||
"familyName": null
|
||||
},
|
||||
"relHolder": {
|
||||
"holder": {
|
||||
"personType": "LEGAL_PERSON",
|
||||
"tradeName": "First GmbH",
|
||||
"givenName": null,
|
||||
"familyName": null
|
||||
},
|
||||
"relType": "PARTNER",
|
||||
"relMark": null,
|
||||
"type": "PARTNER",
|
||||
"mark": null,
|
||||
"contact": {
|
||||
"label": "first contact",
|
||||
"emailAddresses": "contact-admin@firstcontact.example.com",
|
||||
@ -161,19 +161,19 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
},
|
||||
{
|
||||
"debitorRel": {
|
||||
"relAnchor": {"tradeName": "Second e.K."},
|
||||
"relHolder": {"tradeName": "Second e.K."},
|
||||
"relType": "ACCOUNTING",
|
||||
"anchor": {"tradeName": "Second e.K."},
|
||||
"holder": {"tradeName": "Second e.K."},
|
||||
"type": "DEBITOR",
|
||||
"contact": {"emailAddresses": "contact-admin@secondcontact.example.com"}
|
||||
},
|
||||
"debitorNumber": 1000212,
|
||||
"debitorNumberSuffix": 12,
|
||||
"partner": {
|
||||
"partnerNumber": 10002,
|
||||
"partnerRole": {
|
||||
"relAnchor": {"tradeName": "Hostsharing eG"},
|
||||
"relHolder": {"tradeName": "Second e.K."},
|
||||
"relType": "PARTNER",
|
||||
"partnerRel": {
|
||||
"anchor": {"tradeName": "Hostsharing eG"},
|
||||
"holder": {"tradeName": "Second e.K."},
|
||||
"type": "PARTNER",
|
||||
"contact": {"emailAddresses": "contact-admin@secondcontact.example.com"}
|
||||
},
|
||||
"details": {
|
||||
@ -191,19 +191,19 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
},
|
||||
{
|
||||
"debitorRel": {
|
||||
"relAnchor": {"tradeName": "Third OHG"},
|
||||
"relHolder": {"tradeName": "Third OHG"},
|
||||
"relType": "ACCOUNTING",
|
||||
"anchor": {"tradeName": "Third OHG"},
|
||||
"holder": {"tradeName": "Third OHG"},
|
||||
"type": "DEBITOR",
|
||||
"contact": {"emailAddresses": "contact-admin@thirdcontact.example.com"}
|
||||
},
|
||||
"debitorNumber": 1000313,
|
||||
"debitorNumberSuffix": 13,
|
||||
"partner": {
|
||||
"partnerNumber": 10003,
|
||||
"partnerRole": {
|
||||
"relAnchor": {"tradeName": "Hostsharing eG"},
|
||||
"relHolder": {"tradeName": "Third OHG"},
|
||||
"relType": "PARTNER",
|
||||
"partnerRel": {
|
||||
"anchor": {"tradeName": "Hostsharing eG"},
|
||||
"holder": {"tradeName": "Third OHG"},
|
||||
"type": "PARTNER",
|
||||
"contact": {"emailAddresses": "contact-admin@thirdcontact.example.com"}
|
||||
},
|
||||
"details": {
|
||||
@ -268,10 +268,10 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
final var givenDebitorRelUUid = jpaAttempt.transacted(() -> {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
return relRepo.save(HsOfficeRelationshipEntity.builder()
|
||||
.relType(ACCOUNTING)
|
||||
.relAnchor(givenPartner.getPartnerRole().getRelHolder())
|
||||
.relHolder(givenBillingPerson)
|
||||
return relRepo.save(HsOfficeRelationEntity.builder()
|
||||
.type(DEBITOR)
|
||||
.anchor(givenPartner.getPartnerRel().getHolder())
|
||||
.holder(givenBillingPerson)
|
||||
.contact(givenContact)
|
||||
.build()).getUuid();
|
||||
}).assertSuccessful().returnedValue();
|
||||
@ -303,7 +303,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("vatId", is("VAT123456"))
|
||||
.body("defaultPrefix", is("for"))
|
||||
.body("debitorRel.contact.label", is(givenContact.getLabel()))
|
||||
.body("debitorRel.relHolder.tradeName", is(givenBillingPerson.getTradeName()))
|
||||
.body("debitorRel.holder.tradeName", is(givenBillingPerson.getTradeName()))
|
||||
.body("refundBankAccount.holder", is(givenBankAccount.getHolder()))
|
||||
.header("Location", startsWith("http://localhost"))
|
||||
.extract().header("Location"); // @formatter:on
|
||||
@ -328,9 +328,9 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("""
|
||||
{
|
||||
"debitorRel": {
|
||||
"relType": "ACCOUNTING",
|
||||
"relAnchorUuid": "%s",
|
||||
"relHolderUuid": "%s",
|
||||
"type": "DEBITOR",
|
||||
"anchorUuid": "%s",
|
||||
"holderUuid": "%s",
|
||||
"contactUuid": "%s"
|
||||
},
|
||||
"debitorNumberSuffix": "%s",
|
||||
@ -339,8 +339,8 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
"vatReverseCharge": "false"
|
||||
}
|
||||
""".formatted(
|
||||
givenPartner.getPartnerRole().getRelHolder().getUuid(),
|
||||
givenPartner.getPartnerRole().getRelHolder().getUuid(),
|
||||
givenPartner.getPartnerRel().getHolder().getUuid(),
|
||||
givenPartner.getPartnerRel().getHolder().getUuid(),
|
||||
givenContact.getUuid(),
|
||||
++nextDebitorSuffix))
|
||||
.port(port)
|
||||
@ -351,7 +351,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.contentType(ContentType.JSON)
|
||||
.body("uuid", isUuidValid())
|
||||
.body("debitorRel.contact.label", is(givenContact.getLabel()))
|
||||
.body("partner.partnerRole.relHolder.tradeName", is(givenPartner.getPartnerRole().getRelHolder().getTradeName()))
|
||||
.body("partner.partnerRel.holder.tradeName", is(givenPartner.getPartnerRel().getHolder().getTradeName()))
|
||||
.body("vatId", equalTo(null))
|
||||
.body("vatCountryCode", equalTo(null))
|
||||
.body("vatBusiness", equalTo(false))
|
||||
@ -380,9 +380,9 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("""
|
||||
{
|
||||
"debitorRel": {
|
||||
"relType": "ACCOUNTING",
|
||||
"relAnchorUuid": "%s",
|
||||
"relHolderUuid": "%s",
|
||||
"type": "DEBITOR",
|
||||
"anchorUuid": "%s",
|
||||
"holderUuid": "%s",
|
||||
"contactUuid": "%s"
|
||||
},
|
||||
"debitorNumberSuffix": "%s",
|
||||
@ -391,8 +391,8 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
"vatReverseCharge": "false"
|
||||
}
|
||||
""".formatted(
|
||||
givenPartner.getPartnerRole().getRelAnchor().getUuid(),
|
||||
givenPartner.getPartnerRole().getRelAnchor().getUuid(),
|
||||
givenPartner.getPartnerRel().getAnchor().getUuid(),
|
||||
givenPartner.getPartnerRel().getAnchor().getUuid(),
|
||||
givenContactUuid, ++nextDebitorSuffix))
|
||||
.port(port)
|
||||
.when()
|
||||
@ -428,7 +428,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.post("http://localhost/api/hs/office/debitors")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(400)
|
||||
.body("message", is("Unable to find HsOfficeRelationshipEntity with uuid 00000000-0000-0000-0000-000000000000"));
|
||||
.body("message", is("Unable to find HsOfficeRelationEntity with uuid 00000000-0000-0000-0000-000000000000"));
|
||||
// @formatter:on
|
||||
}
|
||||
}
|
||||
@ -454,9 +454,9 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"debitorRel": {
|
||||
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH"},
|
||||
"relHolder": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH"},
|
||||
"relType": "ACCOUNTING",
|
||||
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH"},
|
||||
"holder": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH"},
|
||||
"type": "DEBITOR",
|
||||
"contact": {
|
||||
"label": "first contact",
|
||||
"postalAddress": "\\nVorname Nachname\\nStraße Hnr\\nPLZ Stadt\\n",
|
||||
@ -468,11 +468,11 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
"debitorNumberSuffix": 11,
|
||||
"partner": {
|
||||
"partnerNumber": 10001,
|
||||
"partnerRole": {
|
||||
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG"},
|
||||
"relHolder": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH"},
|
||||
"relType": "PARTNER",
|
||||
"relMark": null,
|
||||
"partnerRel": {
|
||||
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG"},
|
||||
"holder": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH"},
|
||||
"type": "PARTNER",
|
||||
"mark": null,
|
||||
"contact": {
|
||||
"label": "first contact",
|
||||
"postalAddress": "\\nVorname Nachname\\nStraße Hnr\\nPLZ Stadt\\n",
|
||||
@ -576,7 +576,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("vatBusiness", is(true))
|
||||
.body("defaultPrefix", is("for"))
|
||||
// FIXME .body("billingContact.label", is(givenContact.getLabel()))
|
||||
// FIXME .body("partner.partnerRole.relHolder.tradeName", is(givenDebitor.getPartner().getPartnerRole().getRelHolder().getTradeName()))
|
||||
// FIXME .body("partner.partnerRel.holder.tradeName", is(givenDebitor.getPartner().getPartnerRel().getHolder().getTradeName()))
|
||||
;
|
||||
// @formatter:on
|
||||
|
||||
@ -584,8 +584,8 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
assertThat(debitorRepo.findByUuid(givenDebitor.getUuid())).isPresent().get()
|
||||
.matches(debitor -> {
|
||||
assertThat(debitor.getDebitorRel().getRelHolder().getTradeName())
|
||||
.isEqualTo(givenDebitor.getDebitorRel().getRelHolder().getTradeName());
|
||||
assertThat(debitor.getDebitorRel().getHolder().getTradeName())
|
||||
.isEqualTo(givenDebitor.getDebitorRel().getHolder().getTradeName());
|
||||
assertThat(debitor.getDebitorRel().getContact().getLabel()).isEqualTo("fourth contact");
|
||||
assertThat(debitor.getVatId()).isEqualTo("VAT222222");
|
||||
assertThat(debitor.getVatCountryCode()).isEqualTo("AA");
|
||||
@ -627,8 +627,8 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
// finally, the debitor is actually updated
|
||||
assertThat(debitorRepo.findByUuid(givenDebitor.getUuid())).isPresent().get()
|
||||
.matches(partner -> {
|
||||
assertThat(partner.getDebitorRel().getRelHolder().getTradeName())
|
||||
.isEqualTo(givenDebitor.getDebitorRel().getRelHolder().getTradeName());
|
||||
assertThat(partner.getDebitorRel().getHolder().getTradeName())
|
||||
.isEqualTo(givenDebitor.getDebitorRel().getHolder().getTradeName());
|
||||
// FIXME assertThat(partner.getDebitorRel().getContact().getLabel()).isEqualTo("sixth contact");
|
||||
assertThat(partner.getVatId()).isEqualTo("VAT999999");
|
||||
assertThat(partner.getVatCountryCode()).isEqualTo(givenDebitor.getVatCountryCode());
|
||||
@ -711,10 +711,10 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.debitorNumberSuffix(++nextDebitorSuffix)
|
||||
.billable(true)
|
||||
.debitorRel(
|
||||
HsOfficeRelationshipEntity.builder()
|
||||
.relType(ACCOUNTING)
|
||||
.relAnchor(givenPartner.getPartnerRole().getRelHolder())
|
||||
.relHolder(givenPartner.getPartnerRole().getRelHolder())
|
||||
HsOfficeRelationEntity.builder()
|
||||
.type(DEBITOR)
|
||||
.anchor(givenPartner.getPartnerRel().getHolder())
|
||||
.holder(givenPartner.getPartnerRel().getHolder())
|
||||
.contact(givenContact)
|
||||
.build()
|
||||
)
|
||||
|
@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeDebitorPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.test.PatchUnitTestBase;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
@ -44,7 +44,7 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
private static final UUID INITIAL_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID();
|
||||
private static final UUID PATCHED_REFUND_BANK_ACCOUNT_UUID = UUID.randomUUID();
|
||||
|
||||
private final HsOfficeRelationshipEntity givenInitialDebitorRel = HsOfficeRelationshipEntity.builder()
|
||||
private final HsOfficeRelationEntity givenInitialDebitorRel = HsOfficeRelationEntity.builder()
|
||||
.uuid(INITIAL_DEBITOR_REL_UUID)
|
||||
.build();
|
||||
|
||||
@ -56,8 +56,8 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
|
||||
@BeforeEach
|
||||
void initMocks() {
|
||||
lenient().when(em.getReference(eq(HsOfficeRelationshipEntity.class), any())).thenAnswer(invocation ->
|
||||
HsOfficeRelationshipEntity.builder().uuid(invocation.getArgument(1)).build());
|
||||
lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation ->
|
||||
HsOfficeRelationEntity.builder().uuid(invocation.getArgument(1)).build());
|
||||
lenient().when(em.getReference(eq(HsOfficeBankAccountEntity.class), any())).thenAnswer(invocation ->
|
||||
HsOfficeBankAccountEntity.builder().uuid(invocation.getArgument(1)).build());
|
||||
}
|
||||
@ -141,8 +141,8 @@ class HsOfficeDebitorEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
);
|
||||
}
|
||||
|
||||
private HsOfficeRelationshipEntity newDebitorRel(final UUID uuid) {
|
||||
return HsOfficeRelationshipEntity.builder()
|
||||
private HsOfficeRelationEntity newDebitorRel(final UUID uuid) {
|
||||
return HsOfficeRelationEntity.builder()
|
||||
.uuid(uuid)
|
||||
.build();
|
||||
}
|
||||
|
@ -4,19 +4,19 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class HsOfficeDebitorEntityUnitTest {
|
||||
|
||||
private HsOfficeRelationshipEntity givenDebitorRel = HsOfficeRelationshipEntity.builder()
|
||||
.relAnchor(HsOfficePersonEntity.builder()
|
||||
private HsOfficeRelationEntity givenDebitorRel = HsOfficeRelationEntity.builder()
|
||||
.anchor(HsOfficePersonEntity.builder()
|
||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||
.tradeName("some partner trade name")
|
||||
.build())
|
||||
.relHolder(HsOfficePersonEntity.builder()
|
||||
.holder(HsOfficePersonEntity.builder()
|
||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||
.tradeName("some billing trade name")
|
||||
.build())
|
||||
@ -36,7 +36,7 @@ class HsOfficeDebitorEntityUnitTest {
|
||||
|
||||
final var result = given.toString();
|
||||
|
||||
assertThat(result).isEqualTo("debitor(D-1234567: rel(relAnchor='LP some partner trade name', relHolder='LP some billing trade name'), som)");
|
||||
assertThat(result).isEqualTo("debitor(D-1234567: rel(anchor='LP some partner trade name', holder='LP some billing trade name'), som)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -5,8 +5,8 @@ import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountReposi
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantsDiagramService;
|
||||
@ -89,10 +89,10 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
final var result = attempt(em, () -> {
|
||||
final var newDebitor = HsOfficeDebitorEntity.builder()
|
||||
.debitorNumberSuffix((byte)21)
|
||||
.debitorRel(HsOfficeRelationshipEntity.builder()
|
||||
.relType(HsOfficeRelationshipType.ACCOUNTING)
|
||||
.relAnchor(givenPartnerPerson)
|
||||
.relHolder(givenPartnerPerson)
|
||||
.debitorRel(HsOfficeRelationEntity.builder()
|
||||
.type(HsOfficeRelationType.DEBITOR)
|
||||
.anchor(givenPartnerPerson)
|
||||
.holder(givenPartnerPerson)
|
||||
.contact(givenContact)
|
||||
.build())
|
||||
.defaultPrefix("abc")
|
||||
@ -121,10 +121,10 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
final var result = attempt(em, () -> {
|
||||
final var newDebitor = HsOfficeDebitorEntity.builder()
|
||||
.debitorNumberSuffix((byte)21)
|
||||
.debitorRel(HsOfficeRelationshipEntity.builder()
|
||||
.relType(HsOfficeRelationshipType.ACCOUNTING)
|
||||
.relAnchor(givenPartnerPerson)
|
||||
.relHolder(givenPartnerPerson)
|
||||
.debitorRel(HsOfficeRelationEntity.builder()
|
||||
.type(HsOfficeRelationType.DEBITOR)
|
||||
.anchor(givenPartnerPerson)
|
||||
.holder(givenPartnerPerson)
|
||||
.contact(givenContact)
|
||||
.build())
|
||||
.billable(true)
|
||||
@ -156,10 +156,10 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
final var givenContact = one(contactRepo.findContactByOptionalLabelLike("fourth contact"));
|
||||
final var newDebitor = HsOfficeDebitorEntity.builder()
|
||||
.debitorNumberSuffix((byte)22)
|
||||
.debitorRel(HsOfficeRelationshipEntity.builder()
|
||||
.relType(HsOfficeRelationshipType.ACCOUNTING)
|
||||
.relAnchor(givenPartnerPerson)
|
||||
.relHolder(givenDebitorPerson)
|
||||
.debitorRel(HsOfficeRelationEntity.builder()
|
||||
.type(HsOfficeRelationType.DEBITOR)
|
||||
.anchor(givenPartnerPerson)
|
||||
.holder(givenDebitorPerson)
|
||||
.contact(givenContact)
|
||||
.build())
|
||||
.defaultPrefix("abc")
|
||||
@ -171,45 +171,45 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
// then
|
||||
assertThat(distinctRoleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(Array.from(
|
||||
initialRoleNames,
|
||||
"hs_office_relationship#FirstGmbH-with-ACCOUNTING-FourtheG.owner",
|
||||
"hs_office_relationship#FirstGmbH-with-ACCOUNTING-FourtheG.admin",
|
||||
"hs_office_relationship#FirstGmbH-with-ACCOUNTING-FourtheG.agent",
|
||||
"hs_office_relationship#FirstGmbH-with-ACCOUNTING-FourtheG.tenant"));
|
||||
"hs_office_relation#FirstGmbH-with-DEBITOR-FourtheG.owner",
|
||||
"hs_office_relation#FirstGmbH-with-DEBITOR-FourtheG.admin",
|
||||
"hs_office_relation#FirstGmbH-with-DEBITOR-FourtheG.agent",
|
||||
"hs_office_relation#FirstGmbH-with-DEBITOR-FourtheG.tenant"));
|
||||
assertThat(distinctGrantDisplaysOf(rawGrantRepo.findAll()))
|
||||
.map(s -> s.replace("hs_office_", ""))
|
||||
.containsExactlyInAnyOrder(Array.fromFormatted(
|
||||
initialGrantNames,
|
||||
// FIXME: the next line is completely wrong, the format as well that it exists
|
||||
"{ grant perm INSERT on relationship#FirstGmbH-with-ACCOUNTING-FourtheG to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.admin by system and assume }",
|
||||
"{ grant perm INSERT on relation#FirstGmbH-with-DEBITOR-FourtheG to role relation#FirstGmbH-with-DEBITOR-FourtheG.admin by system and assume }",
|
||||
|
||||
// owner
|
||||
"{ grant perm DELETE on debitor#D-1000122 to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.owner by system and assume }",
|
||||
"{ grant perm DELETE on relationship#FirstGmbH-with-ACCOUNTING-FourtheG to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.owner by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.owner to role global#global.admin by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.owner to user superuser-alex@hostsharing.net by relationship#FirstGmbH-with-ACCOUNTING-FourtheG.owner and assume }",
|
||||
"{ grant perm DELETE on debitor#D-1000122 to role relation#FirstGmbH-with-DEBITOR-FourtheG.owner by system and assume }",
|
||||
"{ grant perm DELETE on relation#FirstGmbH-with-DEBITOR-FourtheG to role relation#FirstGmbH-with-DEBITOR-FourtheG.owner by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FourtheG.owner to role global#global.admin by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FourtheG.owner to user superuser-alex@hostsharing.net by relation#FirstGmbH-with-DEBITOR-FourtheG.owner and assume }",
|
||||
|
||||
// admin
|
||||
"{ grant perm UPDATE on debitor#D-1000122 to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.admin by system and assume }",
|
||||
"{ grant perm UPDATE on relationship#FirstGmbH-with-ACCOUNTING-FourtheG to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.admin by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.admin to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.owner by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.admin to role person#FirstGmbH.admin by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.admin to role relationship#HostsharingeG-with-PARTNER-FirstGmbH.admin by system and assume }",
|
||||
"{ grant perm UPDATE on debitor#D-1000122 to role relation#FirstGmbH-with-DEBITOR-FourtheG.admin by system and assume }",
|
||||
"{ grant perm UPDATE on relation#FirstGmbH-with-DEBITOR-FourtheG to role relation#FirstGmbH-with-DEBITOR-FourtheG.admin by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FourtheG.admin to role relation#FirstGmbH-with-DEBITOR-FourtheG.owner by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FourtheG.admin to role person#FirstGmbH.admin by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FourtheG.admin to role relation#HostsharingeG-with-PARTNER-FirstGmbH.admin by system and assume }",
|
||||
|
||||
// agent
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.agent to role person#FourtheG.admin by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.agent to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.admin by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.agent to role relationship#HostsharingeG-with-PARTNER-FirstGmbH.agent by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FourtheG.agent to role person#FourtheG.admin by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FourtheG.agent to role relation#FirstGmbH-with-DEBITOR-FourtheG.admin by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FourtheG.agent to role relation#HostsharingeG-with-PARTNER-FirstGmbH.agent by system and assume }",
|
||||
|
||||
// tenant
|
||||
"{ grant perm SELECT on debitor#D-1000122 to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.tenant by system and assume }",
|
||||
"{ grant perm SELECT on relationship#FirstGmbH-with-ACCOUNTING-FourtheG to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.tenant by system and assume }",
|
||||
"{ grant role relationship#HostsharingeG-with-PARTNER-FirstGmbH.tenant to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.agent by system and assume }",
|
||||
"{ grant role contact#fourthcontact.referrer to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.tenant by system and assume }",
|
||||
"{ grant role person#FirstGmbH.referrer to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.tenant by system and assume }",
|
||||
"{ grant role person#FourtheG.referrer to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.tenant by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.tenant to role contact#fourthcontact.admin by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.tenant to role person#FourtheG.admin by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.tenant to role relationship#FirstGmbH-with-ACCOUNTING-FourtheG.agent by system and assume }",
|
||||
"{ grant perm SELECT on debitor#D-1000122 to role relation#FirstGmbH-with-DEBITOR-FourtheG.tenant by system and assume }",
|
||||
"{ grant perm SELECT on relation#FirstGmbH-with-DEBITOR-FourtheG to role relation#FirstGmbH-with-DEBITOR-FourtheG.tenant by system and assume }",
|
||||
"{ grant role relation#HostsharingeG-with-PARTNER-FirstGmbH.tenant to role relation#FirstGmbH-with-DEBITOR-FourtheG.agent by system and assume }",
|
||||
"{ grant role contact#fourthcontact.referrer to role relation#FirstGmbH-with-DEBITOR-FourtheG.tenant by system and assume }",
|
||||
"{ grant role person#FirstGmbH.referrer to role relation#FirstGmbH-with-DEBITOR-FourtheG.tenant by system and assume }",
|
||||
"{ grant role person#FourtheG.referrer to role relation#FirstGmbH-with-DEBITOR-FourtheG.tenant by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FourtheG.tenant to role contact#fourthcontact.admin by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FourtheG.tenant to role person#FourtheG.admin by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FourtheG.tenant to role relation#FirstGmbH-with-DEBITOR-FourtheG.agent by system and assume }",
|
||||
|
||||
null));
|
||||
}
|
||||
@ -235,9 +235,9 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
// then
|
||||
allTheseDebitorsAreReturned(
|
||||
result,
|
||||
"debitor(D-1000111: rel(relAnchor='LP First GmbH', relType='ACCOUNTING', relHolder='LP First GmbH'), fir)",
|
||||
"debitor(D-1000212: rel(relAnchor='LP Second e.K.', relType='ACCOUNTING', relHolder='LP Second e.K.'), sec)",
|
||||
"debitor(D-1000313: rel(relAnchor='IF Third OHG', relType='ACCOUNTING', relHolder='IF Third OHG'), thi)");
|
||||
"debitor(D-1000111: rel(anchor='LP First GmbH', type='DEBITOR', holder='LP First GmbH'), fir)",
|
||||
"debitor(D-1000212: rel(anchor='LP Second e.K.', type='DEBITOR', holder='LP Second e.K.'), sec)",
|
||||
"debitor(D-1000313: rel(anchor='IF Third OHG', type='DEBITOR', holder='IF Third OHG'), thi)");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ -286,7 +286,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
|
||||
// then
|
||||
exactlyTheseDebitorsAreReturned(result,
|
||||
"debitor(D-1000313: rel(relAnchor='IF Third OHG', relType='ACCOUNTING', relHolder='IF Third OHG'), thi)");
|
||||
"debitor(D-1000313: rel(anchor='IF Third OHG', type='DEBITOR', holder='IF Third OHG'), thi)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -302,7 +302,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
final var result = debitorRepo.findDebitorByOptionalNameLike("third contact");
|
||||
|
||||
// then
|
||||
exactlyTheseDebitorsAreReturned(result, "debitor(D-1000313: rel(relAnchor='IF Third OHG', relType='ACCOUNTING', relHolder='IF Third OHG'), thi)");
|
||||
exactlyTheseDebitorsAreReturned(result, "debitor(D-1000313: rel(anchor='IF Third OHG', type='DEBITOR', holder='IF Third OHG'), thi)");
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,7 +317,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
|
||||
assertThatDebitorIsVisibleForUserWithRole(
|
||||
givenDebitor,
|
||||
"hs_office_relationship#FourtheG-with-ACCOUNTING-FourtheG.admin");
|
||||
"hs_office_relation#FourtheG-with-DEBITOR-FourtheG.admin");
|
||||
final var givenNewPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First"));
|
||||
final var givenNewBillingPerson = one(personRepo.findPersonByOptionalNameLike("Firby"));
|
||||
final var givenNewContact = one(contactRepo.findContactByOptionalLabelLike("sixth contact"));
|
||||
@ -329,10 +329,10 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
givenDebitor.setDebitorRel(HsOfficeRelationshipEntity.builder()
|
||||
.relType(HsOfficeRelationshipType.ACCOUNTING)
|
||||
.relAnchor(givenNewPartnerPerson)
|
||||
.relHolder(givenNewBillingPerson)
|
||||
givenDebitor.setDebitorRel(HsOfficeRelationEntity.builder()
|
||||
.type(HsOfficeRelationType.DEBITOR)
|
||||
.anchor(givenNewPartnerPerson)
|
||||
.holder(givenNewBillingPerson)
|
||||
.contact(givenNewContact)
|
||||
.build());
|
||||
givenDebitor.setRefundBankAccount(givenNewBankAccount);
|
||||
@ -351,10 +351,10 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
// ... partner role was reassigned:
|
||||
assertThatDebitorIsNotVisibleForUserWithRole(
|
||||
result.returnedValue(),
|
||||
"hs_office_relationship#FourtheG-with-ACCOUNTING-FourtheG.admin");
|
||||
"hs_office_relation#FourtheG-with-DEBITOR-FourtheG.admin");
|
||||
assertThatDebitorIsVisibleForUserWithRole(
|
||||
result.returnedValue(),
|
||||
"hs_office_relationship#FirstGmbH-with-ACCOUNTING-FirbySusan.agent");
|
||||
"hs_office_relation#FirstGmbH-with-DEBITOR-FirbySusan.agent");
|
||||
|
||||
// ... contact role was reassigned:
|
||||
assertThatDebitorIsNotVisibleForUserWithRole(
|
||||
@ -380,7 +380,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "fifth contact", null, "fig");
|
||||
assertThatDebitorIsVisibleForUserWithRole(
|
||||
givenDebitor,
|
||||
"hs_office_relationship#FourtheG-with-ACCOUNTING-FourtheG.admin");
|
||||
"hs_office_relation#FourtheG-with-DEBITOR-FourtheG.admin");
|
||||
assertThatDebitorActuallyInDatabase(givenDebitor);
|
||||
final var givenNewBankAccount = one(bankAccountRepo.findByOptionalHolderLike("first"));
|
||||
|
||||
@ -410,7 +410,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "fifth contact", "Fourth", "fih");
|
||||
assertThatDebitorIsVisibleForUserWithRole(
|
||||
givenDebitor,
|
||||
"hs_office_relationship#HostsharingeG-with-PARTNER-FourtheG.agent");
|
||||
"hs_office_relation#HostsharingeG-with-PARTNER-FourtheG.agent");
|
||||
assertThatDebitorActuallyInDatabase(givenDebitor);
|
||||
|
||||
// when
|
||||
@ -439,12 +439,12 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "eighth", "Fourth", "eig");
|
||||
assertThatDebitorIsVisibleForUserWithRole(
|
||||
givenDebitor,
|
||||
"hs_office_relationship#HostsharingeG-with-PARTNER-FourtheG.agent");
|
||||
"hs_office_relation#HostsharingeG-with-PARTNER-FourtheG.agent");
|
||||
assertThatDebitorActuallyInDatabase(givenDebitor);
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net", "hs_office_relationship#HostsharingeG-with-PARTNER-FourtheG.agent");
|
||||
context("superuser-alex@hostsharing.net", "hs_office_relation#HostsharingeG-with-PARTNER-FourtheG.agent");
|
||||
givenDebitor.setVatId("NEW-VAT-ID");
|
||||
return toCleanup(debitorRepo.save(givenDebitor));
|
||||
});
|
||||
@ -489,7 +489,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
if ( saved.getPartner() != null) { // FIXME: check, why there is no partner for the updated contact
|
||||
assertThat(foundEntity.getPartner()).isNotNull();
|
||||
}
|
||||
assertThat(foundEntity.getDebitorRel()).extracting(HsOfficeRelationshipEntity::toString)
|
||||
assertThat(foundEntity.getDebitorRel()).extracting(HsOfficeRelationEntity::toString)
|
||||
.isEqualTo(saved.getDebitorRel().toString());
|
||||
});
|
||||
}
|
||||
@ -545,7 +545,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net", "hs_office_relationship#FourtheG-with-ACCOUNTING-FourtheG.admin");
|
||||
context("superuser-alex@hostsharing.net", "hs_office_relation#FourtheG-with-DEBITOR-FourtheG.admin");
|
||||
assertThat(debitorRepo.findByUuid(givenDebitor.getUuid())).isPresent();
|
||||
|
||||
debitorRepo.deleteByUuid(givenDebitor.getUuid());
|
||||
@ -614,10 +614,10 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
bankAccountHolder != null ? one(bankAccountRepo.findByOptionalHolderLike(bankAccountHolder)) : null;
|
||||
final var newDebitor = HsOfficeDebitorEntity.builder()
|
||||
.debitorNumberSuffix((byte)20)
|
||||
.debitorRel(HsOfficeRelationshipEntity.builder()
|
||||
.relType(HsOfficeRelationshipType.ACCOUNTING)
|
||||
.relAnchor(givenPartnerPerson)
|
||||
.relHolder(givenPartnerPerson)
|
||||
.debitorRel(HsOfficeRelationEntity.builder()
|
||||
.type(HsOfficeRelationType.DEBITOR)
|
||||
.anchor(givenPartnerPerson)
|
||||
.holder(givenPartnerPerson)
|
||||
.contact(givenContact)
|
||||
.build())
|
||||
.refundBankAccount(givenBankAccount)
|
||||
|
@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.office.debitor;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.office.contact.TestHsOfficeContact.TEST_CONTACT;
|
||||
import static net.hostsharing.hsadminng.hs.office.partner.TestHsOfficePartner.TEST_PARTNER;
|
||||
@ -14,9 +14,9 @@ public class TestHsOfficeDebitor {
|
||||
|
||||
public static final HsOfficeDebitorEntity TEST_DEBITOR = HsOfficeDebitorEntity.builder()
|
||||
.debitorNumberSuffix(DEFAULT_DEBITOR_SUFFIX)
|
||||
.debitorRel(HsOfficeRelationshipEntity.builder()
|
||||
.relHolder(HsOfficePersonEntity.builder().build())
|
||||
.relAnchor(HsOfficePersonEntity.builder().build())
|
||||
.debitorRel(HsOfficeRelationEntity.builder()
|
||||
.holder(HsOfficePersonEntity.builder().build())
|
||||
.anchor(HsOfficePersonEntity.builder().build())
|
||||
.contact(TEST_CONTACT)
|
||||
.build())
|
||||
.partner(TEST_PARTNER)
|
||||
|
@ -269,7 +269,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "superuser-alex@hostsharing.net")
|
||||
.header("assumed-roles", "hs_office_relationship#HostsharingeG-with-PARTNER-ThirdOHG.agent")
|
||||
.header("assumed-roles", "hs_office_relation#HostsharingeG-with-PARTNER-ThirdOHG.agent")
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/memberships/" + givenMembershipUuid)
|
||||
@ -338,7 +338,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
void partnerRelAgent_canPatchValidityOfRelatedMembership() {
|
||||
|
||||
// given
|
||||
final var givenPartnerAgent = "hs_office_relationship#HostsharingeG-with-PARTNER-FirstGmbH.agent";
|
||||
final var givenPartnerAgent = "hs_office_relation#HostsharingeG-with-PARTNER-FirstGmbH.agent";
|
||||
context.define("superuser-alex@hostsharing.net", givenPartnerAgent);
|
||||
final var givenMembership = givenSomeTemporaryMembershipBessler("First");
|
||||
|
||||
@ -401,7 +401,7 @@ class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCle
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "superuser-alex@hostsharing.net")
|
||||
.header("assumed-roles", "hs_office_relationship#HostsharingeG-with-PARTNER-FirstGmbH.agent")
|
||||
.header("assumed-roles", "hs_office_relation#HostsharingeG-with-PARTNER-FirstGmbH.agent")
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/memberships/" + givenMembership.getUuid())
|
||||
|
@ -126,16 +126,16 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
|
||||
// admin
|
||||
"{ grant perm UPDATE on membership#M-1000117 to role membership#M-1000117.admin by system and assume }",
|
||||
"{ grant role membership#M-1000117.admin to role membership#M-1000117.owner by system and assume }",
|
||||
"{ grant role membership#M-1000117.owner to role relationship#HostsharingeG-with-PARTNER-FirstGmbH.admin by system and assume }",
|
||||
"{ grant role membership#M-1000117.owner to role relation#HostsharingeG-with-PARTNER-FirstGmbH.admin by system and assume }",
|
||||
"{ grant role membership#M-1000117.owner to user superuser-alex@hostsharing.net by membership#M-1000117.owner and assume }",
|
||||
|
||||
// agent
|
||||
"{ grant role membership#M-1000117.admin to role relationship#HostsharingeG-with-PARTNER-FirstGmbH.agent by system and assume }",
|
||||
"{ grant role membership#M-1000117.admin to role relation#HostsharingeG-with-PARTNER-FirstGmbH.agent by system and assume }",
|
||||
|
||||
// referrer
|
||||
"{ grant perm SELECT on membership#M-1000117 to role membership#M-1000117.referrer by system and assume }",
|
||||
"{ grant role membership#M-1000117.referrer to role membership#M-1000117.admin by system and assume }",
|
||||
"{ grant role relationship#HostsharingeG-with-PARTNER-FirstGmbH.tenant to role membership#M-1000117.referrer by system and assume }",
|
||||
"{ grant role relation#HostsharingeG-with-PARTNER-FirstGmbH.tenant to role membership#M-1000117.referrer by system and assume }",
|
||||
|
||||
null));
|
||||
}
|
||||
@ -294,7 +294,7 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCl
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net", "hs_office_relationship#HostsharingeG-with-PARTNER-FirstGmbH.agent");
|
||||
context("superuser-alex@hostsharing.net", "hs_office_relation#HostsharingeG-with-PARTNER-FirstGmbH.agent");
|
||||
assertThat(membershipRepo.findByUuid(givenMembership.getUuid())).isPresent();
|
||||
|
||||
membershipRepo.deleteByUuid(givenMembership.getUuid());
|
||||
|
@ -182,26 +182,26 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
// no contacts yet => mostly null values
|
||||
assertThat(toFormattedString(partners)).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
17=partner(null null, null),
|
||||
20=partner(null null, null),
|
||||
22=partner(null null, null),
|
||||
99=partner(null null, null)
|
||||
17=partner(P-10017: null null, null),
|
||||
20=partner(P-10020: null null, null),
|
||||
22=partner(P-11022: null null, null),
|
||||
99=partner(P-19999: null null, null)
|
||||
}
|
||||
""");
|
||||
assertThat(toFormattedString(contacts)).isEqualTo("{}");
|
||||
assertThat(toFormattedString(debitors)).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
17=debitor(D-1001700: null null, null: mih),
|
||||
20=debitor(D-1002000: null null, null: xyz),
|
||||
22=debitor(D-1102200: null null, null: xxx),
|
||||
99=debitor(D-1999900: null null, null: zzz)
|
||||
17=debitor(D-1001700: rel(anchor='null null, null', type='DEBITOR', holder='null null, null'), mih),
|
||||
20=debitor(D-1002000: rel(anchor='null null, null', type='DEBITOR', holder='null null, null'), xyz),
|
||||
22=debitor(D-1102200: rel(anchor='null null, null', type='DEBITOR', holder='null null, null'), xxx),
|
||||
99=debitor(D-1999900: rel(anchor='null null, null', type='DEBITOR', holder='null null, null'), zzz)
|
||||
}
|
||||
""");
|
||||
assertThat(toFormattedString(memberships)).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
17=Membership(M-1001700, null null, null, D-1001700, [2000-12-06,), NONE),
|
||||
20=Membership(M-1002000, null null, null, D-1002000, [2000-12-06,2016-01-01), UNKNOWN),
|
||||
22=Membership(M-1102200, null null, null, D-1102200, [2021-04-01,), NONE)
|
||||
17=Membership(M-1001700, P-10017, [2000-12-06,), NONE),
|
||||
20=Membership(M-1002000, P-10020, [2000-12-06,2016-01-01), UNKNOWN),
|
||||
22=Membership(M-1102200, P-11022, [2021-04-01,), NONE)
|
||||
}
|
||||
""");
|
||||
}
|
||||
@ -226,7 +226,7 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
.type(HsOfficeRelationType.DEBITOR)
|
||||
.anchor(debitor.getPartner().getPartnerRel().getHolder())
|
||||
.holder(debitor.getPartner().getPartnerRel().getHolder()) // just 1 debitor/partner in legacy hsadmin
|
||||
.contact(debitor.getBillingContact())
|
||||
// FIXME .contact()
|
||||
.build();
|
||||
if (debitorRel.getAnchor() != null && debitorRel.getHolder() != null &&
|
||||
debitorRel.getContact() != null ) {
|
||||
@ -242,10 +242,10 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
|
||||
assertThat(toFormattedString(partners)).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
17=partner(NP Mellies, Michael: Herr Michael Mellies ),
|
||||
20=partner(LP JM GmbH: Herr Philip Meyer-Contract , JM GmbH),
|
||||
22=partner(?? Test PS: Petra Schmidt , Test PS),
|
||||
99=partner(null null, null)
|
||||
17=partner(P-10017: NP Mellies, Michael, Herr Michael Mellies ),
|
||||
20=partner(P-10020: LP JM GmbH, Herr Philip Meyer-Contract , JM GmbH),
|
||||
22=partner(P-11022: ?? Test PS, Petra Schmidt , Test PS),
|
||||
99=partner(P-19999: null null, null)
|
||||
}
|
||||
""");
|
||||
assertThat(toFormattedString(contacts)).isEqualToIgnoringWhitespace("""
|
||||
@ -275,41 +275,42 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
""");
|
||||
assertThat(toFormattedString(debitors)).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
17=debitor(D-1001700: NP Mellies, Michael: mih),
|
||||
20=debitor(D-1002000: LP JM GmbH: xyz),
|
||||
22=debitor(D-1102200: ?? Test PS: xxx),
|
||||
99=debitor(D-1999900: null null, null: zzz)
|
||||
17=debitor(D-1001700: rel(anchor='NP Mellies, Michael', type='DEBITOR', holder='NP Mellies, Michael'), mih),
|
||||
20=debitor(D-1002000: rel(anchor='LP JM GmbH', type='DEBITOR', holder='LP JM GmbH'), xyz),
|
||||
22=debitor(D-1102200: rel(anchor='?? Test PS', type='DEBITOR', holder='?? Test PS'), xxx),
|
||||
99=debitor(D-1999900: rel(anchor='null null, null', type='DEBITOR', holder='null null, null'), zzz)
|
||||
}
|
||||
""");
|
||||
assertThat(toFormattedString(memberships)).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
17=Membership(M-1001700, NP Mellies, Michael, D-1001700, [2000-12-06,), NONE),
|
||||
20=Membership(M-1002000, LP JM GmbH, D-1002000, [2000-12-06,2016-01-01), UNKNOWN),
|
||||
22=Membership(M-1102200, ?? Test PS, D-1102200, [2021-04-01,), NONE)
|
||||
17=Membership(M-1001700, P-10017, [2000-12-06,), NONE),
|
||||
20=Membership(M-1002000, P-10020, [2000-12-06,2016-01-01), UNKNOWN),
|
||||
22=Membership(M-1102200, P-11022, [2021-04-01,), NONE)
|
||||
}
|
||||
""");
|
||||
assertThat(toFormattedString(relations)).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
2000000=rel(anchor='LP Hostsharing eG', type='PARTNER', holder='NP Mellies, Michael', contact='Herr Michael Mellies '),
|
||||
2000001=rel(anchor='LP Hostsharing eG', type='PARTNER', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
|
||||
2000002=rel(anchor='LP Hostsharing eG', type='PARTNER', holder='?? Test PS', contact='Petra Schmidt , Test PS'),
|
||||
2000003=rel(anchor='LP Hostsharing eG', type='PARTNER', holder='null null, null'),
|
||||
2000004=rel(anchor='NP Mellies, Michael', type='OPERATIONS', holder='NP Mellies, Michael', contact='Herr Michael Mellies '),
|
||||
2000005=rel(anchor='NP Mellies, Michael', type='REPRESENTATIVE', holder='NP Mellies, Michael', contact='Herr Michael Mellies '),
|
||||
2000006=rel(anchor='LP JM GmbH', type='EX_PARTNER', holder='LP JM e.K.', contact='JM e.K.'),
|
||||
2000007=rel(anchor='LP JM GmbH', type='OPERATIONS', holder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
|
||||
2000008=rel(anchor='LP JM GmbH', type='VIP_CONTACT', holder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
|
||||
2000009=rel(anchor='LP JM GmbH', type='SUBSCRIBER', mark='operations-announce', holder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
|
||||
2000010=rel(anchor='LP JM GmbH', type='REPRESENTATIVE', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
|
||||
2000011=rel(anchor='LP JM GmbH', type='SUBSCRIBER', mark='members-announce', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
|
||||
2000012=rel(anchor='LP JM GmbH', type='SUBSCRIBER', mark='customers-announce', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
|
||||
2000013=rel(anchor='LP JM GmbH', type='VIP_CONTACT', holder='LP JM GmbH', contact='Frau Tammy Meyer-VIP , JM GmbH'),
|
||||
2000014=rel(anchor='?? Test PS', type='OPERATIONS', holder='?? Test PS', contact='Petra Schmidt , Test PS'),
|
||||
2000015=rel(anchor='?? Test PS', type='REPRESENTATIVE', holder='?? Test PS', contact='Petra Schmidt , Test PS'),
|
||||
2000016=rel(anchor='NP Mellies, Michael', type='SUBSCRIBER', mark='operations-announce', holder='NP Fanninga, Frauke', contact='Frau Frauke Fanninga '),
|
||||
2000017=rel(anchor='NP Mellies, Michael', type='DEBITOR', holder='NP Mellies, Michael', contact='Herr Michael Mellies '),
|
||||
2000018=rel(anchor='LP JM GmbH', type='DEBITOR', holder='LP JM GmbH', contact='Frau Dr. Jenny Meyer-Billing , JM GmbH'),
|
||||
2000019=rel(anchor='?? Test PS', type='DEBITOR', holder='?? Test PS', contact='Petra Schmidt , Test PS')
|
||||
2000001=rel(anchor='NP Mellies, Michael', type='DEBITOR', holder='NP Mellies, Michael', contact='Herr Michael Mellies '),
|
||||
2000002=rel(anchor='LP Hostsharing eG', type='PARTNER', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
|
||||
2000003=rel(anchor='LP JM GmbH', type='DEBITOR', holder='LP JM GmbH', contact='Frau Dr. Jenny Meyer-Billing , JM GmbH'),
|
||||
2000004=rel(anchor='LP Hostsharing eG', type='PARTNER', holder='?? Test PS', contact='Petra Schmidt , Test PS'),
|
||||
2000005=rel(anchor='?? Test PS', type='DEBITOR', holder='?? Test PS', contact='Petra Schmidt , Test PS'),
|
||||
2000006=rel(anchor='LP Hostsharing eG', type='PARTNER', holder='null null, null'),
|
||||
2000007=rel(anchor='null null, null', type='DEBITOR', holder='null null, null'),
|
||||
2000008=rel(anchor='NP Mellies, Michael', type='OPERATIONS', holder='NP Mellies, Michael', contact='Herr Michael Mellies '),
|
||||
2000009=rel(anchor='NP Mellies, Michael', type='REPRESENTATIVE', holder='NP Mellies, Michael', contact='Herr Michael Mellies '),
|
||||
2000010=rel(anchor='LP JM GmbH', type='EX_PARTNER', holder='LP JM e.K.', contact='JM e.K.'),
|
||||
2000011=rel(anchor='LP JM GmbH', type='OPERATIONS', holder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
|
||||
2000012=rel(anchor='LP JM GmbH', type='VIP_CONTACT', holder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
|
||||
2000013=rel(anchor='LP JM GmbH', type='SUBSCRIBER', mark='operations-announce', holder='LP JM GmbH', contact='Herr Andrew Meyer-Operation , JM GmbH'),
|
||||
2000014=rel(anchor='LP JM GmbH', type='REPRESENTATIVE', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
|
||||
2000015=rel(anchor='LP JM GmbH', type='SUBSCRIBER', mark='members-announce', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
|
||||
2000016=rel(anchor='LP JM GmbH', type='SUBSCRIBER', mark='customers-announce', holder='LP JM GmbH', contact='Herr Philip Meyer-Contract , JM GmbH'),
|
||||
2000017=rel(anchor='LP JM GmbH', type='VIP_CONTACT', holder='LP JM GmbH', contact='Frau Tammy Meyer-VIP , JM GmbH'),
|
||||
2000018=rel(anchor='?? Test PS', type='OPERATIONS', holder='?? Test PS', contact='Petra Schmidt , Test PS'),
|
||||
2000019=rel(anchor='?? Test PS', type='REPRESENTATIVE', holder='?? Test PS', contact='Petra Schmidt , Test PS'),
|
||||
2000020=rel(anchor='NP Mellies, Michael', type='SUBSCRIBER', mark='operations-announce', holder='NP Fanninga, Frauke', contact='Frau Frauke Fanninga ')
|
||||
}
|
||||
""");
|
||||
}
|
||||
@ -333,9 +334,9 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
|
||||
assertThat(toFormattedString(bankAccounts)).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
234234=bankAccount(holder='Michael Mellies', iban='DE37500105177419788228', bic='INGDDEFFXXX'),
|
||||
235600=bankAccount(holder='JM e.K.', iban='DE02300209000106531065', bic='CMCIDEDD'),
|
||||
235662=bankAccount(holder='JM GmbH', iban='DE49500105174516484892', bic='INGDDEFFXXX')
|
||||
234234=bankAccount(DE37500105177419788228: holder='Michael Mellies', bic='INGDDEFFXXX'),
|
||||
235600=bankAccount(DE02300209000106531065: holder='JM e.K.', bic='CMCIDEDD'),
|
||||
235662=bankAccount(DE49500105174516484892: holder='JM GmbH', bic='INGDDEFFXXX')
|
||||
}
|
||||
""");
|
||||
assertThat(toFormattedString(sepaMandates)).isEqualToIgnoringWhitespace("""
|
||||
@ -359,7 +360,7 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1049)
|
||||
@Order(1041)
|
||||
void verifyCoopShares() {
|
||||
assumeThatWeAreImportingControlledTestData();
|
||||
|
||||
@ -392,14 +393,14 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
|
||||
assertThat(toFormattedString(coopAssets)).isEqualToIgnoringWhitespace("""
|
||||
{
|
||||
30000=CoopAssetsTransaction(1001700, 2000-12-06, DEPOSIT, 1280.00, for subscription A),
|
||||
31000=CoopAssetsTransaction(1002000, 2000-12-06, DEPOSIT, 128.00, for subscription B),
|
||||
32000=CoopAssetsTransaction(1001700, 2005-01-10, DEPOSIT, 2560.00, for subscription C),
|
||||
33001=CoopAssetsTransaction(1001700, 2005-01-10, TRANSFER, -512.00, for transfer to 10),
|
||||
33002=CoopAssetsTransaction(1002000, 2005-01-10, ADOPTION, 512.00, for transfer from 7),
|
||||
34001=CoopAssetsTransaction(1002000, 2016-12-31, CLEARING, -8.00, for cancellation D),
|
||||
34002=CoopAssetsTransaction(1002000, 2016-12-31, DISBURSAL, -100.00, for cancellation D),
|
||||
34003=CoopAssetsTransaction(1002000, 2016-12-31, LOSS, -20.00, for cancellation D)
|
||||
30000=CoopAssetsTransaction(M-1001700: 2000-12-06, DEPOSIT, 1280.00, for subscription A),
|
||||
31000=CoopAssetsTransaction(M-1002000: 2000-12-06, DEPOSIT, 128.00, for subscription B),
|
||||
32000=CoopAssetsTransaction(M-1001700: 2005-01-10, DEPOSIT, 2560.00, for subscription C),
|
||||
33001=CoopAssetsTransaction(M-1001700: 2005-01-10, TRANSFER, -512.00, for transfer to 10),
|
||||
33002=CoopAssetsTransaction(M-1002000: 2005-01-10, ADOPTION, 512.00, for transfer from 7),
|
||||
34001=CoopAssetsTransaction(M-1002000: 2016-12-31, CLEARING, -8.00, for cancellation D),
|
||||
34002=CoopAssetsTransaction(M-1002000: 2016-12-31, DISBURSAL, -100.00, for cancellation D),
|
||||
34003=CoopAssetsTransaction(M-1002000: 2016-12-31, LOSS, -20.00, for cancellation D)
|
||||
}
|
||||
""");
|
||||
}
|
||||
@ -408,11 +409,13 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
@Order(2000)
|
||||
void verifyAllPartnersHavePersons() {
|
||||
partners.forEach((id, p) -> {
|
||||
final var partnerRel = p.getPartnerRel();
|
||||
assertThat(partnerRel).describedAs("partner " + id + " without partnerRel").isNotNull();
|
||||
if ( id != 99 ) {
|
||||
assertThat(p.getContact()).describedAs("partner " + id + " without contact").isNotNull();
|
||||
assertThat(p.getContact().getLabel()).describedAs("partner " + id + " without valid contact").isNotNull();
|
||||
assertThat(p.getPerson()).describedAs("partner " + id + " without person").isNotNull();
|
||||
assertThat(p.getPerson().getPersonType()).describedAs("partner " + id + " without valid person").isNotNull();
|
||||
assertThat(partnerRel.getContact()).describedAs("partner " + id + " without partnerRel.contact").isNotNull();
|
||||
assertThat(partnerRel.getContact().getLabel()).describedAs("partner " + id + " without valid partnerRel.contact").isNotNull();
|
||||
assertThat(partnerRel.getHolder()).describedAs("partner " + id + " without partnerRel.relHolder").isNotNull();
|
||||
assertThat(partnerRel.getHolder().getPersonType()).describedAs("partner " + id + " without valid partnerRel.relHolder").isNotNull();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -427,11 +430,11 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
relations.forEach( (id, r) -> {
|
||||
// such a record
|
||||
if (r.getContact() == null || r.getContact().getLabel() == null ||
|
||||
r.getHolder() == null | r.getHolder().getPersonType() == null ) {
|
||||
r.getHolder() == null || r.getHolder().getPersonType() == null ) {
|
||||
idsToRemove.add(id);
|
||||
}
|
||||
});
|
||||
assertThat(idsToRemove.size()).isEqualTo(1); // only from partner #99 (partner+contractual roles)
|
||||
assertThat(idsToRemove.size()).isEqualTo(2); // partner #99 + Hostsharing eG itself
|
||||
idsToRemove.forEach(id -> relations.remove(id));
|
||||
}
|
||||
|
||||
@ -443,9 +446,11 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
// avoid a error when persisting the deliberately invalid partner entry #99
|
||||
final var idsToRemove = new HashSet<Integer>();
|
||||
partners.forEach( (id, r) -> {
|
||||
// such a record
|
||||
if (r.getContact() == null || r.getContact().getLabel() == null ||
|
||||
r.getPerson() == null | r.getPerson().getPersonType() == null ) {
|
||||
final var partnerRole = r.getPartnerRel();
|
||||
|
||||
// such a record is in test data to test error messages
|
||||
if (partnerRole.getContact() == null || partnerRole.getContact().getLabel() == null ||
|
||||
partnerRole.getHolder() == null | partnerRole.getHolder().getPersonType() == null ) {
|
||||
idsToRemove.add(id);
|
||||
}
|
||||
});
|
||||
@ -460,10 +465,11 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
|
||||
// avoid a error when persisting the deliberately invalid partner entry #99
|
||||
final var idsToRemove = new HashSet<Integer>();
|
||||
debitors.forEach( (id, r) -> {
|
||||
// such a record
|
||||
if (r.getBillingContact() == null || r.getBillingContact().getLabel() == null ||
|
||||
r.getPartner().getPerson() == null | r.getPartner().getPerson().getPersonType() == null ) {
|
||||
debitors.forEach( (id, d) -> {
|
||||
final var debitorRel = d.getDebitorRel();
|
||||
if (debitorRel.getContact() == null || debitorRel.getContact().getLabel() == null ||
|
||||
debitorRel.getAnchor() == null || debitorRel.getAnchor().getPersonType() == null ||
|
||||
debitorRel.getHolder() == null || debitorRel.getHolder().getPersonType() == null ) {
|
||||
idsToRemove.add(id);
|
||||
}
|
||||
});
|
||||
@ -676,28 +682,33 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
.forEach(rec -> {
|
||||
final var person = HsOfficePersonEntity.builder().build();
|
||||
|
||||
final var partnerRelation = HsOfficeRelationEntity.builder()
|
||||
final var partnerRel = HsOfficeRelationEntity.builder()
|
||||
.holder(person)
|
||||
.type(HsOfficeRelationType.PARTNER)
|
||||
.anchor(mandant)
|
||||
.contact(null) // is set during contacts import depending on assigned roles
|
||||
.build();
|
||||
relations.put(relationId++, partnerRelation);
|
||||
relations.put(relationId++, partnerRel);
|
||||
|
||||
final var partner = HsOfficePartnerEntity.builder()
|
||||
.partnerNumber(rec.getInteger("member_id"))
|
||||
.details(HsOfficePartnerDetailsEntity.builder().build())
|
||||
.partnerRel(partnerRelation)
|
||||
.contact(null) // is set during contacts import depending on assigned roles
|
||||
.person(person)
|
||||
.partnerRel(partnerRel)
|
||||
.build();
|
||||
partners.put(rec.getInteger("bp_id"), partner);
|
||||
|
||||
final var debitorRel = HsOfficeRelationEntity.builder()
|
||||
.type(HsOfficeRelationType.DEBITOR)
|
||||
.anchor(partnerRel.getHolder())
|
||||
.holder(partnerRel.getHolder()) // currently debitor = partner
|
||||
.build();
|
||||
relations.put(relationId++, debitorRel);
|
||||
|
||||
final var debitor = HsOfficeDebitorEntity.builder()
|
||||
.partner(partner)
|
||||
.debitorNumberSuffix((byte) 0)
|
||||
.defaultPrefix(rec.getString("member_code").replace("hsh00-", ""))
|
||||
.partner(partner)
|
||||
.debitorRel(debitorRel)
|
||||
.defaultPrefix(rec.getString("member_code").replace("hsh00-", ""))
|
||||
.billable(rec.isEmpty("free") || rec.getString("free").equals("f"))
|
||||
.vatReverseCharge(rec.getBoolean("exempt_vat"))
|
||||
.vatBusiness("GROSS".equals(rec.getString("indicator_vat"))) // TODO: remove
|
||||
@ -718,7 +729,6 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
isBlank(rec.getString("member_until"))
|
||||
? HsOfficeReasonForTermination.NONE
|
||||
: HsOfficeReasonForTermination.UNKNOWN)
|
||||
.mainDebitor(debitor)
|
||||
.build();
|
||||
memberships.put(rec.getInteger("bp_id"), membership);
|
||||
}
|
||||
@ -844,9 +854,9 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
final var partner = partners.get(bpId);
|
||||
final var debitor = debitors.get(bpId);
|
||||
|
||||
final var partnerPerson = partner.getPerson();
|
||||
final var partnerPerson = partner.getPartnerRel().getHolder();
|
||||
if (containsPartnerRel(rec)) {
|
||||
initPerson(partner.getPerson(), rec);
|
||||
initPerson(partnerPerson, rec);
|
||||
}
|
||||
|
||||
HsOfficePersonEntity contactPerson = partnerPerson;
|
||||
@ -860,13 +870,12 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
initContact(contact, rec);
|
||||
|
||||
if (containsPartnerRel(rec)) {
|
||||
assertThat(partner.getContact()).isNull();
|
||||
partner.setContact(contact);
|
||||
assertThat(partner.getPartnerRel().getContact()).isNull();
|
||||
partner.getPartnerRel().setContact(contact);
|
||||
}
|
||||
if (containsRole(rec, "billing")) {
|
||||
assertThat(debitor.getBillingContact()).isNull();
|
||||
debitor.setBillingContact(contact);
|
||||
assertThat(debitor.getDebitorRel().getContact()).isNull();
|
||||
debitor.getDebitorRel().setContact(contact);
|
||||
}
|
||||
if (containsRole(rec, "operation")) {
|
||||
addRelation(partnerPerson, contactPerson, contact, HsOfficeRelationType.OPERATIONS);
|
||||
@ -896,13 +905,14 @@ public class ImportOfficeData extends ContextBasedTest {
|
||||
private static void optionallyAddMissingContractualRelations() {
|
||||
final var contractualMissing = new HashSet<Integer>();
|
||||
partners.forEach( (id, partner) -> {
|
||||
final var partnerPerson = partner.getPerson();
|
||||
final var partnerPerson = partner.getPartnerRel().getHolder();
|
||||
if (relations.values().stream()
|
||||
.filter(rel -> rel.getAnchor() == partnerPerson && rel.getType() == HsOfficeRelationType.REPRESENTATIVE)
|
||||
.findFirst().isEmpty()) {
|
||||
contractualMissing.add(partner.getPartnerNumber());
|
||||
}
|
||||
});
|
||||
assertThat(contractualMissing).containsOnly(19999); // deliberately wrong partner entry
|
||||
}
|
||||
private static boolean containsRole(final Record rec, final String role) {
|
||||
final var roles = rec.getString("roles");
|
||||
|
@ -7,9 +7,9 @@ import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.test.Accepts;
|
||||
import net.hostsharing.test.JpaAttempt;
|
||||
@ -41,7 +41,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
HsOfficePartnerRepository partnerRepo;
|
||||
|
||||
@Autowired
|
||||
HsOfficeRelationshipRepository relationshipRepository;
|
||||
HsOfficeRelationRepository relationRepository;
|
||||
|
||||
@Autowired
|
||||
HsOfficePersonRepository personRepo;
|
||||
@ -102,9 +102,9 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("""
|
||||
{
|
||||
"partnerNumber": "20002",
|
||||
"partnerRole": {
|
||||
"relAnchorUuid": "%s",
|
||||
"relHolderUuid": "%s",
|
||||
"partnerRel": {
|
||||
"anchorUuid": "%s",
|
||||
"holderUuid": "%s",
|
||||
"contactUuid": "%s"
|
||||
},
|
||||
"details": {
|
||||
@ -125,11 +125,11 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"partnerNumber": 20002,
|
||||
"partnerRole": {
|
||||
"relAnchor": { "tradeName": "Hostsharing eG" },
|
||||
"relHolder": { "tradeName": "Third OHG" },
|
||||
"relType": "PARTNER",
|
||||
"relMark": null,
|
||||
"partnerRel": {
|
||||
"anchor": { "tradeName": "Hostsharing eG" },
|
||||
"holder": { "tradeName": "Third OHG" },
|
||||
"type": "PARTNER",
|
||||
"mark": null,
|
||||
"contact": { "label": "fourth contact" }
|
||||
},
|
||||
"details": {
|
||||
@ -161,9 +161,9 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("""
|
||||
{
|
||||
"partnerNumber": "20003",
|
||||
"partnerRole": {
|
||||
"relAnchorUuid": "%s",
|
||||
"relHolderUuid": "%s",
|
||||
"partnerRel": {
|
||||
"anchorUuid": "%s",
|
||||
"holderUuid": "%s",
|
||||
"contactUuid": "%s"
|
||||
},
|
||||
"personUuid": "%s",
|
||||
@ -199,9 +199,9 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("""
|
||||
{
|
||||
"partnerNumber": "20004",
|
||||
"partnerRole": {
|
||||
"relAnchorUuid": "%s",
|
||||
"relHolderUuid": "%s",
|
||||
"partnerRel": {
|
||||
"anchorUuid": "%s",
|
||||
"holderUuid": "%s",
|
||||
"contactUuid": "%s"
|
||||
},
|
||||
"personUuid": "%s",
|
||||
@ -247,10 +247,10 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"partnerNumber": 10001,
|
||||
"partnerRole": {
|
||||
"relAnchor": { "tradeName": "Hostsharing eG" },
|
||||
"relHolder": { "tradeName": "First GmbH" },
|
||||
"relType": "PARTNER",
|
||||
"partnerRel": {
|
||||
"anchor": { "tradeName": "Hostsharing eG" },
|
||||
"holder": { "tradeName": "First GmbH" },
|
||||
"type": "PARTNER",
|
||||
"contact": { "label": "first contact" }
|
||||
},
|
||||
"details": {
|
||||
@ -295,8 +295,8 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.contentType("application/json")
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"partnerRole": {
|
||||
"relHolder": { "tradeName": "First GmbH" },
|
||||
"partnerRel": {
|
||||
"holder": { "tradeName": "First GmbH" },
|
||||
"contact": { "label": "first contact" }
|
||||
}
|
||||
}
|
||||
@ -323,7 +323,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("""
|
||||
{
|
||||
"partnerNumber": "20011",
|
||||
"partnerRoleUuid": "%s",
|
||||
"partnerRelUuid": "%s",
|
||||
"details": {
|
||||
"registrationOffice": "Temp Registergericht Aurich",
|
||||
"registrationNumber": "222222",
|
||||
@ -342,10 +342,10 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"partnerNumber": 20011,
|
||||
"partnerRole": {
|
||||
"relAnchor": { "tradeName": "Hostsharing eG" },
|
||||
"relHolder": { "tradeName": "Third OHG" },
|
||||
"relType": "PARTNER",
|
||||
"partnerRel": {
|
||||
"anchor": { "tradeName": "Hostsharing eG" },
|
||||
"holder": { "tradeName": "Third OHG" },
|
||||
"type": "PARTNER",
|
||||
"contact": { "label": "third contact" }
|
||||
},
|
||||
"details": {
|
||||
@ -365,8 +365,8 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isPresent().get()
|
||||
.matches(partner -> {
|
||||
assertThat(partner.getPartnerNumber()).isEqualTo(givenPartner.getPartnerNumber());
|
||||
assertThat(partner.getPartnerRole().getRelHolder().getTradeName()).isEqualTo("Third OHG");
|
||||
assertThat(partner.getPartnerRole().getContact().getLabel()).isEqualTo("third contact");
|
||||
assertThat(partner.getPartnerRel().getHolder().getTradeName()).isEqualTo("Third OHG");
|
||||
assertThat(partner.getPartnerRel().getContact().getLabel()).isEqualTo("third contact");
|
||||
assertThat(partner.getDetails().getRegistrationOffice()).isEqualTo("Temp Registergericht Aurich");
|
||||
assertThat(partner.getDetails().getRegistrationNumber()).isEqualTo("222222");
|
||||
assertThat(partner.getDetails().getBirthName()).isEqualTo("Maja Schmidt");
|
||||
@ -403,7 +403,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
.contentType(ContentType.JSON)
|
||||
.body("uuid", isUuidValid())
|
||||
.body("details.birthName", is("Maja Schmidt"));
|
||||
// TODO: assert partnerRole
|
||||
// TODO: assert partnerRel
|
||||
// .body("contact.label", is(givenPartner.getContact().getLabel()))
|
||||
// .body("person.tradeName", is(givenPartner.getPerson().getTradeName()));
|
||||
// @formatter:on
|
||||
@ -411,7 +411,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
// finally, the partner is actually updated
|
||||
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isPresent().get()
|
||||
.matches(person -> {
|
||||
// TODO: assert partnerRole
|
||||
// TODO: assert partnerRel
|
||||
// assertThat(person.getPerson().getTradeName()).isEqualTo(givenPartner.getPerson().getTradeName());
|
||||
// assertThat(person.getContact().getLabel()).isEqualTo(givenPartner.getContact().getLabel());
|
||||
assertThat(person.getDetails().getRegistrationOffice()).isEqualTo("Temp Registergericht Leer");
|
||||
@ -446,7 +446,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
|
||||
// then the given partner is gone
|
||||
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isEmpty();
|
||||
assertThat(relationshipRepository.findByUuid(givenPartner.getPartnerRole().getUuid())).isEmpty();
|
||||
assertThat(relationRepository.findByUuid(givenPartner.getPartnerRel().getUuid())).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -454,7 +454,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
void contactAdminUser_canNotDeleteRelatedPartner() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenPartner = givenSomeTemporaryPartnerBessler(20014);
|
||||
assertThat(givenPartner.getPartnerRole().getContact().getLabel()).isEqualTo("fourth contact");
|
||||
assertThat(givenPartner.getPartnerRel().getContact().getLabel()).isEqualTo("fourth contact");
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
@ -474,7 +474,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
void normalUser_canNotDeleteUnrelatedPartner() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenPartner = givenSomeTemporaryPartnerBessler(20015);
|
||||
assertThat(givenPartner.getPartnerRole().getContact().getLabel()).isEqualTo("fourth contact");
|
||||
assertThat(givenPartner.getPartnerRel().getContact().getLabel()).isEqualTo("fourth contact");
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
@ -490,7 +490,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
}
|
||||
}
|
||||
|
||||
private HsOfficeRelationshipEntity givenSomeTemporaryPartnerRel(
|
||||
private HsOfficeRelationEntity givenSomeTemporaryPartnerRel(
|
||||
final String partnerHolderName,
|
||||
final String contactName) {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
@ -499,22 +499,22 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
final var givenPerson = personRepo.findPersonByOptionalNameLike(partnerHolderName).stream().findFirst().orElseThrow();
|
||||
final var givenContact = contactRepo.findContactByOptionalLabelLike(contactName).stream().findFirst().orElseThrow();
|
||||
|
||||
final var partnerRole = new HsOfficeRelationshipEntity();
|
||||
partnerRole.setRelType(HsOfficeRelationshipType.PARTNER);
|
||||
partnerRole.setRelAnchor(givenMandantPerson);
|
||||
partnerRole.setRelHolder(givenPerson);
|
||||
partnerRole.setContact(givenContact);
|
||||
em.persist(partnerRole);
|
||||
return partnerRole;
|
||||
final var partnerRel = new HsOfficeRelationEntity();
|
||||
partnerRel.setType(HsOfficeRelationType.PARTNER);
|
||||
partnerRel.setAnchor(givenMandantPerson);
|
||||
partnerRel.setHolder(givenPerson);
|
||||
partnerRel.setContact(givenContact);
|
||||
em.persist(partnerRel);
|
||||
return partnerRel;
|
||||
}).assertSuccessful().returnedValue();
|
||||
}
|
||||
private HsOfficePartnerEntity givenSomeTemporaryPartnerBessler(final Integer partnerNumber) {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var partnerRole = em.merge(givenSomeTemporaryPartnerRel("Erben Bessler", "fourth contact"));
|
||||
final var partnerRel = em.merge(givenSomeTemporaryPartnerRel("Erben Bessler", "fourth contact"));
|
||||
|
||||
final var newPartner = HsOfficePartnerEntity.builder()
|
||||
.partnerRole(partnerRole)
|
||||
.partnerRel(partnerRel)
|
||||
.partnerNumber(partnerNumber)
|
||||
.details(HsOfficePartnerDetailsEntity.builder()
|
||||
.registrationOffice("Temp Registergericht Leer")
|
||||
@ -531,6 +531,6 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
cleanupAllNew(HsOfficePartnerEntity.class);
|
||||
|
||||
// TODO: should not be necessary anymore, once it's deleted via after delete trigger
|
||||
cleanupAllNew(HsOfficeRelationshipEntity.class);
|
||||
cleanupAllNew(HsOfficeRelationEntity.class);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package net.hostsharing.hsadminng.hs.office.partner;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
|
||||
import net.hostsharing.hsadminng.mapper.Mapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@ -54,7 +54,7 @@ class HsOfficePartnerControllerRestTest {
|
||||
HsOfficePartnerRepository partnerRepo;
|
||||
|
||||
@MockBean
|
||||
HsOfficeRelationshipRepository relationshipRepo;
|
||||
HsOfficeRelationRepository relationRepo;
|
||||
|
||||
@MockBean
|
||||
EntityManager em;
|
||||
@ -100,9 +100,9 @@ class HsOfficePartnerControllerRestTest {
|
||||
.content("""
|
||||
{
|
||||
"partnerNumber": "20002",
|
||||
"partnerRole": {
|
||||
"relAnchorUuid": "%s",
|
||||
"relHolderUuid": "%s",
|
||||
"partnerRel": {
|
||||
"anchorUuid": "%s",
|
||||
"holderUuid": "%s",
|
||||
"contactUuid": "%s"
|
||||
},
|
||||
"personUuid": "%s",
|
||||
@ -137,9 +137,9 @@ class HsOfficePartnerControllerRestTest {
|
||||
.content("""
|
||||
{
|
||||
"partnerNumber": "20002",
|
||||
"partnerRole": {
|
||||
"relAnchorUuid": "%s",
|
||||
"relHolderUuid": "%s",
|
||||
"partnerRel": {
|
||||
"anchorUuid": "%s",
|
||||
"holderUuid": "%s",
|
||||
"contactUuid": "%s"
|
||||
},
|
||||
"personUuid": "%s",
|
||||
@ -175,11 +175,11 @@ class HsOfficePartnerControllerRestTest {
|
||||
when(partnerRepo.findByUuid(givenPartnerUuid)).thenReturn(Optional.of(partnerMock));
|
||||
when(partnerRepo.deleteByUuid(givenPartnerUuid)).thenReturn(0);
|
||||
|
||||
final UUID givenRelationshipUuid = UUID.randomUUID();
|
||||
when(partnerMock.getPartnerRole()).thenReturn(HsOfficeRelationshipEntity.builder()
|
||||
.uuid(givenRelationshipUuid)
|
||||
final UUID givenRelationUuid = UUID.randomUUID();
|
||||
when(partnerMock.getPartnerRel()).thenReturn(HsOfficeRelationEntity.builder()
|
||||
.uuid(givenRelationUuid)
|
||||
.build());
|
||||
when(relationshipRepo.deleteByUuid(givenRelationshipUuid)).thenReturn(0);
|
||||
when(relationRepo.deleteByUuid(givenRelationUuid)).thenReturn(0);
|
||||
|
||||
// when
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
|
@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.office.partner;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.test.PatchUnitTestBase;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
@ -48,8 +48,8 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
|
||||
@BeforeEach
|
||||
void initMocks() {
|
||||
lenient().when(em.getReference(eq(HsOfficeRelationshipEntity.class), any())).thenAnswer(invocation ->
|
||||
HsOfficeRelationshipEntity.builder().uuid(invocation.getArgument(1)).build());
|
||||
lenient().when(em.getReference(eq(HsOfficeRelationEntity.class), any())).thenAnswer(invocation ->
|
||||
HsOfficeRelationEntity.builder().uuid(invocation.getArgument(1)).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,8 +57,8 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
final var entity = HsOfficePartnerEntity.builder()
|
||||
.uuid(INITIAL_PARTNER_UUID)
|
||||
.partnerNumber(12345)
|
||||
.partnerRole(HsOfficeRelationshipEntity.builder()
|
||||
.relHolder(givenInitialPerson)
|
||||
.partnerRel(HsOfficeRelationEntity.builder()
|
||||
.holder(givenInitialPerson)
|
||||
.contact(givenInitialContact)
|
||||
.build())
|
||||
.details(givenInitialDetails)
|
||||
@ -80,19 +80,19 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
protected Stream<Property> propertyTestDescriptors() {
|
||||
return Stream.of(
|
||||
new JsonNullableProperty<>(
|
||||
"partnerRole",
|
||||
HsOfficePartnerPatchResource::setPartnerRoleUuid,
|
||||
"partnerRel",
|
||||
HsOfficePartnerPatchResource::setPartnerRelUuid,
|
||||
PATCHED_PARTNER_ROLE_UUID,
|
||||
HsOfficePartnerEntity::setPartnerRole,
|
||||
newPartnerRole(PATCHED_PARTNER_ROLE_UUID))
|
||||
HsOfficePartnerEntity::setPartnerRel,
|
||||
newPartnerRel(PATCHED_PARTNER_ROLE_UUID))
|
||||
.notNullable()
|
||||
);
|
||||
}
|
||||
|
||||
private static HsOfficeRelationshipEntity newPartnerRole(final UUID uuid) {
|
||||
final var newPartnerRole = HsOfficeRelationshipEntity.builder()
|
||||
private static HsOfficeRelationEntity newPartnerRel(final UUID uuid) {
|
||||
final var newPartnerRel = HsOfficeRelationEntity.builder()
|
||||
.uuid(uuid)
|
||||
.build();
|
||||
return newPartnerRole;
|
||||
return newPartnerRel;
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package net.hostsharing.hsadminng.hs.office.partner;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -13,13 +13,13 @@ class HsOfficePartnerEntityUnitTest {
|
||||
|
||||
private final HsOfficePartnerEntity givenPartner = HsOfficePartnerEntity.builder()
|
||||
.partnerNumber(12345)
|
||||
.partnerRole(HsOfficeRelationshipEntity.builder()
|
||||
.relAnchor(HsOfficePersonEntity.builder()
|
||||
.partnerRel(HsOfficeRelationEntity.builder()
|
||||
.anchor(HsOfficePersonEntity.builder()
|
||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||
.tradeName("Hostsharing eG")
|
||||
.build())
|
||||
.relType(HsOfficeRelationshipType.PARTNER)
|
||||
.relHolder(HsOfficePersonEntity.builder()
|
||||
.type(HsOfficeRelationType.PARTNER)
|
||||
.holder(HsOfficePersonEntity.builder()
|
||||
.personType(HsOfficePersonType.LEGAL_PERSON)
|
||||
.tradeName("some trade name")
|
||||
.build())
|
||||
|
@ -3,9 +3,9 @@ package net.hostsharing.hsadminng.hs.office.partner;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacObjectRepository;
|
||||
@ -43,7 +43,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
HsOfficePartnerRepository partnerRepo;
|
||||
|
||||
@Autowired
|
||||
HsOfficeRelationshipRepository relationshipRepo;
|
||||
HsOfficeRelationRepository relationRepo;
|
||||
|
||||
@Autowired
|
||||
HsOfficePersonRepository personRepo;
|
||||
@ -77,13 +77,13 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var count = partnerRepo.count();
|
||||
final var partnerRole = givenSomeTemporaryHostsharingPartnerRole("First GmbH", "first contact");
|
||||
final var partnerRel = givenSomeTemporaryHostsharingPartnerRel("First GmbH", "first contact");
|
||||
|
||||
// when
|
||||
final var result = attempt(em, () -> {
|
||||
final var newPartner = HsOfficePartnerEntity.builder()
|
||||
.partnerNumber(20031)
|
||||
.partnerRole(partnerRole)
|
||||
.partnerRel(partnerRel)
|
||||
.details(HsOfficePartnerDetailsEntity.builder().build())
|
||||
.build();
|
||||
return partnerRepo.save(newPartner);
|
||||
@ -113,17 +113,17 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth contact").get(0);
|
||||
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
|
||||
|
||||
final var newRelationship = HsOfficeRelationshipEntity.builder()
|
||||
.relHolder(givenPartnerPerson)
|
||||
.relType(HsOfficeRelationshipType.PARTNER)
|
||||
.relAnchor(givenMandantPerson)
|
||||
final var newRelation = HsOfficeRelationEntity.builder()
|
||||
.holder(givenPartnerPerson)
|
||||
.type(HsOfficeRelationType.PARTNER)
|
||||
.anchor(givenMandantPerson)
|
||||
.contact(givenContact)
|
||||
.build();
|
||||
relationshipRepo.save(newRelationship);
|
||||
relationRepo.save(newRelation);
|
||||
|
||||
final var newPartner = HsOfficePartnerEntity.builder()
|
||||
.partnerNumber(20032)
|
||||
.partnerRole(newRelationship)
|
||||
.partnerRel(newRelation)
|
||||
.details(HsOfficePartnerDetailsEntity.builder().build())
|
||||
.build();
|
||||
return partnerRepo.save(newPartner);
|
||||
@ -132,10 +132,10 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
// then
|
||||
assertThat(distinctRoleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(Array.from(
|
||||
initialRoleNames,
|
||||
"hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.owner",
|
||||
"hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.admin",
|
||||
"hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.agent",
|
||||
"hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.tenant"));
|
||||
"hs_office_relation#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.owner",
|
||||
"hs_office_relation#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.admin",
|
||||
"hs_office_relation#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.agent",
|
||||
"hs_office_relation#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.tenant"));
|
||||
assertThat(distinctGrantDisplaysOf(rawGrantRepo.findAll()))
|
||||
.map(s -> s.replace("ErbenBesslerMelBessler", "EBess"))
|
||||
.map(s -> s.replace("fourthcontact", "4th"))
|
||||
@ -143,42 +143,42 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
.containsExactlyInAnyOrder(distinct(fromFormatted(
|
||||
initialGrantNames,
|
||||
// FIXME: this entry is wrong in existance and format
|
||||
"{ grant perm INSERT on relationship#HostsharingeG-with-PARTNER-EBess to role relationship#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
|
||||
"{ grant perm INSERT on relation#HostsharingeG-with-PARTNER-EBess to role relation#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
|
||||
|
||||
// permissions on partner
|
||||
"{ grant perm DELETE on partner#P-20032 to role relationship#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
|
||||
"{ grant perm UPDATE on partner#P-20032 to role relationship#HostsharingeG-with-PARTNER-EBess.agent by system and assume }",
|
||||
"{ grant perm SELECT on partner#P-20032 to role relationship#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
|
||||
"{ grant perm DELETE on partner#P-20032 to role relation#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
|
||||
"{ grant perm UPDATE on partner#P-20032 to role relation#HostsharingeG-with-PARTNER-EBess.agent by system and assume }",
|
||||
"{ grant perm SELECT on partner#P-20032 to role relation#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
|
||||
|
||||
// permissions on partner-details
|
||||
"{ grant perm DELETE on partner_details#P-20032-details to role relationship#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
|
||||
"{ grant perm UPDATE on partner_details#P-20032-details to role relationship#HostsharingeG-with-PARTNER-EBess.agent by system and assume }",
|
||||
"{ grant perm SELECT on partner_details#P-20032-details to role relationship#HostsharingeG-with-PARTNER-EBess.agent by system and assume }",
|
||||
"{ grant perm DELETE on partner_details#P-20032-details to role relation#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
|
||||
"{ grant perm UPDATE on partner_details#P-20032-details to role relation#HostsharingeG-with-PARTNER-EBess.agent by system and assume }",
|
||||
"{ grant perm SELECT on partner_details#P-20032-details to role relation#HostsharingeG-with-PARTNER-EBess.agent by system and assume }",
|
||||
|
||||
// permissions on partner-relationship
|
||||
"{ grant perm DELETE on relationship#HostsharingeG-with-PARTNER-EBess to role relationship#HostsharingeG-with-PARTNER-EBess.owner by system and assume }",
|
||||
"{ grant perm UPDATE on relationship#HostsharingeG-with-PARTNER-EBess to role relationship#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
|
||||
"{ grant perm SELECT on relationship#HostsharingeG-with-PARTNER-EBess to role relationship#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
|
||||
// permissions on partner-relation
|
||||
"{ grant perm DELETE on relation#HostsharingeG-with-PARTNER-EBess to role relation#HostsharingeG-with-PARTNER-EBess.owner by system and assume }",
|
||||
"{ grant perm UPDATE on relation#HostsharingeG-with-PARTNER-EBess to role relation#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
|
||||
"{ grant perm SELECT on relation#HostsharingeG-with-PARTNER-EBess to role relation#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
|
||||
|
||||
// relationship owner
|
||||
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.owner to role global#global.admin by system and assume }",
|
||||
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.owner to user superuser-alex@hostsharing.net by relationship#HostsharingeG-with-PARTNER-EBess.owner and assume }",
|
||||
// relation owner
|
||||
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.owner to role global#global.admin by system and assume }",
|
||||
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.owner to user superuser-alex@hostsharing.net by relation#HostsharingeG-with-PARTNER-EBess.owner and assume }",
|
||||
|
||||
// relationship admin
|
||||
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.admin to role relationship#HostsharingeG-with-PARTNER-EBess.owner by system and assume }",
|
||||
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.admin to role person#HostsharingeG.admin by system and assume }",
|
||||
// relation admin
|
||||
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.admin to role relation#HostsharingeG-with-PARTNER-EBess.owner by system and assume }",
|
||||
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.admin to role person#HostsharingeG.admin by system and assume }",
|
||||
|
||||
// relationship agent
|
||||
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.agent to role person#EBess.admin by system and assume }",
|
||||
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.agent to role relationship#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
|
||||
// relation agent
|
||||
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.agent to role person#EBess.admin by system and assume }",
|
||||
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.agent to role relation#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
|
||||
|
||||
// relationship tenant
|
||||
"{ grant role contact#4th.referrer to role relationship#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
|
||||
"{ grant role person#EBess.referrer to role relationship#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
|
||||
"{ grant role person#HostsharingeG.referrer to role relationship#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
|
||||
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role contact#4th.admin by system and assume }",
|
||||
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role person#EBess.admin by system and assume }",
|
||||
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role relationship#HostsharingeG-with-PARTNER-EBess.agent by system and assume }",
|
||||
// relation tenant
|
||||
"{ grant role contact#4th.referrer to role relation#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
|
||||
"{ grant role person#EBess.referrer to role relation#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
|
||||
"{ grant role person#HostsharingeG.referrer to role relation#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
|
||||
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.tenant to role contact#4th.admin by system and assume }",
|
||||
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.tenant to role person#EBess.admin by system and assume }",
|
||||
"{ grant role relation#HostsharingeG-with-PARTNER-EBess.tenant to role relation#HostsharingeG-with-PARTNER-EBess.agent by system and assume }",
|
||||
null)));
|
||||
}
|
||||
|
||||
@ -273,7 +273,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
givenPartner.setPartnerRole(givenSomeTemporaryHostsharingPartnerRole("Third OHG", "sixth contact"));
|
||||
givenPartner.setPartnerRel(givenSomeTemporaryHostsharingPartnerRel("Third OHG", "sixth contact"));
|
||||
return partnerRepo.save(givenPartner);
|
||||
});
|
||||
|
||||
@ -327,7 +327,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net",
|
||||
"hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.tenant");
|
||||
"hs_office_relation#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.tenant");
|
||||
givenPartner.getDetails().setBirthName("new birthname");
|
||||
return partnerRepo.save(givenPartner);
|
||||
});
|
||||
@ -335,7 +335,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
// then
|
||||
result.assertExceptionWithRootCauseMessage(JpaSystemException.class,
|
||||
// FIXME: the assumed role should appear, but it does not:
|
||||
//"[403] insert into hs_office_partner_details not allowed for current subjects {hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.tenant}");
|
||||
//"[403] insert into hs_office_partner_details not allowed for current subjects {hs_office_relation#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.tenant}");
|
||||
"[403] insert into hs_office_partner_details not allowed for current subjects");
|
||||
}
|
||||
|
||||
@ -457,11 +457,11 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
final Integer partnerNumber, final String person, final String contact) {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var partnerRole = givenSomeTemporaryHostsharingPartnerRole(person, contact);
|
||||
final var partnerRel = givenSomeTemporaryHostsharingPartnerRel(person, contact);
|
||||
|
||||
final var newPartner = HsOfficePartnerEntity.builder()
|
||||
.partnerNumber(partnerNumber)
|
||||
.partnerRole(partnerRole)
|
||||
.partnerRel(partnerRel)
|
||||
.details(HsOfficePartnerDetailsEntity.builder().build())
|
||||
.build();
|
||||
|
||||
@ -469,19 +469,19 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
}).assertSuccessful().returnedValue();
|
||||
}
|
||||
|
||||
private HsOfficeRelationshipEntity givenSomeTemporaryHostsharingPartnerRole(final String person, final String contact) {
|
||||
private HsOfficeRelationEntity givenSomeTemporaryHostsharingPartnerRel(final String person, final String contact) {
|
||||
final var givenMandantorPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
|
||||
final var givenPartnerPerson = personRepo.findPersonByOptionalNameLike(person).get(0);
|
||||
final var givenContact = contactRepo.findContactByOptionalLabelLike(contact).get(0);
|
||||
|
||||
final var partnerRole = HsOfficeRelationshipEntity.builder()
|
||||
.relHolder(givenPartnerPerson)
|
||||
.relType(HsOfficeRelationshipType.PARTNER)
|
||||
.relAnchor(givenMandantorPerson)
|
||||
final var partnerRel = HsOfficeRelationEntity.builder()
|
||||
.holder(givenPartnerPerson)
|
||||
.type(HsOfficeRelationType.PARTNER)
|
||||
.anchor(givenMandantorPerson)
|
||||
.contact(givenContact)
|
||||
.build();
|
||||
relationshipRepo.save(partnerRole);
|
||||
return partnerRole;
|
||||
relationRepo.save(partnerRel);
|
||||
return partnerRel;
|
||||
}
|
||||
|
||||
void exactlyThesePartnersAreReturned(final List<HsOfficePartnerEntity> actualResult, final String... partnerNames) {
|
||||
|
@ -2,8 +2,8 @@ package net.hostsharing.hsadminng.hs.office.partner;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.office.person.HsOfficePersonType.LEGAL_PERSON;
|
||||
|
||||
@ -14,14 +14,14 @@ public class TestHsOfficePartner {
|
||||
static public HsOfficePartnerEntity hsOfficePartnerWithLegalPerson(final String tradeName) {
|
||||
return HsOfficePartnerEntity.builder()
|
||||
.partnerNumber(10001)
|
||||
.partnerRole(
|
||||
HsOfficeRelationshipEntity.builder()
|
||||
.relHolder(HsOfficePersonEntity.builder()
|
||||
.partnerRel(
|
||||
HsOfficeRelationEntity.builder()
|
||||
.holder(HsOfficePersonEntity.builder()
|
||||
.personType(LEGAL_PERSON)
|
||||
.tradeName("Hostsharing eG")
|
||||
.build())
|
||||
.relType(HsOfficeRelationshipType.PARTNER)
|
||||
.relHolder(HsOfficePersonEntity.builder()
|
||||
.type(HsOfficeRelationType.PARTNER)
|
||||
.holder(HsOfficePersonEntity.builder()
|
||||
.personType(LEGAL_PERSON)
|
||||
.tradeName(tradeName)
|
||||
.build())
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.hostsharing.hsadminng.hs.office.relationship;
|
||||
package net.hostsharing.hsadminng.hs.office.relation;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
@ -7,7 +7,7 @@ import net.hostsharing.test.Accepts;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationshipTypeResource;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelationTypeResource;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
||||
import net.hostsharing.test.JpaAttempt;
|
||||
import org.json.JSONException;
|
||||
@ -31,7 +31,7 @@ import static org.hamcrest.Matchers.startsWith;
|
||||
classes = { HsadminNgApplication.class, JpaAttempt.class }
|
||||
)
|
||||
@Transactional
|
||||
class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
class HsOfficeRelationControllerAcceptanceTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
public static final UUID GIVEN_NON_EXISTING_HOLDER_PERSON_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
@LocalServerPort
|
||||
@ -44,7 +44,7 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
|
||||
Context contextMock;
|
||||
|
||||
@Autowired
|
||||
HsOfficeRelationshipRepository relationshipRepo;
|
||||
HsOfficeRelationRepository relationRepo;
|
||||
|
||||
@Autowired
|
||||
HsOfficePersonRepository personRepo;
|
||||
@ -56,11 +56,11 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
|
||||
JpaAttempt jpaAttempt;
|
||||
|
||||
@Nested
|
||||
@Accepts({ "Relationship:F(Find)" })
|
||||
class ListRelationships {
|
||||
@Accepts({ "Relation:F(Find)" })
|
||||
class ListRelations {
|
||||
|
||||
@Test
|
||||
void globalAdmin_withoutAssumedRoles_canViewAllRelationshipsOfGivenPersonAndType_ifNoCriteriaGiven() throws JSONException {
|
||||
void globalAdmin_withoutAssumedRoles_canViewAllRelationsOfGivenPersonAndType_ifNoCriteriaGiven() throws JSONException {
|
||||
|
||||
// given
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
@ -71,45 +71,45 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
|
||||
.header("current-user", "superuser-alex@hostsharing.net")
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/relationships?personUuid=%s&relationshipType=%s"
|
||||
.formatted(givenPerson.getUuid(), HsOfficeRelationshipTypeResource.PARTNER))
|
||||
.get("http://localhost/api/hs/office/relations?personUuid=%s&relationType=%s"
|
||||
.formatted(givenPerson.getUuid(), HsOfficeRelationTypeResource.PARTNER))
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", lenientlyEquals("""
|
||||
[
|
||||
{
|
||||
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
|
||||
"relHolder": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH" },
|
||||
"relType": "PARTNER",
|
||||
"relMark": null,
|
||||
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
|
||||
"holder": { "personType": "LEGAL_PERSON", "tradeName": "First GmbH" },
|
||||
"type": "PARTNER",
|
||||
"mark": null,
|
||||
"contact": { "label": "first contact" }
|
||||
},
|
||||
{
|
||||
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
|
||||
"relHolder": { "personType": "LEGAL_PERSON", "tradeName": "Fourth eG" },
|
||||
"relType": "PARTNER",
|
||||
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
|
||||
"holder": { "personType": "LEGAL_PERSON", "tradeName": "Fourth eG" },
|
||||
"type": "PARTNER",
|
||||
"contact": { "label": "fourth contact" }
|
||||
},
|
||||
{
|
||||
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
|
||||
"relHolder": { "personType": "LEGAL_PERSON", "tradeName": "Second e.K.", "givenName": "Peter", "familyName": "Smith" },
|
||||
"relType": "PARTNER",
|
||||
"relMark": null,
|
||||
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
|
||||
"holder": { "personType": "LEGAL_PERSON", "tradeName": "Second e.K.", "givenName": "Peter", "familyName": "Smith" },
|
||||
"type": "PARTNER",
|
||||
"mark": null,
|
||||
"contact": { "label": "second contact" }
|
||||
},
|
||||
{
|
||||
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
|
||||
"relHolder": { "personType": "NATURAL_PERSON", "givenName": "Peter", "familyName": "Smith" },
|
||||
"relType": "PARTNER",
|
||||
"relMark": null,
|
||||
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
|
||||
"holder": { "personType": "NATURAL_PERSON", "givenName": "Peter", "familyName": "Smith" },
|
||||
"type": "PARTNER",
|
||||
"mark": null,
|
||||
"contact": { "label": "sixth contact" }
|
||||
},
|
||||
{
|
||||
"relAnchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
|
||||
"relHolder": { "personType": "INCORPORATED_FIRM", "tradeName": "Third OHG" },
|
||||
"relType": "PARTNER",
|
||||
"relMark": null,
|
||||
"anchor": { "personType": "LEGAL_PERSON", "tradeName": "Hostsharing eG" },
|
||||
"holder": { "personType": "INCORPORATED_FIRM", "tradeName": "Third OHG" },
|
||||
"type": "PARTNER",
|
||||
"mark": null,
|
||||
"contact": { "label": "third contact" }
|
||||
}
|
||||
]
|
||||
@ -119,11 +119,11 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
|
||||
}
|
||||
|
||||
@Nested
|
||||
@Accepts({ "Relationship:C(Create)" })
|
||||
class AddRelationship {
|
||||
@Accepts({ "Relation:C(Create)" })
|
||||
class AddRelation {
|
||||
|
||||
@Test
|
||||
void globalAdmin_withoutAssumedRole_canAddRelationship() {
|
||||
void globalAdmin_withoutAssumedRole_canAddRelation() {
|
||||
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
|
||||
@ -136,38 +136,38 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"relType": "%s",
|
||||
"relAnchorUuid": "%s",
|
||||
"relHolderUuid": "%s",
|
||||
"type": "%s",
|
||||
"anchorUuid": "%s",
|
||||
"holderUuid": "%s",
|
||||
"contactUuid": "%s"
|
||||
}
|
||||
""".formatted(
|
||||
HsOfficeRelationshipTypeResource.ACCOUNTING,
|
||||
HsOfficeRelationTypeResource.DEBITOR,
|
||||
givenAnchorPerson.getUuid(),
|
||||
givenHolderPerson.getUuid(),
|
||||
givenContact.getUuid()))
|
||||
.port(port)
|
||||
.when()
|
||||
.post("http://localhost/api/hs/office/relationships")
|
||||
.post("http://localhost/api/hs/office/relations")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(201)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("uuid", isUuidValid())
|
||||
.body("relType", is("ACCOUNTING"))
|
||||
.body("relAnchor.tradeName", is("Third OHG"))
|
||||
.body("relHolder.givenName", is("Paul"))
|
||||
.body("type", is("DEBITOR"))
|
||||
.body("anchor.tradeName", is("Third OHG"))
|
||||
.body("holder.givenName", is("Paul"))
|
||||
.body("contact.label", is("second contact"))
|
||||
.header("Location", startsWith("http://localhost"))
|
||||
.extract().header("Location"); // @formatter:on
|
||||
|
||||
// finally, the new relationship can be accessed under the generated UUID
|
||||
final var newUserUuid = toCleanup(HsOfficeRelationshipEntity.class, UUID.fromString(
|
||||
// finally, the new relation can be accessed under the generated UUID
|
||||
final var newUserUuid = toCleanup(HsOfficeRelationEntity.class, UUID.fromString(
|
||||
location.substring(location.lastIndexOf('/') + 1)));
|
||||
assertThat(newUserUuid).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void globalAdmin_canNotAddRelationship_ifAnchorPersonDoesNotExist() {
|
||||
void globalAdmin_canNotAddRelation_ifAnchorPersonDoesNotExist() {
|
||||
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenAnchorPersonUuid = GIVEN_NON_EXISTING_HOLDER_PERSON_UUID;
|
||||
@ -180,27 +180,27 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"relType": "%s",
|
||||
"relAnchorUuid": "%s",
|
||||
"relHolderUuid": "%s",
|
||||
"type": "%s",
|
||||
"anchorUuid": "%s",
|
||||
"holderUuid": "%s",
|
||||
"contactUuid": "%s"
|
||||
}
|
||||
""".formatted(
|
||||
HsOfficeRelationshipTypeResource.ACCOUNTING,
|
||||
HsOfficeRelationTypeResource.DEBITOR,
|
||||
givenAnchorPersonUuid,
|
||||
givenHolderPerson.getUuid(),
|
||||
givenContact.getUuid()))
|
||||
.port(port)
|
||||
.when()
|
||||
.post("http://localhost/api/hs/office/relationships")
|
||||
.post("http://localhost/api/hs/office/relations")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(404)
|
||||
.body("message", is("cannot find relAnchorUuid " + GIVEN_NON_EXISTING_HOLDER_PERSON_UUID));
|
||||
.body("message", is("cannot find anchorUuid " + GIVEN_NON_EXISTING_HOLDER_PERSON_UUID));
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
void globalAdmin_canNotAddRelationship_ifHolderPersonDoesNotExist() {
|
||||
void globalAdmin_canNotAddRelation_ifHolderPersonDoesNotExist() {
|
||||
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
|
||||
@ -212,27 +212,27 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"relType": "%s",
|
||||
"relAnchorUuid": "%s",
|
||||
"relHolderUuid": "%s",
|
||||
"type": "%s",
|
||||
"anchorUuid": "%s",
|
||||
"holderUuid": "%s",
|
||||
"contactUuid": "%s"
|
||||
}
|
||||
""".formatted(
|
||||
HsOfficeRelationshipTypeResource.ACCOUNTING,
|
||||
HsOfficeRelationTypeResource.DEBITOR,
|
||||
givenAnchorPerson.getUuid(),
|
||||
GIVEN_NON_EXISTING_HOLDER_PERSON_UUID,
|
||||
givenContact.getUuid()))
|
||||
.port(port)
|
||||
.when()
|
||||
.post("http://localhost/api/hs/office/relationships")
|
||||
.post("http://localhost/api/hs/office/relations")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(404)
|
||||
.body("message", is("cannot find relHolderUuid " + GIVEN_NON_EXISTING_HOLDER_PERSON_UUID));
|
||||
.body("message", is("cannot find holderUuid " + GIVEN_NON_EXISTING_HOLDER_PERSON_UUID));
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
void globalAdmin_canNotAddRelationship_ifContactDoesNotExist() {
|
||||
void globalAdmin_canNotAddRelation_ifContactDoesNotExist() {
|
||||
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
|
||||
@ -245,19 +245,19 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"relType": "%s",
|
||||
"relAnchorUuid": "%s",
|
||||
"relHolderUuid": "%s",
|
||||
"type": "%s",
|
||||
"anchorUuid": "%s",
|
||||
"holderUuid": "%s",
|
||||
"contactUuid": "%s"
|
||||
}
|
||||
""".formatted(
|
||||
HsOfficeRelationshipTypeResource.ACCOUNTING,
|
||||
HsOfficeRelationTypeResource.DEBITOR,
|
||||
givenAnchorPerson.getUuid(),
|
||||
givenHolderPerson.getUuid(),
|
||||
givenContactUuid))
|
||||
.port(port)
|
||||
.when()
|
||||
.post("http://localhost/api/hs/office/relationships")
|
||||
.post("http://localhost/api/hs/office/relations")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(404)
|
||||
.body("message", is("cannot find contactUuid 00000000-0000-0000-0000-000000000000"));
|
||||
@ -266,97 +266,97 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
|
||||
}
|
||||
|
||||
@Nested
|
||||
@Accepts({ "Relationship:R(Read)" })
|
||||
class GetRelationship {
|
||||
@Accepts({ "Relation:R(Read)" })
|
||||
class GetRelation {
|
||||
|
||||
@Test
|
||||
void globalAdmin_withoutAssumedRole_canGetArbitraryRelationship() {
|
||||
void globalAdmin_withoutAssumedRole_canGetArbitraryRelation() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final UUID givenRelationshipUuid = findRelationship("First", "Firby").getUuid();
|
||||
final UUID givenRelationUuid = findRelation("First", "Firby").getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "superuser-alex@hostsharing.net")
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/relationships/" + givenRelationshipUuid)
|
||||
.get("http://localhost/api/hs/office/relations/" + givenRelationUuid)
|
||||
.then().log().body().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"relAnchor": { "tradeName": "First GmbH" },
|
||||
"relHolder": { "familyName": "Firby" },
|
||||
"anchor": { "tradeName": "First GmbH" },
|
||||
"holder": { "familyName": "Firby" },
|
||||
"contact": { "label": "first contact" }
|
||||
}
|
||||
""")); // @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
@Accepts({ "Relationship:X(Access Control)" })
|
||||
void normalUser_canNotGetUnrelatedRelationship() {
|
||||
@Accepts({ "Relation:X(Access Control)" })
|
||||
void normalUser_canNotGetUnrelatedRelation() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final UUID givenRelationshipUuid = findRelationship("First", "Firby").getUuid();
|
||||
final UUID givenRelationUuid = findRelation("First", "Firby").getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "selfregistered-user-drew@hostsharing.org")
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/relationships/" + givenRelationshipUuid)
|
||||
.get("http://localhost/api/hs/office/relations/" + givenRelationUuid)
|
||||
.then().log().body().assertThat()
|
||||
.statusCode(404); // @formatter:on
|
||||
}
|
||||
|
||||
@Test
|
||||
@Accepts({ "Relationship:X(Access Control)" })
|
||||
void contactAdminUser_canGetRelatedRelationship() {
|
||||
@Accepts({ "Relation:X(Access Control)" })
|
||||
void contactAdminUser_canGetRelatedRelation() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenRelationship = findRelationship("First", "Firby");
|
||||
assertThat(givenRelationship.getContact().getLabel()).isEqualTo("first contact");
|
||||
final var givenRelation = findRelation("First", "Firby");
|
||||
assertThat(givenRelation.getContact().getLabel()).isEqualTo("first contact");
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "contact-admin@firstcontact.example.com")
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/office/relationships/" + givenRelationship.getUuid())
|
||||
.get("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
|
||||
.then().log().body().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"relAnchor": { "tradeName": "First GmbH" },
|
||||
"relHolder": { "familyName": "Firby" },
|
||||
"anchor": { "tradeName": "First GmbH" },
|
||||
"holder": { "familyName": "Firby" },
|
||||
"contact": { "label": "first contact" }
|
||||
}
|
||||
""")); // @formatter:on
|
||||
}
|
||||
}
|
||||
|
||||
private HsOfficeRelationshipEntity findRelationship(
|
||||
private HsOfficeRelationEntity findRelation(
|
||||
final String anchorPersonName,
|
||||
final String holderPersoneName) {
|
||||
final var anchorPersonUuid = personRepo.findPersonByOptionalNameLike(anchorPersonName).get(0).getUuid();
|
||||
final var holderPersonUuid = personRepo.findPersonByOptionalNameLike(holderPersoneName).get(0).getUuid();
|
||||
final var givenRelationship = relationshipRepo
|
||||
.findRelationshipRelatedToPersonUuid(anchorPersonUuid)
|
||||
final var givenRelation = relationRepo
|
||||
.findRelationRelatedToPersonUuid(anchorPersonUuid)
|
||||
.stream()
|
||||
.filter(r -> r.getRelHolder().getUuid().equals(holderPersonUuid))
|
||||
.filter(r -> r.getHolder().getUuid().equals(holderPersonUuid))
|
||||
.findFirst().orElseThrow();
|
||||
return givenRelationship;
|
||||
return givenRelation;
|
||||
}
|
||||
|
||||
@Nested
|
||||
@Accepts({ "Relationship:U(Update)" })
|
||||
class PatchRelationship {
|
||||
@Accepts({ "Relation:U(Update)" })
|
||||
class PatchRelation {
|
||||
|
||||
@Test
|
||||
void globalAdmin_withoutAssumedRole_canPatchContactOfArbitraryRelationship() {
|
||||
void globalAdmin_withoutAssumedRole_canPatchContactOfArbitraryRelation() {
|
||||
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenRelationship = givenSomeTemporaryRelationshipBessler();
|
||||
assertThat(givenRelationship.getContact().getLabel()).isEqualTo("seventh contact");
|
||||
final var givenRelation = givenSomeTemporaryRelationBessler();
|
||||
assertThat(givenRelation.getContact().getLabel()).isEqualTo("seventh contact");
|
||||
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0);
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
@ -370,109 +370,109 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
|
||||
""".formatted(givenContact.getUuid()))
|
||||
.port(port)
|
||||
.when()
|
||||
.patch("http://localhost/api/hs/office/relationships/" + givenRelationship.getUuid())
|
||||
.patch("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("uuid", isUuidValid())
|
||||
.body("relType", is("REPRESENTATIVE"))
|
||||
.body("relAnchor.tradeName", is("Erben Bessler"))
|
||||
.body("relHolder.familyName", is("Winkler"))
|
||||
.body("type", is("REPRESENTATIVE"))
|
||||
.body("anchor.tradeName", is("Erben Bessler"))
|
||||
.body("holder.familyName", is("Winkler"))
|
||||
.body("contact.label", is("fourth contact"));
|
||||
// @formatter:on
|
||||
|
||||
// finally, the relationship is actually updated
|
||||
// finally, the relation is actually updated
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
assertThat(relationshipRepo.findByUuid(givenRelationship.getUuid())).isPresent().get()
|
||||
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isPresent().get()
|
||||
.matches(rel -> {
|
||||
assertThat(rel.getRelAnchor().getTradeName()).contains("Bessler");
|
||||
assertThat(rel.getRelHolder().getFamilyName()).contains("Winkler");
|
||||
assertThat(rel.getAnchor().getTradeName()).contains("Bessler");
|
||||
assertThat(rel.getHolder().getFamilyName()).contains("Winkler");
|
||||
assertThat(rel.getContact().getLabel()).isEqualTo("fourth contact");
|
||||
assertThat(rel.getRelType()).isEqualTo(HsOfficeRelationshipType.REPRESENTATIVE);
|
||||
assertThat(rel.getType()).isEqualTo(HsOfficeRelationType.REPRESENTATIVE);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@Accepts({ "Relationship:D(Delete)" })
|
||||
class DeleteRelationship {
|
||||
@Accepts({ "Relation:D(Delete)" })
|
||||
class DeleteRelation {
|
||||
|
||||
@Test
|
||||
void globalAdmin_withoutAssumedRole_canDeleteArbitraryRelationship() {
|
||||
void globalAdmin_withoutAssumedRole_canDeleteArbitraryRelation() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenRelationship = givenSomeTemporaryRelationshipBessler();
|
||||
final var givenRelation = givenSomeTemporaryRelationBessler();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "superuser-alex@hostsharing.net")
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/relationships/" + givenRelationship.getUuid())
|
||||
.delete("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
|
||||
.then().log().body().assertThat()
|
||||
.statusCode(204); // @formatter:on
|
||||
|
||||
// then the given relationship is gone
|
||||
assertThat(relationshipRepo.findByUuid(givenRelationship.getUuid())).isEmpty();
|
||||
// then the given relation is gone
|
||||
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Accepts({ "Relationship:X(Access Control)" })
|
||||
void contactAdminUser_canNotDeleteRelatedRelationship() {
|
||||
@Accepts({ "Relation:X(Access Control)" })
|
||||
void contactAdminUser_canNotDeleteRelatedRelation() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenRelationship = givenSomeTemporaryRelationshipBessler();
|
||||
assertThat(givenRelationship.getContact().getLabel()).isEqualTo("seventh contact");
|
||||
final var givenRelation = givenSomeTemporaryRelationBessler();
|
||||
assertThat(givenRelation.getContact().getLabel()).isEqualTo("seventh contact");
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "contact-admin@seventhcontact.example.com")
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/relationships/" + givenRelationship.getUuid())
|
||||
.delete("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
|
||||
.then().log().body().assertThat()
|
||||
.statusCode(403); // @formatter:on
|
||||
|
||||
// then the given relationship is still there
|
||||
assertThat(relationshipRepo.findByUuid(givenRelationship.getUuid())).isNotEmpty();
|
||||
// then the given relation is still there
|
||||
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Accepts({ "Relationship:X(Access Control)" })
|
||||
void normalUser_canNotDeleteUnrelatedRelationship() {
|
||||
@Accepts({ "Relation:X(Access Control)" })
|
||||
void normalUser_canNotDeleteUnrelatedRelation() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenRelationship = givenSomeTemporaryRelationshipBessler();
|
||||
assertThat(givenRelationship.getContact().getLabel()).isEqualTo("seventh contact");
|
||||
final var givenRelation = givenSomeTemporaryRelationBessler();
|
||||
assertThat(givenRelation.getContact().getLabel()).isEqualTo("seventh contact");
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "selfregistered-user-drew@hostsharing.org")
|
||||
.port(port)
|
||||
.when()
|
||||
.delete("http://localhost/api/hs/office/relationships/" + givenRelationship.getUuid())
|
||||
.delete("http://localhost/api/hs/office/relations/" + givenRelation.getUuid())
|
||||
.then().log().body().assertThat()
|
||||
.statusCode(404); // @formatter:on
|
||||
|
||||
// then the given relationship is still there
|
||||
assertThat(relationshipRepo.findByUuid(givenRelationship.getUuid())).isNotEmpty();
|
||||
// then the given relation is still there
|
||||
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isNotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
private HsOfficeRelationshipEntity givenSomeTemporaryRelationshipBessler() {
|
||||
private HsOfficeRelationEntity givenSomeTemporaryRelationBessler() {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
|
||||
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Winkler").get(0);
|
||||
final var givenContact = contactRepo.findContactByOptionalLabelLike("seventh contact").get(0);
|
||||
final var newRelationship = HsOfficeRelationshipEntity.builder()
|
||||
.relType(HsOfficeRelationshipType.REPRESENTATIVE)
|
||||
.relAnchor(givenAnchorPerson)
|
||||
.relHolder(givenHolderPerson)
|
||||
final var newRelation = HsOfficeRelationEntity.builder()
|
||||
.type(HsOfficeRelationType.REPRESENTATIVE)
|
||||
.anchor(givenAnchorPerson)
|
||||
.holder(givenHolderPerson)
|
||||
.contact(givenContact)
|
||||
.build();
|
||||
|
||||
assertThat(toCleanup(relationshipRepo.save(newRelationship))).isEqualTo(newRelationship);
|
||||
assertThat(toCleanup(relationRepo.save(newRelation))).isEqualTo(newRelation);
|
||||
|
||||
return newRelationship;
|
||||
return newRelation;
|
||||
}).assertSuccessful().returnedValue();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.hostsharing.hsadminng.hs.office.relationship;
|
||||
package net.hostsharing.hsadminng.hs.office.relation;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
|
||||
@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@DataJpaTest
|
||||
@Import( { Context.class, JpaAttempt.class })
|
||||
class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
|
||||
class HsOfficeRelationRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
|
||||
|
||||
@Autowired
|
||||
HsOfficeRelationshipRepository relationshipRepo;
|
||||
HsOfficeRelationRepository relationRepo;
|
||||
|
||||
@Autowired
|
||||
HsOfficePersonRepository personRepo;
|
||||
@ -58,13 +58,13 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
|
||||
HttpServletRequest request;
|
||||
|
||||
@Nested
|
||||
class CreateRelationship {
|
||||
class CreateRelation {
|
||||
|
||||
@Test
|
||||
public void testHostsharingAdmin_withoutAssumedRole_canCreateNewRelationship() {
|
||||
public void testHostsharingAdmin_withoutAssumedRole_canCreateNewRelation() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var count = relationshipRepo.count();
|
||||
final var count = relationRepo.count();
|
||||
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Bessler").stream()
|
||||
.filter(p -> p.getPersonType() == UNINCORPORATED_FIRM)
|
||||
.findFirst().orElseThrow();
|
||||
@ -76,20 +76,20 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
|
||||
|
||||
// when
|
||||
final var result = attempt(em, () -> {
|
||||
final var newRelationship = HsOfficeRelationshipEntity.builder()
|
||||
.relAnchor(givenAnchorPerson)
|
||||
.relHolder(givenHolderPerson)
|
||||
.relType(HsOfficeRelationshipType.REPRESENTATIVE)
|
||||
final var newRelation = HsOfficeRelationEntity.builder()
|
||||
.anchor(givenAnchorPerson)
|
||||
.holder(givenHolderPerson)
|
||||
.type(HsOfficeRelationType.REPRESENTATIVE)
|
||||
.contact(givenContact)
|
||||
.build();
|
||||
return toCleanup(relationshipRepo.save(newRelationship));
|
||||
return toCleanup(relationRepo.save(newRelation));
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertSuccessful();
|
||||
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeRelationshipEntity::getUuid).isNotNull();
|
||||
assertThatRelationshipIsPersisted(result.returnedValue());
|
||||
assertThat(relationshipRepo.count()).isEqualTo(count + 1);
|
||||
assertThat(result.returnedValue()).isNotNull().extracting(HsOfficeRelationEntity::getUuid).isNotNull();
|
||||
assertThatRelationIsPersisted(result.returnedValue());
|
||||
assertThat(relationRepo.count()).isEqualTo(count + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -109,62 +109,62 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
|
||||
.findFirst().orElseThrow();
|
||||
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth contact").stream()
|
||||
.findFirst().orElseThrow();
|
||||
final var newRelationship = HsOfficeRelationshipEntity.builder()
|
||||
.relAnchor(givenAnchorPerson)
|
||||
.relHolder(givenHolderPerson)
|
||||
.relType(HsOfficeRelationshipType.REPRESENTATIVE)
|
||||
final var newRelation = HsOfficeRelationEntity.builder()
|
||||
.anchor(givenAnchorPerson)
|
||||
.holder(givenHolderPerson)
|
||||
.type(HsOfficeRelationType.REPRESENTATIVE)
|
||||
.contact(givenContact)
|
||||
.build();
|
||||
return toCleanup(relationshipRepo.save(newRelationship));
|
||||
return toCleanup(relationRepo.save(newRelation));
|
||||
});
|
||||
|
||||
// then
|
||||
assertThat(distinctRoleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(Array.from(
|
||||
initialRoleNames,
|
||||
"hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner",
|
||||
"hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin",
|
||||
"hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.agent",
|
||||
"hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant"));
|
||||
"hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner",
|
||||
"hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin",
|
||||
"hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.agent",
|
||||
"hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant"));
|
||||
assertThat(distinctGrantDisplaysOf(rawGrantRepo.findAll())).containsExactlyInAnyOrder(Array.fromFormatted(
|
||||
initialGrantNames,
|
||||
"{ grant perm INSERT on hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert to role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin by system and assume }",
|
||||
"{ grant perm INSERT on hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert to role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin by system and assume }",
|
||||
|
||||
"{ grant perm DELETE on hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert to role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner by system and assume }",
|
||||
"{ grant role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner to role global#global.admin by system and assume }",
|
||||
"{ grant role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner to user superuser-alex@hostsharing.net by hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner and assume }",
|
||||
"{ grant perm DELETE on hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert to role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner by system and assume }",
|
||||
"{ grant role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner to role global#global.admin by system and assume }",
|
||||
"{ grant role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner to user superuser-alex@hostsharing.net by hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner and assume }",
|
||||
|
||||
"{ grant perm UPDATE on hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert to role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin by system and assume }",
|
||||
"{ grant role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin to role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner by system and assume }",
|
||||
"{ grant role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin to role hs_office_person#ErbenBesslerMelBessler.admin by system and assume }",
|
||||
"{ grant perm UPDATE on hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert to role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin by system and assume }",
|
||||
"{ grant role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin to role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.owner by system and assume }",
|
||||
"{ grant role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin to role hs_office_person#ErbenBesslerMelBessler.admin by system and assume }",
|
||||
|
||||
"{ grant role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.agent to role hs_office_person#BesslerBert.admin by system and assume }",
|
||||
"{ grant role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.agent to role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin by system and assume }",
|
||||
"{ grant role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.agent to role hs_office_person#BesslerBert.admin by system and assume }",
|
||||
"{ grant role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.agent to role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.admin by system and assume }",
|
||||
|
||||
"{ grant perm SELECT on hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert to role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant by system and assume }",
|
||||
"{ grant role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant to role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.agent by system and assume }",
|
||||
"{ grant role hs_office_person#BesslerBert.referrer to role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant by system and assume }",
|
||||
"{ grant role hs_office_person#ErbenBesslerMelBessler.referrer to role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant by system and assume }",
|
||||
"{ grant role hs_office_contact#fourthcontact.referrer to role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant by system and assume }",
|
||||
"{ grant perm SELECT on hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert to role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant by system and assume }",
|
||||
"{ grant role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant to role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.agent by system and assume }",
|
||||
"{ grant role hs_office_person#BesslerBert.referrer to role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant by system and assume }",
|
||||
"{ grant role hs_office_person#ErbenBesslerMelBessler.referrer to role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant by system and assume }",
|
||||
"{ grant role hs_office_contact#fourthcontact.referrer to role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant by system and assume }",
|
||||
|
||||
// REPRESENTATIVE holder person -> (represented) anchor person
|
||||
"{ grant role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant to role hs_office_contact#fourthcontact.admin by system and assume }",
|
||||
"{ grant role hs_office_relationship#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant to role hs_office_person#BesslerBert.admin by system and assume }",
|
||||
"{ grant role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant to role hs_office_contact#fourthcontact.admin by system and assume }",
|
||||
"{ grant role hs_office_relation#ErbenBesslerMelBessler-with-REPRESENTATIVE-BesslerBert.tenant to role hs_office_person#BesslerBert.admin by system and assume }",
|
||||
|
||||
null)
|
||||
);
|
||||
}
|
||||
|
||||
private void assertThatRelationshipIsPersisted(final HsOfficeRelationshipEntity saved) {
|
||||
final var found = relationshipRepo.findByUuid(saved.getUuid());
|
||||
private void assertThatRelationIsPersisted(final HsOfficeRelationEntity saved) {
|
||||
final var found = relationRepo.findByUuid(saved.getUuid());
|
||||
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class FindAllRelationships {
|
||||
class FindAllRelations {
|
||||
|
||||
@Test
|
||||
public void globalAdmin_withoutAssumedRole_canViewAllRelationshipsOfArbitraryPerson() {
|
||||
public void globalAdmin_withoutAssumedRole_canViewAllRelationsOfArbitraryPerson() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var person = personRepo.findPersonByOptionalNameLike("Smith").stream()
|
||||
@ -172,18 +172,18 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
|
||||
.findFirst().orElseThrow();
|
||||
|
||||
// when
|
||||
final var result = relationshipRepo.findRelationshipRelatedToPersonUuid(person.getUuid());
|
||||
final var result = relationRepo.findRelationRelatedToPersonUuid(person.getUuid());
|
||||
|
||||
// then
|
||||
allTheseRelationshipsAreReturned(
|
||||
allTheseRelationsAreReturned(
|
||||
result,
|
||||
"rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='NP Smith, Peter', contact='sixth contact')",
|
||||
"rel(relAnchor='LP Second e.K.', relType='REPRESENTATIVE', relHolder='NP Smith, Peter', contact='second contact')",
|
||||
"rel(relAnchor='IF Third OHG', relType='SUBSCRIBER', relMark='members-announce', relHolder='NP Smith, Peter', contact='third contact')");
|
||||
"rel(anchor='LP Hostsharing eG', type='PARTNER', holder='NP Smith, Peter', contact='sixth contact')",
|
||||
"rel(anchor='LP Second e.K.', type='REPRESENTATIVE', holder='NP Smith, Peter', contact='second contact')",
|
||||
"rel(anchor='IF Third OHG', type='SUBSCRIBER', mark='members-announce', holder='NP Smith, Peter', contact='third contact')");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalUser_canViewRelationshipsOfOwnedPersons() {
|
||||
public void normalUser_canViewRelationsOfOwnedPersons() {
|
||||
// given:
|
||||
context("person-SmithPeter@example.com");
|
||||
final var person = personRepo.findPersonByOptionalNameLike("Smith").stream()
|
||||
@ -191,124 +191,124 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
|
||||
.findFirst().orElseThrow();
|
||||
|
||||
// when:
|
||||
final var result = relationshipRepo.findRelationshipRelatedToPersonUuid(person.getUuid());
|
||||
final var result = relationRepo.findRelationRelatedToPersonUuid(person.getUuid());
|
||||
|
||||
// then:
|
||||
exactlyTheseRelationshipsAreReturned(
|
||||
exactlyTheseRelationsAreReturned(
|
||||
result,
|
||||
"rel(relAnchor='LP Second e.K.', relType='REPRESENTATIVE', relHolder='NP Smith, Peter', contact='second contact')",
|
||||
"rel(relAnchor='IF Third OHG', relType='SUBSCRIBER', relMark='members-announce', relHolder='NP Smith, Peter', contact='third contact')",
|
||||
"rel(relAnchor='LP Hostsharing eG', relType='PARTNER', relHolder='NP Smith, Peter', contact='sixth contact')",
|
||||
"rel(relAnchor='NP Smith, Peter', relType='ACCOUNTING', relHolder='NP Smith, Peter', contact='third contact')");
|
||||
"rel(anchor='LP Second e.K.', type='REPRESENTATIVE', holder='NP Smith, Peter', contact='second contact')",
|
||||
"rel(anchor='IF Third OHG', type='SUBSCRIBER', mark='members-announce', holder='NP Smith, Peter', contact='third contact')",
|
||||
"rel(anchor='LP Hostsharing eG', type='PARTNER', holder='NP Smith, Peter', contact='sixth contact')",
|
||||
"rel(anchor='NP Smith, Peter', type='DEBITOR', holder='NP Smith, Peter', contact='third contact')");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class UpdateRelationship {
|
||||
class UpdateRelation {
|
||||
|
||||
@Test
|
||||
public void hostsharingAdmin_withoutAssumedRole_canUpdateContactOfArbitraryRelationship() {
|
||||
public void hostsharingAdmin_withoutAssumedRole_canUpdateContactOfArbitraryRelation() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
|
||||
final var givenRelation = givenSomeTemporaryRelationBessler(
|
||||
"Bert", "fifth contact");
|
||||
assertThatRelationshipIsVisibleForUserWithRole(
|
||||
givenRelationship,
|
||||
assertThatRelationIsVisibleForUserWithRole(
|
||||
givenRelation,
|
||||
"hs_office_person#ErbenBesslerMelBessler.admin");
|
||||
assertThatRelationshipActuallyInDatabase(givenRelationship);
|
||||
assertThatRelationActuallyInDatabase(givenRelation);
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var givenContact = contactRepo.findContactByOptionalLabelLike("sixth contact").stream().findFirst().orElseThrow();
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
givenRelationship.setContact(givenContact);
|
||||
return toCleanup(relationshipRepo.save(givenRelationship));
|
||||
givenRelation.setContact(givenContact);
|
||||
return toCleanup(relationRepo.save(givenRelation));
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertSuccessful();
|
||||
assertThat(result.returnedValue().getContact().getLabel()).isEqualTo("sixth contact");
|
||||
assertThatRelationshipIsVisibleForUserWithRole(
|
||||
assertThatRelationIsVisibleForUserWithRole(
|
||||
result.returnedValue(),
|
||||
"global#global.admin");
|
||||
assertThatRelationshipIsVisibleForUserWithRole(
|
||||
assertThatRelationIsVisibleForUserWithRole(
|
||||
result.returnedValue(),
|
||||
"hs_office_contact#sixthcontact.admin");
|
||||
|
||||
assertThatRelationshipIsNotVisibleForUserWithRole(
|
||||
assertThatRelationIsNotVisibleForUserWithRole(
|
||||
result.returnedValue(),
|
||||
"hs_office_contact#fifthcontact.admin");
|
||||
|
||||
relationshipRepo.deleteByUuid(givenRelationship.getUuid());
|
||||
relationRepo.deleteByUuid(givenRelation.getUuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void relHolderAdmin_canNotUpdateRelatedRelationship() {
|
||||
public void holderAdmin_canNotUpdateRelatedRelation() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
|
||||
final var givenRelation = givenSomeTemporaryRelationBessler(
|
||||
"Anita", "eighth");
|
||||
assertThatRelationshipIsVisibleForUserWithRole(
|
||||
givenRelationship,
|
||||
assertThatRelationIsVisibleForUserWithRole(
|
||||
givenRelation,
|
||||
"hs_office_person#BesslerAnita.admin");
|
||||
assertThatRelationshipActuallyInDatabase(givenRelationship);
|
||||
assertThatRelationActuallyInDatabase(givenRelation);
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net", "hs_office_person#BesslerAnita.admin");
|
||||
givenRelationship.setContact(null);
|
||||
return relationshipRepo.save(givenRelationship);
|
||||
givenRelation.setContact(null);
|
||||
return relationRepo.save(givenRelation);
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertExceptionWithRootCauseMessage(JpaSystemException.class,
|
||||
"[403] Subject ", " is not allowed to update hs_office_relationship uuid");
|
||||
"[403] Subject ", " is not allowed to update hs_office_relation uuid");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contactAdmin_canNotUpdateRelatedRelationship() {
|
||||
public void contactAdmin_canNotUpdateRelatedRelation() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
|
||||
final var givenRelation = givenSomeTemporaryRelationBessler(
|
||||
"Anita", "ninth");
|
||||
assertThatRelationshipIsVisibleForUserWithRole(
|
||||
givenRelationship,
|
||||
assertThatRelationIsVisibleForUserWithRole(
|
||||
givenRelation,
|
||||
"hs_office_contact#ninthcontact.admin");
|
||||
assertThatRelationshipActuallyInDatabase(givenRelationship);
|
||||
assertThatRelationActuallyInDatabase(givenRelation);
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net", "hs_office_contact#ninthcontact.admin");
|
||||
givenRelationship.setContact(null); // TODO
|
||||
return relationshipRepo.save(givenRelationship);
|
||||
givenRelation.setContact(null); // TODO
|
||||
return relationRepo.save(givenRelation);
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertExceptionWithRootCauseMessage(JpaSystemException.class,
|
||||
"[403] Subject ", " is not allowed to update hs_office_relationship uuid");
|
||||
"[403] Subject ", " is not allowed to update hs_office_relation uuid");
|
||||
}
|
||||
|
||||
private void assertThatRelationshipActuallyInDatabase(final HsOfficeRelationshipEntity saved) {
|
||||
final var found = relationshipRepo.findByUuid(saved.getUuid());
|
||||
private void assertThatRelationActuallyInDatabase(final HsOfficeRelationEntity saved) {
|
||||
final var found = relationRepo.findByUuid(saved.getUuid());
|
||||
assertThat(found).isNotEmpty().get().isNotSameAs(saved).usingRecursiveComparison().isEqualTo(saved);
|
||||
}
|
||||
|
||||
private void assertThatRelationshipIsVisibleForUserWithRole(
|
||||
final HsOfficeRelationshipEntity entity,
|
||||
private void assertThatRelationIsVisibleForUserWithRole(
|
||||
final HsOfficeRelationEntity entity,
|
||||
final String assumedRoles) {
|
||||
jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net", assumedRoles);
|
||||
assertThatRelationshipActuallyInDatabase(entity);
|
||||
assertThatRelationActuallyInDatabase(entity);
|
||||
}).assertSuccessful();
|
||||
}
|
||||
|
||||
private void assertThatRelationshipIsNotVisibleForUserWithRole(
|
||||
final HsOfficeRelationshipEntity entity,
|
||||
private void assertThatRelationIsNotVisibleForUserWithRole(
|
||||
final HsOfficeRelationEntity entity,
|
||||
final String assumedRoles) {
|
||||
jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net", assumedRoles);
|
||||
final var found = relationshipRepo.findByUuid(entity.getUuid());
|
||||
final var found = relationRepo.findByUuid(entity.getUuid());
|
||||
assertThat(found).isEmpty();
|
||||
}).assertSuccessful();
|
||||
}
|
||||
@ -318,63 +318,63 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
|
||||
class DeleteByUuid {
|
||||
|
||||
@Test
|
||||
public void globalAdmin_withoutAssumedRole_canDeleteAnyRelationship() {
|
||||
public void globalAdmin_withoutAssumedRole_canDeleteAnyRelation() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net", null);
|
||||
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
|
||||
final var givenRelation = givenSomeTemporaryRelationBessler(
|
||||
"Anita", "tenth");
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
relationshipRepo.deleteByUuid(givenRelationship.getUuid());
|
||||
relationRepo.deleteByUuid(givenRelation.getUuid());
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertSuccessful();
|
||||
assertThat(jpaAttempt.transacted(() -> {
|
||||
context("superuser-fran@hostsharing.net", null);
|
||||
return relationshipRepo.findByUuid(givenRelationship.getUuid());
|
||||
return relationRepo.findByUuid(givenRelation.getUuid());
|
||||
}).assertSuccessful().returnedValue()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contactUser_canViewButNotDeleteTheirRelatedRelationship() {
|
||||
public void contactUser_canViewButNotDeleteTheirRelatedRelation() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net", null);
|
||||
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
|
||||
final var givenRelation = givenSomeTemporaryRelationBessler(
|
||||
"Anita", "eleventh");
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("contact-admin@eleventhcontact.example.com");
|
||||
assertThat(relationshipRepo.findByUuid(givenRelationship.getUuid())).isPresent();
|
||||
relationshipRepo.deleteByUuid(givenRelationship.getUuid());
|
||||
assertThat(relationRepo.findByUuid(givenRelation.getUuid())).isPresent();
|
||||
relationRepo.deleteByUuid(givenRelation.getUuid());
|
||||
});
|
||||
|
||||
// then
|
||||
result.assertExceptionWithRootCauseMessage(
|
||||
JpaSystemException.class,
|
||||
"[403] Subject ", " not allowed to delete hs_office_relationship");
|
||||
"[403] Subject ", " not allowed to delete hs_office_relation");
|
||||
assertThat(jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
return relationshipRepo.findByUuid(givenRelationship.getUuid());
|
||||
return relationRepo.findByUuid(givenRelation.getUuid());
|
||||
}).assertSuccessful().returnedValue()).isPresent(); // still there
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletingARelationshipAlsoDeletesRelatedRolesAndGrants() {
|
||||
public void deletingARelationAlsoDeletesRelatedRolesAndGrants() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var initialRoleNames = Array.from(distinctRoleNamesOf(rawRoleRepo.findAll()));
|
||||
final var initialGrantNames = Array.from(distinctGrantDisplaysOf(rawGrantRepo.findAll()));
|
||||
final var givenRelationship = givenSomeTemporaryRelationshipBessler(
|
||||
final var givenRelation = givenSomeTemporaryRelationBessler(
|
||||
"Anita", "twelfth");
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
return relationshipRepo.deleteByUuid(givenRelationship.getUuid());
|
||||
return relationRepo.deleteByUuid(givenRelation.getUuid());
|
||||
});
|
||||
|
||||
// then
|
||||
@ -391,7 +391,7 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
|
||||
final var query = em.createNativeQuery("""
|
||||
select currentTask, targetTable, targetOp
|
||||
from tx_journal_v
|
||||
where targettable = 'hs_office_relationship';
|
||||
where targettable = 'hs_office_relation';
|
||||
""");
|
||||
|
||||
// when
|
||||
@ -399,40 +399,40 @@ class HsOfficeRelationshipRepositoryIntegrationTest extends ContextBasedTestWith
|
||||
|
||||
// then
|
||||
assertThat(customerLogEntries).map(Arrays::toString).contains(
|
||||
"[creating relationship test-data HostsharingeG-FirstGmbH, hs_office_relationship, INSERT]",
|
||||
"[creating relationship test-data FirstGmbH-Firby, hs_office_relationship, INSERT]");
|
||||
"[creating relation test-data HostsharingeG-FirstGmbH, hs_office_relation, INSERT]",
|
||||
"[creating relation test-data FirstGmbH-Firby, hs_office_relation, INSERT]");
|
||||
}
|
||||
|
||||
private HsOfficeRelationshipEntity givenSomeTemporaryRelationshipBessler(final String holderPerson, final String contact) {
|
||||
private HsOfficeRelationEntity givenSomeTemporaryRelationBessler(final String holderPerson, final String contact) {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var givenAnchorPerson = personRepo.findPersonByOptionalNameLike("Erben Bessler").get(0);
|
||||
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike(holderPerson).get(0);
|
||||
final var givenContact = contactRepo.findContactByOptionalLabelLike(contact).get(0);
|
||||
final var newRelationship = HsOfficeRelationshipEntity.builder()
|
||||
.relType(HsOfficeRelationshipType.REPRESENTATIVE)
|
||||
.relAnchor(givenAnchorPerson)
|
||||
.relHolder(givenHolderPerson)
|
||||
final var newRelation = HsOfficeRelationEntity.builder()
|
||||
.type(HsOfficeRelationType.REPRESENTATIVE)
|
||||
.anchor(givenAnchorPerson)
|
||||
.holder(givenHolderPerson)
|
||||
.contact(givenContact)
|
||||
.build();
|
||||
|
||||
return toCleanup(relationshipRepo.save(newRelationship));
|
||||
return toCleanup(relationRepo.save(newRelation));
|
||||
}).assertSuccessful().returnedValue();
|
||||
}
|
||||
|
||||
void exactlyTheseRelationshipsAreReturned(
|
||||
final List<HsOfficeRelationshipEntity> actualResult,
|
||||
final String... relationshipNames) {
|
||||
void exactlyTheseRelationsAreReturned(
|
||||
final List<HsOfficeRelationEntity> actualResult,
|
||||
final String... relationNames) {
|
||||
assertThat(actualResult)
|
||||
.extracting(HsOfficeRelationshipEntity::toString)
|
||||
.containsExactlyInAnyOrder(relationshipNames);
|
||||
.extracting(HsOfficeRelationEntity::toString)
|
||||
.containsExactlyInAnyOrder(relationNames);
|
||||
}
|
||||
|
||||
void allTheseRelationshipsAreReturned(
|
||||
final List<HsOfficeRelationshipEntity> actualResult,
|
||||
final String... relationshipNames) {
|
||||
void allTheseRelationsAreReturned(
|
||||
final List<HsOfficeRelationEntity> actualResult,
|
||||
final String... relationNames) {
|
||||
assertThat(actualResult)
|
||||
.extracting(HsOfficeRelationshipEntity::toString)
|
||||
.contains(relationshipNames);
|
||||
.extracting(HsOfficeRelationEntity::toString)
|
||||
.contains(relationNames);
|
||||
}
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isPresent().get()
|
||||
.matches(mandate -> {
|
||||
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(D-1000111: rel(relAnchor='LP First GmbH', relType='ACCOUNTING', relHolder='LP First GmbH'), fir)");
|
||||
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(D-1000111: rel(anchor='LP First GmbH', type='DEBITOR', holder='LP First GmbH'), fir)");
|
||||
assertThat(mandate.getBankAccount().toShortString()).isEqualTo("First GmbH");
|
||||
assertThat(mandate.getReference()).isEqualTo("temp ref CAT Z - patched");
|
||||
assertThat(mandate.getValidFrom()).isEqualTo("2020-06-05");
|
||||
@ -398,7 +398,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
// finally, the sepaMandate is actually updated
|
||||
assertThat(sepaMandateRepo.findByUuid(givenSepaMandate.getUuid())).isPresent().get()
|
||||
.matches(mandate -> {
|
||||
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(D-1000111: rel(relAnchor='LP First GmbH', relType='ACCOUNTING', relHolder='LP First GmbH'), fir)");
|
||||
assertThat(mandate.getDebitor().toString()).isEqualTo("debitor(D-1000111: rel(anchor='LP First GmbH', type='DEBITOR', holder='LP First GmbH'), fir)");
|
||||
assertThat(mandate.getBankAccount().toShortString()).isEqualTo("First GmbH");
|
||||
assertThat(mandate.getReference()).isEqualTo("temp ref CAT Z");
|
||||
assertThat(mandate.getValidity().asString()).isEqualTo("[2022-11-01,2023-01-01)");
|
||||
@ -503,8 +503,8 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenDebitor = debitorRepo.findDebitorByDebitorNumber(debitorNumber).get(0);
|
||||
final var bankAccountHolder = ofNullable(givenDebitor.getPartner().getPartnerRole().getRelHolder().getTradeName())
|
||||
.orElse(givenDebitor.getPartner().getPartnerRole().getRelHolder().getFamilyName());
|
||||
final var bankAccountHolder = ofNullable(givenDebitor.getPartner().getPartnerRel().getHolder().getTradeName())
|
||||
.orElse(givenDebitor.getPartner().getPartnerRel().getHolder().getFamilyName());
|
||||
final var givenBankAccount = bankAccountRepo.findByOptionalHolderLike(bankAccountHolder).get(0);
|
||||
final var newSepaMandate = HsOfficeSepaMandateEntity.builder()
|
||||
.uuid(UUID.randomUUID())
|
||||
|
@ -138,14 +138,14 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
|
||||
// agent
|
||||
"{ grant role bankaccount#DE02600501010002034304.referrer to role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).agent by system and assume }",
|
||||
"{ grant role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).agent to role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).admin by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FirstGmbH.agent to role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).agent by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FirstGmbH.agent to role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).agent by system and assume }",
|
||||
|
||||
// referrer
|
||||
"{ grant perm SELECT on sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01) to role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).referrer by system and assume }",
|
||||
"{ grant role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).referrer to role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).agent by system and assume }",
|
||||
"{ grant role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).referrer to role bankaccount#DE02600501010002034304.admin by system and assume }",
|
||||
"{ grant role relationship#FirstGmbH-with-ACCOUNTING-FirstGmbH.tenant to role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).referrer by system and assume }",
|
||||
"{ grant role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).referrer to role relationship#FirstGmbH-with-ACCOUNTING-FirstGmbH.agent by system and assume }",
|
||||
"{ grant role relation#FirstGmbH-with-DEBITOR-FirstGmbH.tenant to role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).referrer by system and assume }",
|
||||
"{ grant role sepamandate#DE02600501010002034304-[2020-01-01,2023-01-01).referrer to role relation#FirstGmbH-with-DEBITOR-FirstGmbH.agent by system and assume }",
|
||||
|
||||
null));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user