Search in sources :

Example 1 with PropertyDatasource

use of com.haulmont.cuba.gui.data.PropertyDatasource in project cuba by cuba-platform.

the class RemoveAction method checkRemovePermission.

protected boolean checkRemovePermission() {
    CollectionDatasource ds = target.getDatasource();
    if (ds instanceof PropertyDatasource) {
        PropertyDatasource propertyDatasource = (PropertyDatasource) ds;
        MetaClass parentMetaClass = propertyDatasource.getMaster().getMetaClass();
        MetaProperty metaProperty = propertyDatasource.getProperty();
        boolean modifyPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
        if (!modifyPermitted) {
            return false;
        }
        if (metaProperty.getRange().getCardinality() != Range.Cardinality.MANY_TO_MANY) {
            boolean deletePermitted = security.isEntityOpPermitted(ds.getMetaClass(), EntityOp.DELETE);
            if (!deletePermitted) {
                return false;
            }
        }
    } else {
        boolean entityOpPermitted = security.isEntityOpPermitted(ds.getMetaClass(), EntityOp.DELETE);
        if (!entityOpPermitted) {
            return false;
        }
    }
    return true;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 2 with PropertyDatasource

use of com.haulmont.cuba.gui.data.PropertyDatasource in project cuba by cuba-platform.

the class EditAction method actionPerform.

/**
 * This method is invoked by the action owner component.
 *
 * @param component component invoking the action
 */
@Override
public void actionPerform(Component component) {
    if (beforeActionPerformedHandler != null) {
        if (!beforeActionPerformedHandler.beforeActionPerformed())
            return;
    }
    final Set selected = target.getSelected();
    if (selected.size() == 1) {
        Datasource parentDs = null;
        final CollectionDatasource datasource = target.getDatasource();
        if (datasource instanceof PropertyDatasource) {
            MetaProperty metaProperty = ((PropertyDatasource) datasource).getProperty();
            if (metaProperty.getType().equals(MetaProperty.Type.COMPOSITION)) {
                parentDs = datasource;
            }
        }
        Map<String, Object> params = prepareWindowParams();
        internalOpenEditor(datasource, datasource.getItem(), parentDs, params);
    } else if (selected.size() > 1 && bulkEditorIntegration.isEnabled()) {
        UserSession userSession = AppBeans.get(UserSessionSource.class).getUserSession();
        boolean isBulkEditorPermitted = userSession.isSpecificPermitted(BulkEditor.PERMISSION);
        if (isBulkEditorPermitted) {
            // if bulk editor integration enabled and permitted for user
            Map<String, Object> params = ParamsMap.of("metaClass", target.getDatasource().getMetaClass(), "selected", selected, "exclude", bulkEditorIntegration.getExcludePropertiesRegex(), "fieldValidators", bulkEditorIntegration.getFieldValidators(), "modelValidators", bulkEditorIntegration.getModelValidators());
            LegacyFrame frameOwner = (LegacyFrame) target.getFrame().getFrameOwner();
            Window bulkEditor = frameOwner.openWindow("bulkEditor", bulkEditorIntegration.getOpenType(), params);
            bulkEditor.addCloseListener(actionId -> {
                if (Window.COMMIT_ACTION_ID.equals(actionId)) {
                    target.getDatasource().refresh();
                }
                if (target instanceof Component.Focusable) {
                    ((Component.Focusable) target).focus();
                }
                Consumer<BulkEditorCloseEvent> afterEditorCloseHandler = bulkEditorIntegration.getAfterEditorCloseHandler();
                if (afterEditorCloseHandler != null) {
                    afterEditorCloseHandler.accept(new BulkEditorCloseEvent(this, bulkEditor, actionId));
                }
            });
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) java.util(java.util) Datasource(com.haulmont.cuba.gui.data.Datasource) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ParamsMap(com.haulmont.bali.util.ParamsMap) CubaIcon(com.haulmont.cuba.gui.icons.CubaIcon) Messages(com.haulmont.cuba.core.global.Messages) AppBeans(com.haulmont.cuba.core.global.AppBeans) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Icons(com.haulmont.cuba.gui.icons.Icons) Supplier(java.util.function.Supplier) MetaClass(com.haulmont.chile.core.model.MetaClass) Scope(org.springframework.context.annotation.Scope) UserSession(com.haulmont.cuba.security.global.UserSession) Consumer(java.util.function.Consumer) EntityOp(com.haulmont.cuba.security.entity.EntityOp) Configuration(com.haulmont.cuba.core.global.Configuration) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) ClientConfig(com.haulmont.cuba.client.ClientConfig) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(com.haulmont.cuba.core.entity.Entity) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) Consumer(java.util.function.Consumer) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) UserSession(com.haulmont.cuba.security.global.UserSession) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ParamsMap(com.haulmont.bali.util.ParamsMap)

Example 3 with PropertyDatasource

use of com.haulmont.cuba.gui.data.PropertyDatasource in project cuba by cuba-platform.

the class ExcludeAction method checkRemovePermission.

@Override
protected boolean checkRemovePermission() {
    CollectionDatasource ds = target.getDatasource();
    if (ds instanceof PropertyDatasource) {
        PropertyDatasource propertyDatasource = (PropertyDatasource) ds;
        MetaClass parentMetaClass = propertyDatasource.getMaster().getMetaClass();
        MetaProperty metaProperty = propertyDatasource.getProperty();
        boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
        if (!attrPermitted) {
            return false;
        }
    }
    return true;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 4 with PropertyDatasource

use of com.haulmont.cuba.gui.data.PropertyDatasource in project cuba by cuba-platform.

the class AddAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null || target.getDatasource() == null) {
        return false;
    }
    CollectionDatasource ownerDs = target.getDatasource();
    if (ownerDs instanceof PropertyDatasource) {
        PropertyDatasource datasource = (PropertyDatasource) ownerDs;
        MetaClass parentMetaClass = datasource.getMaster().getMetaClass();
        MetaProperty metaProperty = datasource.getProperty();
        boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
        if (!attrPermitted) {
            return false;
        }
    }
    return super.isPermitted();
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

MetaClass (com.haulmont.chile.core.model.MetaClass)4 MetaProperty (com.haulmont.chile.core.model.MetaProperty)4 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)4 PropertyDatasource (com.haulmont.cuba.gui.data.PropertyDatasource)4 ParamsMap (com.haulmont.bali.util.ParamsMap)1 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 Entity (com.haulmont.cuba.core.entity.Entity)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 Messages (com.haulmont.cuba.core.global.Messages)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 CubaIcon (com.haulmont.cuba.gui.icons.CubaIcon)1 Icons (com.haulmont.cuba.gui.icons.Icons)1 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)1 EntityOp (com.haulmont.cuba.security.entity.EntityOp)1 UserSession (com.haulmont.cuba.security.global.UserSession)1