Search in sources :

Example 11 with UiEntityContext

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

the class ChangePasswordAction 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.isEditPermitted()) {
        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 12 with UiEntityContext

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

the class ResetRememberMeTokenAction 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.isEditPermitted()) {
        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 13 with UiEntityContext

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

the class ShowUserSubstitutionsAction 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;
    }
    UiEntityContext userSubstitutionContext = new UiEntityContext(metadata.getClass(UserSubstitutionEntity.class));
    accessManager.applyRegisteredConstraints(userSubstitutionContext);
    if (!userSubstitutionContext.isViewPermitted()) {
        return false;
    }
    return super.isPermitted();
}
Also used : UiEntityContext(io.jmix.ui.accesscontext.UiEntityContext) UserSubstitutionEntity(io.jmix.securitydata.entity.UserSubstitutionEntity) MetaClass(io.jmix.core.metamodel.model.MetaClass) EntityDataUnit(io.jmix.ui.component.data.meta.EntityDataUnit)

Example 14 with UiEntityContext

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

use of io.jmix.ui.accesscontext.UiEntityContext 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)

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