Search in sources :

Example 16 with UiEntityAttributeContext

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

the class AbstractTable method setupColumnSettings.

protected void setupColumnSettings(EntityTableItems<E> entityTableSource) {
    MetaClass metaClass = entityTableSource.getEntityMetaClass();
    List<MetaPropertyPath> editableColumns = Collections.emptyList();
    for (Map.Entry<Object, Column<E>> entry : this.columns.entrySet()) {
        Object columnId = entry.getKey();
        Column<E> column = entry.getValue();
        String caption;
        if (column != null) {
            caption = getColumnCaption(columnId, column);
        } else {
            caption = StringUtils.capitalize(getColumnCaption(columnId));
        }
        setColumnHeader(columnId, caption);
        if (column != null) {
            if (column.isEditable() && (columnId instanceof MetaPropertyPath)) {
                MetaPropertyPath propertyPath = ((MetaPropertyPath) columnId);
                UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, propertyPath.toString());
                accessManager.applyRegisteredConstraints(attributeContext);
                if (attributeContext.canModify() && attributeContext.canView()) {
                    if (editableColumns.isEmpty()) {
                        editableColumns = new ArrayList<>();
                    }
                    editableColumns.add(propertyPath);
                } else {
                    log.info("Editable column '{}' is not permitted to read or update", propertyPath.toString());
                }
            }
            if (column.isCollapsed() && component.isColumnCollapsingAllowed()) {
                UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, columnId.toString());
                accessManager.applyRegisteredConstraints(attributeContext);
                if (!(columnId instanceof MetaPropertyPath) || attributeContext.canView()) {
                    component.setColumnCollapsed(column.getId(), true);
                }
            }
            if (column.getAggregation() != null) {
                checkAggregation(column.getAggregation());
                component.addContainerPropertyAggregation(column.getId(), WrapperUtils.convertAggregationType(column.getAggregation().getType()));
            }
        }
    }
    if (isEditable() && !editableColumns.isEmpty()) {
        UiEntityContext entityContext = new UiEntityContext(metaClass);
        accessManager.applyRegisteredConstraints(entityContext);
        if (entityContext.isViewPermitted() && entityContext.isEditPermitted()) {
            setEditableColumns(editableColumns);
        } else {
            log.info("Entity '{}' is not permitted to read or update", metaClass.getName());
        }
    }
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) KeyValueMetaClass(io.jmix.core.impl.keyvalue.KeyValueMetaClass) MetaClass(io.jmix.core.metamodel.model.MetaClass)

Example 17 with UiEntityAttributeContext

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

the class TableFieldFactoryImpl method applyPermissions.

protected void applyPermissions(io.jmix.ui.component.Component columnComponent) {
    if (columnComponent instanceof HasValueSource && columnComponent instanceof io.jmix.ui.component.Component.Editable) {
        HasValueSource component = (HasValueSource) columnComponent;
        MetaPropertyPath propertyPath = ((EntityValueSource) component.getValueSource()).getMetaPropertyPath();
        if (propertyPath != null) {
            io.jmix.ui.component.Component.Editable editable = (io.jmix.ui.component.Component.Editable) component;
            UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(propertyPath);
            accessManager.applyRegisteredConstraints(attributeContext);
            editable.setEditable(editable.isEditable() && attributeContext.canModify());
        }
    }
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) io.jmix.ui.component(io.jmix.ui.component) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) HasValueSource(io.jmix.ui.component.data.HasValueSource) Component(com.vaadin.ui.Component)

Example 18 with UiEntityAttributeContext

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

the class DataComponents method createCollectionContainer.

/**
 * Creates {@code CollectionPropertyContainer}.
 */
@SuppressWarnings("unchecked")
public <E> CollectionPropertyContainer<E> createCollectionContainer(Class<E> entityClass, InstanceContainer<?> masterContainer, String property) {
    CollectionPropertyContainerImpl<E> container = new CollectionPropertyContainerImpl<>(metadata.getClass(entityClass), masterContainer, property);
    autowire(container);
    container.setSorter(sorterFactory.createCollectionPropertyContainerSorter(container));
    UiEntityContext entityContext = new UiEntityContext(masterContainer.getEntityMetaClass());
    accessManager.applyRegisteredConstraints(entityContext);
    UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(masterContainer.getEntityMetaClass(), property);
    accessManager.applyRegisteredConstraints(attributeContext);
    if (attributeContext.canView() && entityContext.isViewPermitted()) {
        masterContainer.addItemChangeListener(e -> {
            Object item = masterContainer.getItemOrNull();
            container.setItems(item != null ? EntityValues.getValue(item, property) : null);
        });
        masterContainer.addItemPropertyChangeListener(e -> {
            if (e.getProperty().equals(property)) {
                container.setDisconnectedItems((Collection<E>) e.getValue());
            }
        });
    }
    return container;
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext)

Example 19 with UiEntityAttributeContext

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

the class DataComponents method createInstanceContainer.

/**
 * Creates {@code InstancePropertyContainer}.
 */
@SuppressWarnings("unchecked")
public <E> InstancePropertyContainer<E> createInstanceContainer(Class<E> entityClass, InstanceContainer<?> masterContainer, String property) {
    InstancePropertyContainerImpl<E> container = new InstancePropertyContainerImpl<>(metadata.getClass(entityClass), masterContainer, property);
    autowire(container);
    UiEntityContext entityContext = new UiEntityContext(masterContainer.getEntityMetaClass());
    accessManager.applyRegisteredConstraints(entityContext);
    UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(masterContainer.getEntityMetaClass(), property);
    accessManager.applyRegisteredConstraints(attributeContext);
    if (entityContext.isViewPermitted() && attributeContext.canView()) {
        masterContainer.addItemChangeListener(e -> {
            Object item = masterContainer.getItemOrNull();
            container.setItem(item != null ? EntityValues.getValue(item, property) : null);
        });
        masterContainer.addItemPropertyChangeListener(e -> {
            if (e.getProperty().equals(property)) {
                container.setItem((E) e.getValue());
            }
        });
    }
    return container;
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext)

Example 20 with UiEntityAttributeContext

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

the class ReadOnlyScreensSupport method isEditableConsideringDataBinding.

protected boolean isEditableConsideringDataBinding(Component component, boolean editable) {
    boolean shouldBeEditable = true;
    if (component instanceof HasValueSource && ((HasValueSource) component).getValueSource() != null) {
        ValueSource valueSource = ((HasValueSource) component).getValueSource();
        shouldBeEditable = !valueSource.isReadOnly();
        if (valueSource instanceof EntityValueSource && ((EntityValueSource) valueSource).isDataModelSecurityEnabled()) {
            MetaPropertyPath metaPropertyPath = ((EntityValueSource) valueSource).getMetaPropertyPath();
            UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaPropertyPath);
            accessManager.applyRegisteredConstraints(attributeContext);
            if (!attributeContext.canModify() || !attributeContext.canView()) {
                shouldBeEditable = false;
            }
        }
    }
    return editable && shouldBeEditable;
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) HasValueSource(io.jmix.ui.component.data.HasValueSource) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) HasValueSource(io.jmix.ui.component.data.HasValueSource)

Aggregations

UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)20 MetaClass (io.jmix.core.metamodel.model.MetaClass)13 UiEntityContext (io.jmix.ui.accesscontext.UiEntityContext)9 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)7 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)5 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)5 Nested (io.jmix.ui.model.Nested)4 ValueSource (io.jmix.ui.component.data.ValueSource)3 ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)3 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)3 Range (io.jmix.core.metamodel.model.Range)2 io.jmix.ui.component (io.jmix.ui.component)2 HasValueSource (io.jmix.ui.component.data.HasValueSource)2 ContainerValueSource (io.jmix.ui.component.data.value.ContainerValueSource)2 Component (com.vaadin.ui.Component)1 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