Skip to content

Commit

Permalink
Merge pull request #22 from cuba-platform/feature/tenant-admins-are-n…
Browse files Browse the repository at this point in the history
…ot-able-10

Tenant admins are not able to view user sessions from the administration menu #10
  • Loading branch information
Evgeny Zakharchenko authored May 20, 2019
2 parents 63ffe32 + 8b19779 commit 4ed7973
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
import com.haulmont.addon.sdbmt.core.TenantId;
import com.haulmont.addon.sdbmt.entity.HasTenant;
import com.haulmont.addon.sdbmt.entity.Tenant;
import com.haulmont.addon.sdbmt.entity.TenantGroup;
import com.haulmont.bali.util.Preconditions;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.cuba.core.Persistence;
import com.haulmont.cuba.core.Transaction;
import com.haulmont.cuba.core.TypedQuery;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.core.global.View;
import com.haulmont.cuba.core.sys.AppContext;
import com.haulmont.cuba.security.entity.*;
import com.haulmont.cuba.security.global.UserSession;
Expand Down Expand Up @@ -246,10 +247,11 @@ protected Tenant findGroupTenant(Group group) {

protected Tenant getGroupTenant(Group group) {
//to prevent user from having to create a new Group view that includes Tenant
return persistence.callInTransaction(em ->
em.createQuery("select group.tenant from sec$Group group where group = ?1", Tenant.class)
.setParameter(1, group)
.setViewName(View.LOCAL)
.getFirstResult());
TenantGroup tenantGroup = persistence.createTransaction().execute((Transaction.Callable<TenantGroup>) em ->
em.find(TenantGroup.class, group.getId(), "group-tenant-and-hierarchy"));
if (tenantGroup.getTenant() == null && tenantGroup.getParent() != null) {
return getGroupTenant(tenantGroup.getParent());
}
return tenantGroup.getTenant();
}
}

0 comments on commit 4ed7973

Please sign in to comment.