HHH-17935 Do not use the "auto-enable" feature for the tenant ID filter
This filter already gets enabled automatically where relevant, and critically it's not relevant when using a "root" tenant identifier.
This commit is contained in:
parent
ce97a5da2c
commit
56105a8fc6
|
@ -59,7 +59,7 @@ public class TenantIdBinder implements AttributeBinder<TenantId> {
|
|||
"",
|
||||
singletonMap( PARAMETER_NAME, tenantIdType ),
|
||||
Collections.emptyMap(),
|
||||
true
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -76,6 +76,11 @@ public class TenantIdTest implements SessionFactoryProducer {
|
|||
public boolean validateExistingCurrentSessions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot(String tenantId) {
|
||||
return "root".equals( tenantId );
|
||||
}
|
||||
} );
|
||||
return (SessionFactoryImplementor) sessionFactoryBuilder.build();
|
||||
}
|
||||
|
@ -105,6 +110,47 @@ public class TenantIdTest implements SessionFactoryProducer {
|
|||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoot(SessionFactoryScope scope) {
|
||||
currentTenant = "root";
|
||||
scope.inTransaction( session -> {
|
||||
assertEquals( 0, session.createQuery( "from Account" ).getResultList().size() );
|
||||
} );
|
||||
|
||||
currentTenant = "mine";
|
||||
Client client = new Client( "Gavin" );
|
||||
Account acc = new Account( client );
|
||||
scope.inTransaction( session -> {
|
||||
session.persist( client );
|
||||
session.persist( acc );
|
||||
} );
|
||||
assertEquals( "mine", acc.tenantId );
|
||||
scope.inTransaction( session -> {
|
||||
assertNotNull( session.find( Account.class, acc.id ) );
|
||||
assertEquals( 1, session.createQuery( "from Account" ).getResultList().size() );
|
||||
} );
|
||||
|
||||
currentTenant = "root";
|
||||
// Root tenants should find entities from other tenants
|
||||
scope.inTransaction( session -> {
|
||||
assertNotNull( session.find( Account.class, acc.id ) );
|
||||
assertEquals( 1, session.createQuery( "from Account" ).getResultList().size() );
|
||||
} );
|
||||
|
||||
// Root tenants should find entities from their own tenant
|
||||
Client rootClient = new Client( "Sacha" );
|
||||
Account rootAcc = new Account( rootClient );
|
||||
scope.inTransaction( session -> {
|
||||
session.persist( rootClient );
|
||||
session.persist( rootAcc );
|
||||
} );
|
||||
assertEquals( "root", rootAcc.tenantId );
|
||||
scope.inTransaction( session -> {
|
||||
assertNotNull( session.find( Account.class, rootAcc.id ) );
|
||||
assertEquals( 2, session.createQuery( "from Account" ).getResultList().size() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorOnInsert(SessionFactoryScope scope) {
|
||||
currentTenant = "mine";
|
||||
|
|
Loading…
Reference in New Issue