bugfix/only-one-partner-per-person #143
@ -9,6 +9,7 @@ import lombok.experimental.FieldNameConstants;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import net.hostsharing.hsadminng.errors.DisplayAs;
|
||||
import net.hostsharing.hsadminng.persistence.BaseEntity;
|
||||
import net.hostsharing.hsadminng.rbac.role.WithRoleId;
|
||||
import net.hostsharing.hsadminng.repr.Stringify;
|
||||
import net.hostsharing.hsadminng.repr.Stringifyable;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -30,7 +31,7 @@ import static net.hostsharing.hsadminng.repr.Stringify.stringify;
|
||||
@SuperBuilder(toBuilder = true)
|
||||
@FieldNameConstants
|
||||
@DisplayAs("Person")
|
||||
public class HsOfficePerson<T extends HsOfficePerson<?> & BaseEntity<?>> implements BaseEntity<T>, Stringifyable {
|
||||
public class HsOfficePerson<T extends HsOfficePerson<?> & BaseEntity<?>> implements BaseEntity<T>, Stringifyable, WithRoleId {
|
||||
|
||||
private static Stringify<HsOfficePerson> toString = stringify(HsOfficePerson.class, "person")
|
||||
.withProp(Fields.personType, HsOfficePerson::getPersonType)
|
||||
|
@ -6,6 +6,7 @@ import lombok.experimental.SuperBuilder;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRealEntity;
|
||||
import net.hostsharing.hsadminng.persistence.BaseEntity;
|
||||
import net.hostsharing.hsadminng.rbac.role.WithRoleId;
|
||||
import net.hostsharing.hsadminng.repr.Stringify;
|
||||
import net.hostsharing.hsadminng.repr.Stringifyable;
|
||||
|
||||
@ -22,7 +23,7 @@ import static net.hostsharing.hsadminng.repr.Stringify.stringify;
|
||||
@Setter
|
||||
@SuperBuilder(toBuilder = true)
|
||||
@FieldNameConstants
|
||||
public class HsOfficeRelation implements BaseEntity<HsOfficeRelation>, Stringifyable {
|
||||
public class HsOfficeRelation implements BaseEntity<HsOfficeRelation>, Stringifyable, WithRoleId {
|
||||
|
||||
private static Stringify<HsOfficeRelation> toString = stringify(HsOfficeRelation.class, "rel")
|
||||
.withProp(Fields.anchor, HsOfficeRelation::getAnchor)
|
||||
|
@ -1,10 +1,8 @@
|
||||
package net.hostsharing.hsadminng.persistence;
|
||||
|
||||
|
||||
import net.hostsharing.hsadminng.rbac.role.RbacRoleType;
|
||||
import org.hibernate.Hibernate;
|
||||
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface BaseEntity<T extends BaseEntity<?>> {
|
||||
@ -17,13 +15,4 @@ public interface BaseEntity<T extends BaseEntity<?>> {
|
||||
//noinspection unchecked
|
||||
return (T) this;
|
||||
};
|
||||
|
||||
default String role(RbacRoleType rbacRoleType) {
|
||||
if ( getUuid() == null ) {
|
||||
throw new IllegalStateException("UUID missing => role can't be determined");
|
||||
}
|
||||
final Table tableAnnot = getClass().getAnnotation(Table.class);
|
||||
final var qualifiedTableName = tableAnnot.schema() + "." + tableAnnot.name();
|
||||
return qualifiedTableName + "#" + getUuid() + ":" + rbacRoleType.name();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package net.hostsharing.hsadminng.rbac.role;
|
||||
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface WithRoleId {
|
||||
UUID getUuid();
|
||||
|
||||
/**
|
||||
* @return the RBAC-Role-Id of the given `rbacRoleType` for this entity instance.
|
||||
*/
|
||||
default String roleId(final RbacRoleType rbacRoleType) {
|
||||
if ( getUuid() == null ) {
|
||||
throw new IllegalStateException("UUID missing => role can't be determined");
|
||||
}
|
||||
final Table tableAnnot = getClass().getAnnotation(Table.class);
|
||||
final var qualifiedTableName = tableAnnot.schema() + "." + tableAnnot.name();
|
||||
return qualifiedTableName + "#" + getUuid() + ":" + rbacRoleType.name();
|
||||
}
|
||||
}
|
@ -340,7 +340,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
|
||||
assertThatDebitorIsVisibleForUserWithRole(
|
||||
givenDebitor,
|
||||
givenDebitor.getDebitorRel().role(ADMIN), true);
|
||||
givenDebitor.getDebitorRel().roleId(ADMIN), true);
|
||||
final var givenNewPartnerPerson = one(personRepo.findPersonByOptionalNameLike("First"));
|
||||
final var givenNewBillingPerson = one(personRepo.findPersonByOptionalNameLike("Firby"));
|
||||
final var givenNewContact = one(contactRealRepo.findContactByOptionalCaptionLike("sixth contact"));
|
||||
@ -373,10 +373,10 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
// ... partner role was reassigned:
|
||||
assertThatDebitorIsNotVisibleForUserWithRole(
|
||||
result.returnedValue(),
|
||||
originalDebitorRel.role(ADMIN));
|
||||
originalDebitorRel.roleId(ADMIN));
|
||||
assertThatDebitorIsVisibleForUserWithRole(
|
||||
result.returnedValue(),
|
||||
result.returnedValue().getDebitorRel().role(ADMIN), true);
|
||||
result.returnedValue().getDebitorRel().roleId(ADMIN), true);
|
||||
|
||||
// ... contact role was reassigned:
|
||||
assertThatDebitorIsNotVisibleForUserWithRole(
|
||||
@ -402,7 +402,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
final var givenDebitor = givenSomeTemporaryDebitor("Fourth", "tenth contact", null, "fig");
|
||||
assertThatDebitorIsVisibleForUserWithRole(
|
||||
givenDebitor,
|
||||
givenDebitor.getDebitorRel().role(ADMIN), true);
|
||||
givenDebitor.getDebitorRel().roleId(ADMIN), true);
|
||||
assertThatDebitorActuallyInDatabase(givenDebitor, true);
|
||||
final var givenNewBankAccount = one(bankAccountRepo.findByOptionalHolderLike("first"));
|
||||
|
||||
@ -566,7 +566,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net", givenDebitor.getDebitorRel().role(ADMIN));
|
||||
context("superuser-alex@hostsharing.net", givenDebitor.getDebitorRel().roleId(ADMIN));
|
||||
assertThat(debitorRepo.findByUuid(givenDebitor.getUuid())).isPresent();
|
||||
|
||||
debitorRepo.deleteByUuid(givenDebitor.getUuid());
|
||||
|
@ -282,7 +282,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
|
||||
"rbac.global#global:ADMIN");
|
||||
assertThatPartnerIsVisibleForUserWithRole(
|
||||
givenPartner,
|
||||
givenPartner.getPartnerRel().getHolder().role(ADMIN));
|
||||
givenPartner.getPartnerRel().getHolder().roleId(ADMIN));
|
||||
assertThatPartnerIsNotVisibleForUserWithRole(
|
||||
givenPartner,
|
||||
"hs_office.person#ErbenBesslerMelBessler:ADMIN");
|
||||
|
Loading…
x
Reference in New Issue
Block a user