Compare commits

...

2 Commits

Author SHA1 Message Date
Michael Hoennig
c67af5948b use XX for not-assumed 2024-03-11 09:20:25 +01:00
Michael Hoennig
1c2cdf207c add check for @Version field 2024-03-11 09:13:07 +01:00
10 changed files with 21 additions and 13 deletions

View File

@ -20,6 +20,7 @@ import net.hostsharing.hsadminng.test.dom.TestDomainEntity;
import net.hostsharing.hsadminng.test.pac.TestPackageEntity;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import jakarta.validation.constraints.NotNull;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -29,6 +30,7 @@ import java.util.function.Consumer;
import java.util.stream.Stream;
import static java.lang.reflect.Modifier.isStatic;
import static java.util.Arrays.stream;
import static java.util.Optional.ofNullable;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.RbacUserReference.UserRole.CREATOR;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.autoFetched;
@ -76,7 +78,7 @@ public class RbacView {
public RbacView withUpdatableColumns(final String... columnNames) {
Collections.addAll(updatableColumns, columnNames);
// TODO: automatically add @Version column, otherwise optimistic locking won't work
verifyVersionColumnExists();
return this;
}
@ -214,6 +216,14 @@ public class RbacView {
return this;
}
private void verifyVersionColumnExists() {
if (stream(rootEntityAlias.entityClass.getDeclaredFields())
.noneMatch(f -> f.getAnnotation(Version.class) != null)) {
// TODO: convert this into throw Exception once RbacEntity is a base class with @Version field
System.err.println("@Version field required in updatable entity " + rootEntityAlias.entityClass);
}
}
public RbacGrantBuilder toRole(final String entityAlias, final Role role) {
return new RbacGrantBuilder(entityAlias, role);
}
@ -801,7 +811,7 @@ public class RbacView {
HsOfficeCoopSharesTransactionEntity.class,
HsOfficeMembershipEntity.class
).forEach(c -> {
final Method mainMethod = Arrays.stream(c.getMethods()).filter(
final Method mainMethod = stream(c.getMethods()).filter(
m -> isStatic(m.getModifiers()) && m.getName().equals("main")
)
.findFirst()

View File

@ -127,9 +127,9 @@ public class RbacGrantsDiagramService {
: "";
final var grants = graph.stream()
.map(g -> quoted(g.getAscendantIdName()) +
(g.isAssumed() ? " --> " : " -.-> ") +
quoted(g.getDescendantIdName()))
.map(g -> quoted(g.getAscendantIdName())
+ " -->" + (g.isAssumed() ? " " : "|XX| ")
+ quoted(g.getDescendantIdName()))
.sorted()
.collect(joining("\n"));

View File

@ -53,7 +53,6 @@ public class TestCustomerController implements TestCustomersApi {
context.define(currentUser, assumedRoles);
final var saved = testCustomerRepository.save(mapper.map(customer, TestCustomerEntity.class));
em.flush();
final var uri =
MvcUriComponentsBuilder.fromController(getClass())
.path("/api/test/customers/{id}")

View File

@ -41,7 +41,7 @@ public class TestCustomerEntity implements HasUuid {
.withIdentityView(SQL.projection("prefix"))
.withRestrictedViewOrderBy(SQL.expression("reference"))
.withUpdatableColumns("reference", "prefix", "adminUserName")
// TODO: do we want explicit specification of parent-indenpendent insert permissions?
// TODO: do we want explicit specification of parent-independent insert permissions?
// .toRole("global", ADMIN).grantPermission("customer", INSERT)
.createRole(OWNER, (with) -> {

View File

@ -1,4 +1,4 @@
### rbac customer 2024-03-10T11:42:41.089596517
### rbac customer 2024-03-11T09:06:04.484587070
```mermaid
%%{init:{'flowchart':{'htmlLabels':false}}}%%

View File

@ -1,5 +1,5 @@
--liquibase formatted sql
-- This code generated was by RbacViewPostgresGenerator at 2024-03-10T11:42:41.121556631.
-- This code generated was by RbacViewPostgresGenerator at 2024-03-11T09:06:04.497071201.
-- ============================================================================
--changeset test-customer-rbac-OBJECT:1 endDelimiter:--//

View File

@ -1,4 +1,4 @@
### rbac package 2024-03-10T11:42:41.162678472
### rbac package 2024-03-11T09:06:04.536081351
```mermaid
%%{init:{'flowchart':{'htmlLabels':false}}}%%

View File

@ -1,5 +1,5 @@
--liquibase formatted sql
-- This code generated was by RbacViewPostgresGenerator at 2024-03-10T11:42:41.163393064.
-- This code generated was by RbacViewPostgresGenerator at 2024-03-11T09:06:04.536525766.
-- ============================================================================
--changeset test-package-rbac-OBJECT:1 endDelimiter:--//

View File

@ -1,5 +1,5 @@
--liquibase formatted sql
-- This code generated was by RbacViewPostgresGenerator at 2024-03-10T11:42:41.186902574.
-- This code generated was by RbacViewPostgresGenerator at 2024-03-11T09:06:04.558752062.
-- ============================================================================
--changeset test-domain-rbac-OBJECT:1 endDelimiter:--//

View File

@ -473,7 +473,6 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
.contact(givenContact)
.build();
relationshipRepo.save(partnerRole);
em.flush(); // TODO: why is that necessary?
final var newPartner = HsOfficePartnerEntity.builder()
.partnerNumber(partnerNumber)