Search in sources :

Example 1 with MultiplePermissionTarget

use of com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget in project cuba by cuba-platform.

the class MultiplePermissionTargetsDatasource method loadData.

@Override
protected void loadData(Map<String, Object> params) {
    if (permissionDs == null)
        return;
    if (targets == null) {
        targets = new ArrayList<>();
        PermissionConfig permissionConfig = AppBeans.get(PermissionConfig.class);
        List<MultiplePermissionTarget> entityAttrs = permissionConfig.getEntityAttributes(AppBeans.get(UserSessionSource.class).getLocale());
        for (MultiplePermissionTarget target : entityAttrs) {
            try {
                MultiplePermissionTarget cloneTarget = target.clone();
                loadPermissionVariants(cloneTarget);
                attachListener(cloneTarget);
                targets.add(cloneTarget);
            } catch (CloneNotSupportedException e) {
                throw new RuntimeException(e);
            }
        }
    }
    clear();
    targets.stream().filter(permittedEntityFilter).filter(t -> permissionsFilter == null || permissionsFilter.test(t)).forEach(t -> data.put(t.getId(), t));
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) AttributePermissionVariant(com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant) Predicate(java.util.function.Predicate) CollectionDatasourceImpl(com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl) PropertyPermissionValue(com.haulmont.cuba.gui.app.security.role.edit.PropertyPermissionValue) AppBeans(com.haulmont.cuba.core.global.AppBeans) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) MetaClass(com.haulmont.chile.core.model.MetaClass) MultiplePermissionTarget(com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget) UserSession(com.haulmont.cuba.security.global.UserSession) Permission(com.haulmont.cuba.security.entity.Permission) EntityOp(com.haulmont.cuba.security.entity.EntityOp) PermissionConfig(com.haulmont.cuba.gui.config.PermissionConfig) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) PermissionConfig(com.haulmont.cuba.gui.config.PermissionConfig) MultiplePermissionTarget(com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget)

Example 2 with MultiplePermissionTarget

use of com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget in project cuba by cuba-platform.

the class AttributePermissionsFrame method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    if (!PersistenceHelper.isNew(params.get("ITEM"))) {
        assignedOnlyCheckBox.setValue(Boolean.TRUE);
    }
    assignedOnlyCheckBox.addValueChangeListener(e -> {
        applyFilter();
    });
    attributeTargetsDs.setPermissionDs(propertyPermissionsDs);
    attributeTargetsDs.setFilter(new EntityNameFilter<>(metadata, assignedOnlyCheckBox, systemLevelCheckBox, entityFilter));
    propertyPermissionsDs.refresh();
    // client specific code
    companion.initPermissionColoredColumn(propertyPermissionsTable);
    entityFilter.addEnterPressListener(e -> applyFilter());
    attributeTargetsDs.addItemChangeListener(e -> {
        MultiplePermissionTarget item = e.getItem();
        boolean itemExists = item != null;
        if (!selectedEntityPanel.isVisible() && itemExists) {
            selectedEntityPanel.setVisible(true);
        }
        if (selectedEntityPanel.isVisible() && (item == null)) {
            selectedEntityPanel.setVisible(false);
        }
        String name = null;
        String localName = null;
        if (itemExists) {
            name = item.getEntityMetaClassName();
            localName = item.getLocalName();
        }
        selectedTargetCaption.setVisible(itemExists);
        selectedTargetCaption.setValue(name);
        selectedTargetCaption.setDescription(name);
        selectedTargetLocalCaption.setVisible(itemExists);
        selectedTargetLocalCaption.setValue(localName);
        selectedTargetLocalCaption.setDescription(localName);
        clearEditGrid();
        if (itemExists) {
            compileEditPane(item);
        }
    });
    attributeTargetsDs.refresh();
    boolean isCreatePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.CREATE);
    boolean isDeletePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.DELETE);
    hasPermissionsToModifyPermission = isCreatePermitted && isDeletePermitted;
    editPane.setEnabled(security.isEntityOpPermitted(metadata.getClass(Role.class), EntityOp.UPDATE));
}
Also used : MultiplePermissionTarget(com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget)

Example 3 with MultiplePermissionTarget

use of com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget in project cuba by cuba-platform.

the class AttributePermissionsFrame method attachAllCheckboxListener.

protected void attachAllCheckboxListener(CheckBox checkBox, final AttributePermissionVariant activeVariant) {
    checkBox.addValueChangeListener(e -> {
        if (itemChanging) {
            return;
        }
        if (propertyPermissionsTable.getSelected().isEmpty()) {
            return;
        }
        itemChanging = true;
        MultiplePermissionTarget item = propertyPermissionsTable.getSingleSelected();
        if (item != null) {
            for (AttributePermissionControl control : permissionControls) {
                AttributePermissionVariant permissionVariant = PermissionUiHelper.getCheckBoxVariant(e.getValue(), activeVariant);
                control.markTargetPermission(permissionVariant);
                control.updateCheckers(permissionVariant);
            }
            // todo enforce value change
            propertyPermissionsTable.repaint();
            allModifyCheck.setValue(isAllModified());
            allReadOnlyCheck.setValue(isAllReadOnly());
            allHideCheck.setValue(isAllHide());
        }
        itemChanging = false;
    });
}
Also used : AttributePermissionVariant(com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant) MultiplePermissionTarget(com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget)

Aggregations

MultiplePermissionTarget (com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget)3 AttributePermissionVariant (com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 PropertyPermissionValue (com.haulmont.cuba.gui.app.security.role.edit.PropertyPermissionValue)1 PermissionConfig (com.haulmont.cuba.gui.config.PermissionConfig)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 CollectionDatasourceImpl (com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl)1 EntityOp (com.haulmont.cuba.security.entity.EntityOp)1 Permission (com.haulmont.cuba.security.entity.Permission)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 java.util (java.util)1 Predicate (java.util.function.Predicate)1 StringUtils (org.apache.commons.lang.StringUtils)1