Search in sources :

Example 6 with UiEntityContext

use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.

the class EditAction method isDisabledWhenScreenReadOnly.

@Override
public boolean isDisabledWhenScreenReadOnly() {
    if (!(target.getItems() instanceof EntityDataUnit)) {
        return true;
    }
    MetaClass metaClass = ((EntityDataUnit) target.getItems()).getEntityMetaClass();
    if (metaClass != null) {
        // Even though the screen is read-only, this edit action may remain active
        // because the related entity cannot be edited and the corresponding edit screen
        // will be opened in read-only mode either.
        UiEntityContext entityContext = new UiEntityContext(metaClass);
        accessManager.applyRegisteredConstraints(entityContext);
        return entityContext.isEditPermitted();
    }
    return true;
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 7 with UiEntityContext

use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.

the class RemoveAction method checkRemovePermission.

protected boolean checkRemovePermission() {
    if (target == null || !(target.getItems() instanceof ContainerDataUnit)) {
        return false;
    }
    ContainerDataUnit<E> containerDataUnit = (ContainerDataUnit) target.getItems();
    MetaClass metaClass = containerDataUnit.getEntityMetaClass();
    if (metaClass == null) {
        return false;
    }
    UiEntityContext entityContext = new UiEntityContext(metaClass);
    accessManager.applyRegisteredConstraints(entityContext);
    if (!entityContext.isDeletePermitted()) {
        return false;
    }
    if (containerDataUnit.getContainer() instanceof Nested) {
        Nested nestedContainer = (Nested) containerDataUnit.getContainer();
        MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
        MetaProperty metaProperty = masterMetaClass.getProperty(nestedContainer.getProperty());
        UiEntityAttributeContext entityAttributeContext = new UiEntityAttributeContext(masterMetaClass, metaProperty.getName());
        accessManager.applyRegisteredConstraints(entityAttributeContext);
        if (!entityAttributeContext.canModify()) {
            return false;
        }
    }
    return true;
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) Nested(io.jmix.ui.model.Nested) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 8 with UiEntityContext

use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.

the class ViewAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == 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);
    if (!entityContext.isViewPermitted()) {
        return false;
    }
    return super.isPermitted();
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 9 with UiEntityContext

use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.

the class StandardEditor method setupLock.

protected void setupLock() {
    Object entityId = EntityValues.getId(entityToEdit);
    if (!getEntityStates().isNew(entityToEdit) && entityId != null) {
        AccessManager accessManager = getApplicationContext().getBean(AccessManager.class);
        MetaClass metaClass = getEditedEntityContainer().getEntityMetaClass();
        UiEntityContext entityContext = new UiEntityContext(metaClass);
        accessManager.applyRegisteredConstraints(entityContext);
        InMemoryCrudEntityContext inMemoryContext = new InMemoryCrudEntityContext(metaClass, getApplicationContext());
        accessManager.applyRegisteredConstraints(inMemoryContext);
        if (entityContext.isEditPermitted() && (inMemoryContext.updatePredicate() == null || inMemoryContext.isUpdatePermitted(getEditedEntity()))) {
            readOnlyDueToLock = false;
            PessimisticLockStatus lockStatus = getLockingSupport().lock(entityId);
            if (lockStatus == PessimisticLockStatus.LOCKED) {
                justLocked = true;
                addAfterDetachListener(afterDetachEvent -> releaseLock());
            } else if (lockStatus == PessimisticLockStatus.FAILED) {
                readOnlyDueToLock = true;
                showEnableEditingBtn = false;
                setReadOnly(true);
            }
        } else {
            showEnableEditingBtn = false;
            setReadOnly(true);
        }
    }
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) InMemoryCrudEntityContext(io.jmix.core.accesscontext.InMemoryCrudEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 10 with UiEntityContext

use of io.jmix.ui.accesscontext.UiEntityContext in project jmix by jmix-framework.

the class MasterDetailScreen method initBrowseEditAction.

/**
 * Adds an EditAction that enables controls for editing.
 */
protected void initBrowseEditAction() {
    ListComponent<T> table = getTable();
    EditAction editAction = (EditAction) table.getActionNN("edit");
    editAction.withHandler(actionPerformedEvent -> {
        T item = table.getSingleSelected();
        if (item != null) {
            if (lockIfNeeded(item)) {
                refreshOptionsForLookupFields();
                enableEditControls(false);
            }
        }
    });
    MetaClass entityMetaClass = getApplicationContext().getBean(Metadata.class).getClass(getEntityClass());
    UiEntityContext entityContext = new UiEntityContext(entityMetaClass);
    getApplicationContext().getBean(AccessManager.class).applyRegisteredConstraints(entityContext);
    editAction.addEnabledRule(() -> table.getSelected().size() == 1 && entityContext.isEditPermitted());
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EditAction(io.jmix.ui.action.list.EditAction)

Aggregations

UiEntityContext (io.jmix.ui.accesscontext.UiEntityContext)24 MetaClass (io.jmix.core.metamodel.model.MetaClass)20 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)9 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)9 InMemoryCrudEntityContext (io.jmix.core.accesscontext.InMemoryCrudEntityContext)3 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)3 Range (io.jmix.core.metamodel.model.Range)2 ValueSource (io.jmix.ui.component.data.ValueSource)2 ContainerValueSource (io.jmix.ui.component.data.value.ContainerValueSource)2 AccessManager (io.jmix.core.AccessManager)1 EntityStates (io.jmix.core.EntityStates)1 MessageTools (io.jmix.core.MessageTools)1 Metadata (io.jmix.core.Metadata)1 ParamsMap (io.jmix.core.common.util.ParamsMap)1 EntityValues (io.jmix.core.entity.EntityValues)1 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)1 ASSOCIATION (io.jmix.core.metamodel.model.MetaProperty.Type.ASSOCIATION)1 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)1 AccessDeniedException (io.jmix.core.security.AccessDeniedException)1 PersistenceHints (io.jmix.data.PersistenceHints)1