Search in sources :

Example 6 with InMemoryCrudEntityContext

use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.

the class DataStoreInMemoryCrudListener method entitySaving.

@Override
public void entitySaving(DataStoreEntitySavingEvent event) {
    SaveContext context = event.getSaveContext();
    for (Object entity : event.getEntities()) {
        MetaClass metaClass = metadata.getClass(entity);
        InMemoryCrudEntityContext entityContext = new InMemoryCrudEntityContext(metaClass, applicationContext);
        accessManager.applyConstraints(entityContext, context.getAccessConstraints());
        if (isNew(context, entity)) {
            if (!entityContext.isCreatePermitted(entity)) {
                throw new AccessDeniedException("entity", entity.toString(), "create");
            }
        } else {
            if (!entityContext.isUpdatePermitted(entity)) {
                throw new AccessDeniedException("entity", entity.toString(), "update");
            }
        }
    }
}
Also used : InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) AccessDeniedException(io.jmix.core.security.AccessDeniedException) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 7 with InMemoryCrudEntityContext

use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.

the class DataStoreInMemoryCrudListener method hasInMemoryRead.

protected boolean hasInMemoryRead(LoadContext<?> context) {
    return collectEntityClasses(context).stream().anyMatch(entityClass -> {
        InMemoryCrudEntityContext crudContext = new InMemoryCrudEntityContext(entityClass, applicationContext);
        accessManager.applyConstraints(crudContext, context.getAccessConstraints());
        return crudContext.readPredicate() != null;
    });
}
Also used : InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext)

Example 8 with InMemoryCrudEntityContext

use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.

the class EditAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null || target.getSingleSelected() == null || !(target.getItems() instanceof EntityDataUnit)) {
        return false;
    }
    MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
    if (metaClass == null) {
        return true;
    }
    UiEntityContext entityContext = new UiEntityContext(metaClass);
    accessManager.applyRegisteredConstraints(entityContext);
    InMemoryCrudEntityContext inMemoryCrudEntityContext = new InMemoryCrudEntityContext(metaClass, applicationContext);
    accessManager.applyRegisteredConstraints(inMemoryCrudEntityContext);
    if (!entityContext.isViewPermitted() && !entityContext.isEditPermitted()) {
        return false;
    }
    if (inMemoryCrudEntityContext.updatePredicate() != null) {
        return true;
    }
    return super.isPermitted();
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 9 with InMemoryCrudEntityContext

use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.

the class EditAction method refreshState.

@Override
public void refreshState() {
    super.refreshState();
    if (target == null || !(target.getItems() instanceof EntityDataUnit)) {
        return;
    }
    if (!captionInitialized) {
        MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
        UiEntityContext entityContext = new UiEntityContext(metaClass);
        accessManager.applyRegisteredConstraints(entityContext);
        InMemoryCrudEntityContext inMemoryContext = new InMemoryCrudEntityContext(metaClass, applicationContext);
        accessManager.applyRegisteredConstraints(inMemoryContext);
        if (metaClass != null) {
            Object entity = target.getSingleSelected();
            if (entityContext.isEditPermitted() && (inMemoryContext.updatePredicate() == null || entity != null && inMemoryContext.isUpdatePermitted(entity))) {
                super.setCaption(messages.getMessage("actions.Edit"));
            } else {
                super.setCaption(messages.getMessage("actions.View"));
            }
        }
    }
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 10 with InMemoryCrudEntityContext

use of io.jmix.core.accesscontext.InMemoryCrudEntityContext in project jmix by jmix-framework.

the class DeclarativeTrackingAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null) {
        return false;
    }
    Object singleSelected = target.getSingleSelected();
    if (singleSelected == null) {
        return false;
    }
    if (constraintEntityOp != null) {
        MetaClass metaClass = metadata.getClass(singleSelected.getClass());
        InMemoryCrudEntityContext context = new InMemoryCrudEntityContext(metaClass, applicationContext);
        accessManager.applyRegisteredConstraints(context);
        if (constraintEntityOp == EntityOp.CREATE) {
            return context.isCreatePermitted(singleSelected);
        } else if (constraintEntityOp == EntityOp.READ) {
            return context.isReadPermitted(singleSelected);
        } else if (constraintEntityOp == EntityOp.UPDATE) {
            return context.isUpdatePermitted(singleSelected);
        } else if (constraintEntityOp == EntityOp.DELETE) {
            return context.isDeletePermitted(singleSelected);
        } else {
            return false;
        }
    }
    return super.isPermitted();
}
Also used : InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Aggregations

InMemoryCrudEntityContext (io.jmix.core.accesscontext.InMemoryCrudEntityContext)11 MetaClass (io.jmix.core.metamodel.model.MetaClass)10 UiEntityContext (io.jmix.ui.accesscontext.UiEntityContext)3 AccessDeniedException (io.jmix.core.security.AccessDeniedException)2 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)2 EntitySystemAccess.getSecurityState (io.jmix.core.entity.EntitySystemAccess.getSecurityState)1 SecurityState (io.jmix.core.entity.SecurityState)1 EntityTokenException (io.jmix.core.impl.serialization.EntityTokenException)1 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)1