Search in sources :

Example 1 with OperationPermissionTarget

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

the class EntityPermissionsFrame method applyPermissionMask.

@SuppressWarnings("unused")
public void applyPermissionMask() {
    Set<OperationPermissionTarget> selected = entityPermissionsTable.getSelected();
    if (!selected.isEmpty() && (selected.size() > 1)) {
        for (OperationPermissionTarget target : selected) {
            for (EntityOperationControl control : operationControls) {
                if (control.isControlVisible() && control.applicableToEntity(target.getEntityClass())) {
                    PermissionVariant variant;
                    if (Boolean.TRUE.equals(control.getAllowChecker().getValue())) {
                        variant = PermissionVariant.ALLOWED;
                    } else if (Boolean.TRUE.equals(control.getDenyChecker().getValue())) {
                        variant = PermissionVariant.DISALLOWED;
                    } else {
                        variant = PermissionVariant.NOTSET;
                    }
                    markTargetPermission(target, control.getMetaProperty(), control.getOperation(), variant);
                }
            }
        }
        // update all after data change
        entityPermissionsTable.repaint();
        showNotification(getMessage("notification.applied"), NotificationType.HUMANIZED);
    }
}
Also used : OperationPermissionTarget(com.haulmont.cuba.gui.app.security.entity.OperationPermissionTarget) PermissionVariant(com.haulmont.cuba.gui.app.security.entity.PermissionVariant)

Example 2 with OperationPermissionTarget

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

the class EntityPermissionsFrame method attachAllCheckBoxListener.

protected void attachAllCheckBoxListener(CheckBox checkBox, final PermissionVariant activeVariant) {
    checkBox.addValueChangeListener(e -> {
        if (itemChanging)
            return;
        if (entityPermissionsTable.getSelected().isEmpty())
            return;
        itemChanging = true;
        PermissionVariant permissionVariant = PermissionUiHelper.getCheckBoxVariant(e.getValue(), activeVariant);
        if (isSingleSelection()) {
            for (EntityOperationControl control : operationControls) {
                OperationPermissionTarget target = entityPermissionsTable.getSingleSelected();
                // noinspection ConstantConditions
                if (control.applicableToEntity(target.getEntityClass())) {
                    markItemPermission(control.getMetaProperty(), control.getOperation(), permissionVariant);
                }
            }
        } else {
            for (EntityOperationControl control : operationControls) {
                control.getAllowChecker().setValue(permissionVariant == PermissionVariant.ALLOWED);
                control.getDenyChecker().setValue(permissionVariant == PermissionVariant.DISALLOWED);
            }
            allAllowCheck.setValue(permissionVariant == PermissionVariant.ALLOWED);
            allDenyCheck.setValue(permissionVariant == PermissionVariant.DISALLOWED);
        }
        entityPermissionsTable.repaint();
        itemChanging = false;
    });
}
Also used : OperationPermissionTarget(com.haulmont.cuba.gui.app.security.entity.OperationPermissionTarget) PermissionVariant(com.haulmont.cuba.gui.app.security.entity.PermissionVariant)

Example 3 with OperationPermissionTarget

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

the class EntityPermissionTargetsDatasource 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<OperationPermissionTarget> entities = permissionConfig.getEntities(userSessionSource.getLocale());
        for (OperationPermissionTarget target : entities) {
            try {
                OperationPermissionTarget cloneTarget = target.clone();
                loadPermissionVariants(cloneTarget);
                attachListener(cloneTarget);
                targets.add(cloneTarget);
            } catch (CloneNotSupportedException e) {
                throw new RuntimeException("Can't clone permission target", e);
            }
        }
    }
    data.clear();
    targets.stream().filter(permittedEntityFilter).filter(t -> permissionsFilter == null || permissionsFilter.test(t)).forEach(t -> data.put(t.getId(), t));
}
Also used : OperationPermissionTarget(com.haulmont.cuba.gui.app.security.entity.OperationPermissionTarget) PermissionVariant(com.haulmont.cuba.gui.app.security.entity.PermissionVariant) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) Predicate(java.util.function.Predicate) CollectionDatasourceImpl(com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl) AppBeans(com.haulmont.cuba.core.global.AppBeans) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) MetaClass(com.haulmont.chile.core.model.MetaClass) PermissionValue(com.haulmont.cuba.gui.app.security.role.edit.PermissionValue) 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) OperationPermissionTarget(com.haulmont.cuba.gui.app.security.entity.OperationPermissionTarget)

Example 4 with OperationPermissionTarget

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

the class EntityPermissionsFrame method markItemPermission.

protected void markItemPermission(String property, EntityOp operation, PermissionVariant permissionVariant) {
    OperationPermissionTarget target = entityPermissionsTable.getSingleSelected();
    markTargetPermission(target, property, operation, permissionVariant);
}
Also used : OperationPermissionTarget(com.haulmont.cuba.gui.app.security.entity.OperationPermissionTarget)

Aggregations

OperationPermissionTarget (com.haulmont.cuba.gui.app.security.entity.OperationPermissionTarget)4 PermissionVariant (com.haulmont.cuba.gui.app.security.entity.PermissionVariant)3 MetaClass (com.haulmont.chile.core.model.MetaClass)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 PermissionValue (com.haulmont.cuba.gui.app.security.role.edit.PermissionValue)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