Search in sources :

Example 6 with UiEntityAttributeContext

use of io.jmix.ui.accesscontext.UiEntityAttributeContext 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 7 with UiEntityAttributeContext

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

the class BulkEditorWindow method isEntityAttributeModifyPermitted.

protected boolean isEntityAttributeModifyPermitted(MetaClass metaClass, MetaProperty metaProperty) {
    UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, metaProperty.getName());
    accessManager.applyRegisteredConstraints(attributeContext);
    return attributeContext.canModify();
}
Also used : UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext)

Example 8 with UiEntityAttributeContext

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

the class RelatedEntitiesImpl method isSuitableProperty.

protected boolean isSuitableProperty(MetaClass metaClass, MetaProperty metaProperty, @Nullable Pattern excludePattern) {
    if (!metaProperty.getRange().isClass()) {
        return false;
    }
    // check that entities are placed in the same data store
    MetaClass propertyMetaClass = metaProperty.getRange().asClass();
    String propertyStore = propertyMetaClass.getStore().getName();
    String effectiveStore = metaClass.getStore().getName();
    if (!Objects.equals(effectiveStore, propertyStore)) {
        return false;
    }
    // apply security
    UiEntityContext entityContext = new UiEntityContext(metaClass);
    accessManager.applyRegisteredConstraints(entityContext);
    UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, metaProperty.getName());
    accessManager.applyRegisteredConstraints(attributeContext);
    return entityContext.isViewPermitted() && attributeContext.canView() && (excludePattern == null || !excludePattern.matcher(metaProperty.getName()).matches());
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext)

Example 9 with UiEntityAttributeContext

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

the class EntityInspectorEditor method addTable.

/**
 * Creates a table for the entities in ONE_TO_MANY or MANY_TO_MANY relation with the current one
 */
protected void addTable(InstanceContainer parent, MetaProperty childMeta) {
    MetaClass meta = childMeta.getRange().asClass();
    UiEntityContext entityContext = new UiEntityContext(meta);
    accessManager.applyRegisteredConstraints(entityContext);
    UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(parent.getEntityMetaClass(), childMeta.getName());
    accessManager.applyRegisteredConstraints(attributeContext);
    // don't show empty table if the user don't have permissions on the attribute or the entity
    if (!attributeContext.canView() || !entityContext.isViewPermitted()) {
        return;
    }
    // vertical box for the table and its label
    BoxLayout vbox = uiComponents.create(VBoxLayout.class);
    vbox.setSizeFull();
    Table entitiesTable = InspectorTableBuilder.from(getApplicationContext(), createTableContainer(parent, childMeta, meta)).withMaxTextLength(MAX_TEXT_LENGTH).withSystem(true).withButtons(table -> createButtonsPanel(table, childMeta)).build();
    vbox.add(entitiesTable);
    vbox.expand(entitiesTable);
    vbox.setMargin(true);
    TabSheet.Tab tab = tablesTabSheet.addTab(childMeta.toString(), vbox);
    tab.setCaption(getPropertyCaption(parent.getEntityMetaClass(), childMeta));
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) UiComponentProperties(io.jmix.ui.UiComponentProperties) NoopDataContext(io.jmix.ui.model.impl.NoopDataContext) io.jmix.ui.model(io.jmix.ui.model) InspectorFormBuilder(io.jmix.datatoolsui.screen.entityinspector.assistant.InspectorFormBuilder) Autowired(org.springframework.beans.factory.annotation.Autowired) ParamsMap(io.jmix.core.common.util.ParamsMap) HashMap(java.util.HashMap) EntityValues(io.jmix.core.entity.EntityValues) ArrayList(java.util.ArrayList) ASSOCIATION(io.jmix.core.metamodel.model.MetaProperty.Type.ASSOCIATION) UiComponents(io.jmix.ui.UiComponents) Map(java.util.Map) Action(io.jmix.ui.action.Action) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) Actions(io.jmix.ui.Actions) Collection(java.util.Collection) AccessManager(io.jmix.core.AccessManager) PersistenceHints(io.jmix.data.PersistenceHints) io.jmix.ui.action.list(io.jmix.ui.action.list) Metadata(io.jmix.core.Metadata) UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) InspectorFetchPlanBuilder(io.jmix.datatoolsui.screen.entityinspector.assistant.InspectorFetchPlanBuilder) InspectorTableBuilder(io.jmix.datatoolsui.screen.entityinspector.assistant.InspectorTableBuilder) io.jmix.ui.screen(io.jmix.ui.screen) EntityFormUtils.isMany(io.jmix.datatoolsui.screen.entityinspector.EntityFormUtils.isMany) EntityStates(io.jmix.core.EntityStates) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) MessageTools(io.jmix.core.MessageTools) io.jmix.ui.component(io.jmix.ui.component) MetaClass(io.jmix.core.metamodel.model.MetaClass) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext)

Example 10 with UiEntityAttributeContext

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

the class AppSettingsGridLayoutBuilder method addRowToGrid.

protected void addRowToGrid(InstanceContainer container, GridLayout gridLayout, int currentRow, MetaProperty metaProperty) {
    MetaClass metaClass = container.getEntityMetaClass();
    Range range = metaProperty.getRange();
    UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaClass, metaProperty.getName());
    accessManager.applyRegisteredConstraints(attributeContext);
    if (!attributeContext.canView()) {
        return;
    }
    if (range.isClass()) {
        UiEntityContext entityContext = new UiEntityContext(range.asClass());
        accessManager.applyRegisteredConstraints(entityContext);
        if (!entityContext.isViewPermitted()) {
            return;
        }
    }
    // add label
    Label fieldLabel = uiComponents.create(Label.class);
    fieldLabel.setValue(getPropertyCaption(metaClass, metaProperty));
    fieldLabel.setAlignment(io.jmix.ui.component.Component.Alignment.MIDDLE_LEFT);
    gridLayout.add(fieldLabel, 0, currentRow + 1);
    // current field
    ValueSource valueSource = new ContainerValueSource<>(container, metaProperty.getName());
    ComponentGenerationContext componentContext = new ComponentGenerationContext(metaClass, metaProperty.getName());
    componentContext.setValueSource(valueSource);
    gridLayout.add(createField(metaProperty, range, componentContext), 1, currentRow + 1);
    // default value
    ComponentGenerationContext componentContextForDefaultField = new ComponentGenerationContext(metaClass, metaProperty.getName());
    ValueSource valueSourceForDefaultField = new ContainerValueSource<>(dataComponents.createInstanceContainer(metaClass.getJavaClass()), metaProperty.getName());
    componentContextForDefaultField.setValueSource(valueSourceForDefaultField);
    Field defaultValueField = createField(metaProperty, range, componentContextForDefaultField);
    defaultValueField.setValue(appSettingsTools.getDefaultPropertyValue(metaClass.getJavaClass(), metaProperty.getName()));
    defaultValueField.setEditable(false);
    gridLayout.add(defaultValueField, 2, currentRow + 1);
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) MetaClass(io.jmix.core.metamodel.model.MetaClass) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) Range(io.jmix.core.metamodel.model.Range)

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