1
0

hs-office-partner-details

This commit is contained in:
Michael Hoennig
2022-10-20 20:11:31 +02:00
parent dc0835fa25
commit e1895e3735
26 changed files with 573 additions and 212 deletions

View File

@@ -1,6 +1,7 @@
package net.hostsharing.hsadminng.hs.office.debitor;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerDetailsEntity;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerEntity;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import org.junit.jupiter.api.Test;
@@ -17,7 +18,8 @@ class HsOfficeDebitorEntityTest {
.person(HsOfficePersonEntity.builder()
.tradeName("some trade name")
.build())
.birthName("some birth name")
.details(HsOfficePartnerDetailsEntity.builder().birthName("some birth name").build())
.build())
.billingContact(HsOfficeContactEntity.builder().label("some label").build())
.build();

View File

@@ -66,7 +66,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
class CreateDebitor {
@Test
public void testHostsharingAdmin_withoutAssumedRole_canCreateNewDebitor() {
public void globalAdmin_canCreateNewDebitor() {
// given
context("superuser-alex@hostsharing.net");
final var count = debitorRepo.count();
@@ -170,7 +170,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
class FindByOptionalName {
@Test
public void globalAdmin_withoutAssumedRole_canViewAllDebitors() {
public void globalAdmin_canViewAllDebitors() {
// given
context("superuser-alex@hostsharing.net");
@@ -219,7 +219,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
class FindByDebitorNumberLike {
@Test
public void globalAdmin_withoutAssumedRole_canViewAllDebitors() {
public void globalAdmin_canViewAllDebitors() {
// given
context("superuser-alex@hostsharing.net");
@@ -235,7 +235,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
class FindByNameLike {
@Test
public void globalAdmin_withoutAssumedRole_canViewAllDebitors() {
public void globalAdmin_canViewAllDebitors() {
// given
context("superuser-alex@hostsharing.net");
@@ -251,7 +251,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
class UpdateDebitor {
@Test
public void hostsharingAdmin_withoutAssumedRole_canUpdateArbitraryDebitor() {
public void globalAdmin_canUpdateArbitraryDebitor() {
// given
context("superuser-alex@hostsharing.net");
final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "fifth contact");
@@ -336,7 +336,8 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
private void assertThatDebitorActuallyInDatabase(final HsOfficeDebitorEntity saved) {
final var found = debitorRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().isNotSameAs(saved).usingRecursiveComparison().isEqualTo(saved);
assertThat(found).isNotEmpty().get().isNotSameAs(saved)
.extracting(Object::toString).isEqualTo(saved.toString());
}
private void assertThatDebitorIsVisibleForUserWithRole(
@@ -363,7 +364,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTest {
class DeleteByUuid {
@Test
public void globalAdmin_withoutAssumedRole_canDeleteAnyDebitor() {
public void globalAdmin_canDeleteAnyDebitor() {
// given
context("superuser-alex@hostsharing.net", null);
final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "tenth");

View File

@@ -271,7 +271,8 @@ class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTest {
private void assertThatMembershipExistsAndIsAccessibleToCurrentContext(final HsOfficeMembershipEntity saved) {
final var found = membershipRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().isNotSameAs(saved).usingRecursiveComparison().isEqualTo(saved);
assertThat(found).isNotEmpty().get().isNotSameAs(saved)
.extracting(Object::toString).isEqualTo(saved.toString());
}
private void assertThatMembershipIsVisibleForUserWithRole(

View File

@@ -79,23 +79,27 @@ class HsOfficePartnerControllerAcceptanceTest {
{
"person": { "familyName": "Smith" },
"contact": { "label": "fifth contact" },
"birthday": "1987-10-31"
"details": { "birthday": "1987-10-31" }
},
{
"person": { "tradeName": "First GmbH" },
"contact": { "label": "first contact" }
"contact": { "label": "first contact" },
"details": { "registrationOffice": "Hamburg" }
},
{
"person": { "tradeName": "Third OHG" },
"contact": { "label": "third contact" }
"contact": { "label": "third contact" },
"details": { "registrationOffice": "Hamburg" }
},
{
"person": { "tradeName": "Second e.K." },
"contact": { "label": "second contact" }
"contact": { "label": "second contact" },
"details": { "registrationOffice": "Hamburg" }
},
{
"person": { "personType": "SOLE_REPRESENTATION" },
"contact": { "label": "forth contact" }
"contact": { "label": "forth contact" },
"details": { "registrationOffice": "Hamburg" }
}
]
"""));
@@ -122,8 +126,10 @@ class HsOfficePartnerControllerAcceptanceTest {
{
"contactUuid": "%s",
"personUuid": "%s",
"registrationOffice": "Registergericht Hamburg",
"registrationNumber": "123456"
"details": {
"registrationOffice": "Registergericht Aurich",
"registrationNumber": "123456"
}
}
""".formatted(givenContact.getUuid(), givenPerson.getUuid()))
.port(port)
@@ -133,7 +139,8 @@ class HsOfficePartnerControllerAcceptanceTest {
.statusCode(201)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("registrationNumber", is("123456"))
.body("details.registrationOffice", is("Registergericht Aurich"))
.body("details.registrationNumber", is("123456"))
.body("contact.label", is(givenContact.getLabel()))
.body("person.tradeName", is(givenPerson.getTradeName()))
.header("Location", startsWith("http://localhost"))
@@ -289,11 +296,13 @@ class HsOfficePartnerControllerAcceptanceTest {
{
"contactUuid": "%s",
"personUuid": "%s",
"registrationOffice": "Registergericht Hamburg",
"registrationNumber": "222222",
"birthName": "Maja Schmidt",
"birthday": "1938-04-08",
"dateOfDeath": "2022-01-12"
"details": {
"registrationOffice": "Registergericht Hamburg",
"registrationNumber": "222222",
"birthName": "Maja Schmidt",
"birthday": "1938-04-08",
"dateOfDeath": "2022-01-12"
}
}
""".formatted(givenContact.getUuid(), givenPerson.getUuid()))
.port(port)
@@ -303,7 +312,7 @@ class HsOfficePartnerControllerAcceptanceTest {
.statusCode(200)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("registrationNumber", is("222222"))
.body("details.registrationNumber", is("222222"))
.body("contact.label", is(givenContact.getLabel()))
.body("person.tradeName", is(givenPerson.getTradeName()));
// @formatter:on
@@ -314,11 +323,11 @@ class HsOfficePartnerControllerAcceptanceTest {
.matches(person -> {
assertThat(person.getPerson().getTradeName()).isEqualTo("Third OHG");
assertThat(person.getContact().getLabel()).isEqualTo("forth contact");
assertThat(person.getRegistrationOffice()).isEqualTo("Registergericht Hamburg");
assertThat(person.getRegistrationNumber()).isEqualTo("222222");
assertThat(person.getBirthName()).isEqualTo("Maja Schmidt");
assertThat(person.getBirthday()).isEqualTo("1938-04-08");
assertThat(person.getDateOfDeath()).isEqualTo("2022-01-12");
assertThat(person.getDetails().getRegistrationOffice()).isEqualTo("Registergericht Hamburg");
assertThat(person.getDetails().getRegistrationNumber()).isEqualTo("222222");
assertThat(person.getDetails().getBirthName()).isEqualTo("Maja Schmidt");
assertThat(person.getDetails().getBirthday()).isEqualTo("1938-04-08");
assertThat(person.getDetails().getDateOfDeath()).isEqualTo("2022-01-12");
return true;
});
}
@@ -335,9 +344,11 @@ class HsOfficePartnerControllerAcceptanceTest {
.contentType(ContentType.JSON)
.body("""
{
"birthName": "Maja Schmidt",
"birthday": "1938-04-08",
"dateOfDeath": "2022-01-12"
"details": {
"birthName": "Maja Schmidt",
"birthday": "1938-04-08",
"dateOfDeath": "2022-01-12"
}
}
""")
.port(port)
@@ -347,7 +358,7 @@ class HsOfficePartnerControllerAcceptanceTest {
.statusCode(200)
.contentType(ContentType.JSON)
.body("uuid", isUuidValid())
.body("birthName", is("Maja Schmidt"))
.body("details.birthName", is("Maja Schmidt"))
.body("contact.label", is(givenPartner.getContact().getLabel()))
.body("person.tradeName", is(givenPartner.getPerson().getTradeName()));
// @formatter:on
@@ -357,11 +368,11 @@ class HsOfficePartnerControllerAcceptanceTest {
.matches(person -> {
assertThat(person.getPerson().getTradeName()).isEqualTo(givenPartner.getPerson().getTradeName());
assertThat(person.getContact().getLabel()).isEqualTo(givenPartner.getContact().getLabel());
assertThat(person.getRegistrationOffice()).isEqualTo(null);
assertThat(person.getRegistrationNumber()).isEqualTo(null);
assertThat(person.getBirthName()).isEqualTo("Maja Schmidt");
assertThat(person.getBirthday()).isEqualTo("1938-04-08");
assertThat(person.getDateOfDeath()).isEqualTo("2022-01-12");
assertThat(person.getDetails().getRegistrationOffice()).isEqualTo(null);
assertThat(person.getDetails().getRegistrationNumber()).isEqualTo(null);
assertThat(person.getDetails().getBirthName()).isEqualTo("Maja Schmidt");
assertThat(person.getDetails().getBirthday()).isEqualTo("1938-04-08");
assertThat(person.getDetails().getDateOfDeath()).isEqualTo("2022-01-12");
return true;
});
}
@@ -440,6 +451,9 @@ class HsOfficePartnerControllerAcceptanceTest {
.uuid(UUID.randomUUID())
.person(givenPerson)
.contact(givenContact)
.details(HsOfficePartnerDetailsEntity.builder()
.uuid((UUID.randomUUID()))
.build())
.build();
toCleanup(newPartner.getUuid());

View File

@@ -0,0 +1,93 @@
package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.PatchUnitTestBase;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerDetailsPatchResource;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import javax.persistence.EntityManager;
import java.time.LocalDate;
import java.util.UUID;
import java.util.stream.Stream;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.lenient;
@TestInstance(PER_CLASS)
@ExtendWith(MockitoExtension.class)
class HsOfficePartnerDetailsEntityPatcherUnitTest extends PatchUnitTestBase<
HsOfficePartnerDetailsPatchResource,
HsOfficePartnerDetailsEntity
> {
private static final UUID INITIAL_PARTNER_UUID = UUID.randomUUID();
private static final UUID INITIAL_CONTACT_UUID = UUID.randomUUID();
private static final UUID INITIAL_PERSON_UUID = UUID.randomUUID();
private static final LocalDate INITIAL_BIRTHDAY = LocalDate.parse("1900-01-01");
private static final LocalDate PATCHED_BIRTHDAY = LocalDate.parse("1990-12-31");
private static final LocalDate INITIAL_DAY_OF_DEATH = LocalDate.parse("2000-01-01");
private static final LocalDate PATCHED_DATE_OF_DEATH = LocalDate.parse("2022-08-31");
@Mock
private EntityManager em;
@BeforeEach
void initMocks() {
lenient().when(em.getReference(eq(HsOfficeContactEntity.class), any())).thenAnswer(invocation ->
HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build());
lenient().when(em.getReference(eq(HsOfficePersonEntity.class), any())).thenAnswer(invocation ->
HsOfficePersonEntity.builder().uuid(invocation.getArgument(1)).build());
}
@Override
protected HsOfficePartnerDetailsEntity newInitialEntity() {
final var entity = new HsOfficePartnerDetailsEntity();
entity.setUuid(INITIAL_PARTNER_UUID);
entity.setRegistrationOffice("initial Reg-Office");
entity.setRegistrationNumber("initial Reg-Number");
entity.setBirthday(INITIAL_BIRTHDAY);
entity.setBirthName("initial birth name");
entity.setDateOfDeath(INITIAL_DAY_OF_DEATH);
return entity;
}
@Override
protected HsOfficePartnerDetailsPatchResource newPatchResource() {
return new HsOfficePartnerDetailsPatchResource();
}
@Override
protected HsOfficePartnerDetailsEntityPatcher createPatcher(final HsOfficePartnerDetailsEntity details) {
return new HsOfficePartnerDetailsEntityPatcher(em, details);
}
@Override
protected Stream<Property> propertyTestDescriptors() {
return Stream.of(
new JsonNullableProperty<>(
"registrationOffice",
HsOfficePartnerDetailsPatchResource::setRegistrationOffice,
"patched Reg-Office",
HsOfficePartnerDetailsEntity::setRegistrationOffice),
new JsonNullableProperty<>(
"birthday",
HsOfficePartnerDetailsPatchResource::setBirthday,
PATCHED_BIRTHDAY,
HsOfficePartnerDetailsEntity::setBirthday),
new JsonNullableProperty<>(
"dayOfDeath",
HsOfficePartnerDetailsPatchResource::setDateOfDeath,
PATCHED_DATE_OF_DEATH,
HsOfficePartnerDetailsEntity::setDateOfDeath)
);
}
}

View File

@@ -0,0 +1,51 @@
package net.hostsharing.hsadminng.hs.office.partner;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import static org.assertj.core.api.Assertions.assertThat;
class HsOfficePartnerDetailsEntityTest {
final HsOfficePartnerDetailsEntity given = HsOfficePartnerDetailsEntity.builder()
.registrationOffice("Hamburg")
.registrationNumber("12345")
.birthday(LocalDate.parse("2002-01-15"))
.birthName("Melly Miller")
.dateOfDeath(LocalDate.parse("2081-12-21"))
.build();
@Test
void toStringContainsAllProperties() {
final var result = given.toString();
assertThat(result).isEqualTo("partnerDetails(Hamburg, 12345, 2002-01-15, 2002-01-15, 2081-12-21)");
}
@Test
void toShortStringContainsFirstNonNullValue() {
assertThat(given.toShortString()).isEqualTo("12345");
assertThat(HsOfficePartnerDetailsEntity.builder()
.birthName("Melly Miller")
.birthday(LocalDate.parse("2002-01-15"))
.dateOfDeath(LocalDate.parse("2081-12-21"))
.build().toShortString()).isEqualTo("Melly Miller");
assertThat(HsOfficePartnerDetailsEntity.builder()
.birthday(LocalDate.parse("2002-01-15"))
.dateOfDeath(LocalDate.parse("2081-12-21"))
.build().toShortString()).isEqualTo("2002-01-15");
assertThat(HsOfficePartnerDetailsEntity.builder()
.dateOfDeath(LocalDate.parse("2081-12-21"))
.build().toShortString()).isEqualTo("2081-12-21");
assertThat(HsOfficePartnerDetailsEntity.builder()
.build().toShortString()).isEqualTo("<empty details>");
}
}

View File

@@ -1,9 +1,9 @@
package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.PatchUnitTestBase;
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.PatchUnitTestBase;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -11,14 +11,12 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import javax.persistence.EntityManager;
import java.time.LocalDate;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
import static org.mockito.Mockito.lenient;
@TestInstance(PER_CLASS)
@@ -31,28 +29,27 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
private static final UUID INITIAL_PARTNER_UUID = UUID.randomUUID();
private static final UUID INITIAL_CONTACT_UUID = UUID.randomUUID();
private static final UUID INITIAL_PERSON_UUID = UUID.randomUUID();
private static final UUID INITIAL_DETAILS_UUID = UUID.randomUUID();
private static final UUID PATCHED_CONTACT_UUID = UUID.randomUUID();
private static final UUID PATCHED_PERSON_UUID = UUID.randomUUID();
private static final LocalDate INITIAL_BIRTHDAY = LocalDate.parse("1900-01-01");
private static final LocalDate PATCHED_BIRTHDAY = LocalDate.parse("1990-12-31");
private static final LocalDate INITIAL_DAY_OF_DEATH = LocalDate.parse("2000-01-01");
private static final LocalDate PATCHED_DATE_OF_DEATH = LocalDate.parse("2022-08-31");
private final HsOfficePersonEntity givenInitialPerson = HsOfficePersonEntity.builder()
.uuid(INITIAL_PERSON_UUID)
.build();
private final HsOfficeContactEntity givenInitialContact = HsOfficeContactEntity.builder()
.uuid(INITIAL_CONTACT_UUID)
.build();
private final HsOfficePartnerDetailsEntity givenInitialDetails = HsOfficePartnerDetailsEntity.builder()
.uuid(INITIAL_DETAILS_UUID)
.build();
@Mock
private EntityManager em;
@BeforeEach
void initMocks() {
lenient().when(em.getReference(eq(HsOfficeContactEntity.class), any())).thenAnswer(invocation ->
HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build());
HsOfficeContactEntity.builder().uuid(invocation.getArgument(1)).build());
lenient().when(em.getReference(eq(HsOfficePersonEntity.class), any())).thenAnswer(invocation ->
HsOfficePersonEntity.builder().uuid(invocation.getArgument(1)).build());
}
@@ -63,11 +60,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
entity.setUuid(INITIAL_PARTNER_UUID);
entity.setPerson(givenInitialPerson);
entity.setContact(givenInitialContact);
entity.setRegistrationOffice("initial Reg-Office");
entity.setRegistrationNumber("initial Reg-Number");
entity.setBirthday(INITIAL_BIRTHDAY);
entity.setBirthName("initial birth name");
entity.setDateOfDeath(INITIAL_DAY_OF_DEATH);
entity.setDetails(givenInitialDetails);
return entity;
}
@@ -78,15 +71,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
@Override
protected HsOfficePartnerEntityPatcher createPatcher(final HsOfficePartnerEntity partner) {
return new HsOfficePartnerEntityPatcher(
em,
partner,
uuid -> uuid == PATCHED_CONTACT_UUID
? Optional.of(newContact(uuid))
: Optional.empty(),
uuid -> uuid == PATCHED_PERSON_UUID
? Optional.of(newPerson(uuid))
: Optional.empty());
return new HsOfficePartnerEntityPatcher(em, partner);
}
@Override
@@ -105,22 +90,7 @@ class HsOfficePartnerEntityPatcherUnitTest extends PatchUnitTestBase<
PATCHED_PERSON_UUID,
HsOfficePartnerEntity::setPerson,
newPerson(PATCHED_PERSON_UUID))
.notNullable(),
new JsonNullableProperty<>(
"registrationOffice",
HsOfficePartnerPatchResource::setRegistrationOffice,
"patched Reg-Office",
HsOfficePartnerEntity::setRegistrationOffice),
new JsonNullableProperty<>(
"birthday",
HsOfficePartnerPatchResource::setBirthday,
PATCHED_BIRTHDAY,
HsOfficePartnerEntity::setBirthday),
new JsonNullableProperty<>(
"dayOfDeath",
HsOfficePartnerPatchResource::setDateOfDeath,
PATCHED_DATE_OF_DEATH,
HsOfficePartnerEntity::setDateOfDeath)
.notNullable()
);
}

View File

@@ -20,7 +20,6 @@ import org.springframework.test.annotation.DirtiesContext;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.*;
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.grantDisplaysOf;
@@ -77,6 +76,9 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest {
.uuid(UUID.randomUUID())
.person(givenPerson)
.contact(givenContact)
.details(HsOfficePartnerDetailsEntity.builder()
.uuid(UUID.randomUUID())
.build())
.build());
return partnerRepo.save(newPartner);
});
@@ -107,6 +109,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest {
.uuid(UUID.randomUUID())
.person(givenPerson)
.contact(givenContact)
.details(HsOfficePartnerDetailsEntity.builder().uuid(UUID.randomUUID()).build())
.build());
return partnerRepo.save(newPartner);
});
@@ -126,28 +129,32 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest {
.containsExactlyInAnyOrder(Array.fromFormatted(
initialGrantNames,
// owner
"{ grant perm * on partner#EBess-4th to role partner#EBess-4th.owner by system and assume }",
"{ grant role partner#EBess-4th.owner to role global#global.admin by system and assume }",
"{ grant perm * on partner#EBess-4th to role partner#EBess-4th.owner by system and assume }",
"{ grant perm * on partner_details#EBess-4th-details to role partner#EBess-4th.owner by system and assume }",
"{ grant role partner#EBess-4th.owner to role global#global.admin by system and assume }",
// admin
"{ grant perm edit on partner#EBess-4th to role partner#EBess-4th.admin by system and assume }",
"{ grant role partner#EBess-4th.admin to role partner#EBess-4th.owner by system and assume }",
"{ grant role person#EBess.tenant to role partner#EBess-4th.admin by system and assume }",
"{ grant role contact#4th.tenant to role partner#EBess-4th.admin by system and assume }",
"{ grant perm edit on partner#EBess-4th to role partner#EBess-4th.admin by system and assume }",
"{ grant perm edit on partner_details#EBess-4th-details to role partner#EBess-4th.admin by system and assume }",
"{ grant role partner#EBess-4th.admin to role partner#EBess-4th.owner by system and assume }",
"{ grant role person#EBess.tenant to role partner#EBess-4th.admin by system and assume }",
"{ grant role contact#4th.tenant to role partner#EBess-4th.admin by system and assume }",
// agent
"{ grant role partner#EBess-4th.agent to role partner#EBess-4th.admin by system and assume }",
"{ grant role partner#EBess-4th.agent to role person#EBess.admin by system and assume }",
"{ grant role partner#EBess-4th.agent to role contact#4th.admin by system and assume }",
"{ grant perm view on partner_details#EBess-4th-details to role partner#EBess-4th.agent by system and assume }",
"{ grant role partner#EBess-4th.agent to role partner#EBess-4th.admin by system and assume }",
"{ grant role partner#EBess-4th.agent to role person#EBess.admin by system and assume }",
"{ grant role partner#EBess-4th.agent to role contact#4th.admin by system and assume }",
// tenant
"{ grant role partner#EBess-4th.tenant to role partner#EBess-4th.agent by system and assume }",
"{ grant role person#EBess.guest to role partner#EBess-4th.tenant by system and assume }",
"{ grant role contact#4th.guest to role partner#EBess-4th.tenant by system and assume }",
"{ grant role partner#EBess-4th.tenant to role partner#EBess-4th.agent by system and assume }",
"{ grant role person#EBess.guest to role partner#EBess-4th.tenant by system and assume }",
"{ grant role contact#4th.guest to role partner#EBess-4th.tenant by system and assume }",
// guest
"{ grant perm view on partner#EBess-4th to role partner#EBess-4th.guest by system and assume }",
"{ grant role partner#EBess-4th.guest to role partner#EBess-4th.tenant by system and assume }",
"{ grant perm view on partner#EBess-4th to role partner#EBess-4th.guest by system and assume }",
"{ grant role partner#EBess-4th.guest to role partner#EBess-4th.tenant by system and assume }",
null));
}
@@ -226,7 +233,6 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest {
context("superuser-alex@hostsharing.net");
givenPartner.setContact(givenNewContact);
givenPartner.setPerson(givenNewPerson);
givenPartner.setDateOfDeath(LocalDate.parse("2022-09-15"));
return toCleanup(partnerRepo.save(givenPartner));
});
@@ -246,47 +252,26 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest {
}
@Test
public void personAdmin_canNotUpdateRelatedPartner() {
// given
context("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler("eighth");
assertThatPartnerIsVisibleForUserWithRole(
givenPartner,
"hs_office_person#ErbenBesslerMelBessler.admin");
assertThatPartnerActuallyInDatabase(givenPartner);
// when
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", "hs_office_person#ErbenBesslerMelBessler.admin");
givenPartner.setDateOfDeath(LocalDate.parse("2022-09-15"));
return partnerRepo.save(givenPartner);
});
// then
result.assertExceptionWithRootCauseMessage(JpaSystemException.class,
"[403] Subject ", " is not allowed to update hs_office_partner uuid");
}
@Test
public void contactAdmin_canNotUpdateRelatedPartner() {
public void partnerAgent_canNotUpdateRelatedPartner() {
// given
context("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler("ninth");
assertThatPartnerIsVisibleForUserWithRole(
givenPartner,
"hs_office_contact#ninthcontact.admin");
"hs_office_partner#ErbenBesslerMelBessler-ninthcontact.agent");
assertThatPartnerActuallyInDatabase(givenPartner);
final var givenNewContact = contactRepo.findContactByOptionalLabelLike("tenth").get(0);
// when
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", "hs_office_contact#ninthcontact.admin");
givenPartner.setDateOfDeath(LocalDate.parse("2022-09-15"));
context("superuser-alex@hostsharing.net", "hs_office_partner#ErbenBesslerMelBessler-ninthcontact.agent");
givenPartner.getDetails().setBirthName("new birthname");
return partnerRepo.save(givenPartner);
});
// then
result.assertExceptionWithRootCauseMessage(JpaSystemException.class,
"[403] Subject ", " is not allowed to update hs_office_partner uuid");
"[403] Subject ", " is not allowed to update hs_office_partner_details uuid");
}
private void assertThatPartnerActuallyInDatabase(final HsOfficePartnerEntity saved) {
@@ -424,6 +409,9 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest {
.uuid(UUID.randomUUID())
.person(givenPerson)
.contact(givenContact)
.details(HsOfficePartnerDetailsEntity.builder()
.uuid(UUID.randomUUID())
.build())
.build();
toCleanup(newPartner);

View File

@@ -290,7 +290,8 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTest {
private void assertThatSepaMandateActuallyInDatabase(final HsOfficeSepaMandateEntity saved) {
final var found = sepaMandateRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().isNotSameAs(saved).usingRecursiveComparison().isEqualTo(saved);
assertThat(found).isNotEmpty().get().isNotSameAs(saved)
.extracting(Object::toString).isEqualTo(saved.toString());
}
private void assertThatSepaMandateIsVisibleForUserWithRole(