Search in sources :

Example 1 with PermissionVariant

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

the class EntityPermissionTargetsDatasource method loadPermissionVariants.

private void loadPermissionVariants(OperationPermissionTarget target) {
    for (Permission p : permissionDs.getItems()) {
        String permissionTargetString = p.getTarget();
        if (StringUtils.isNotEmpty(permissionTargetString)) {
            int delimeterIndex = permissionTargetString.lastIndexOf(Permission.TARGET_PATH_DELIMETER);
            if (delimeterIndex >= 0) {
                String variant = permissionTargetString.substring(delimeterIndex + 1);
                String permissionTarget = permissionTargetString.substring(0, delimeterIndex);
                if (Objects.equals(permissionTarget, target.getPermissionValue())) {
                    PermissionVariant permissionVariant = getPermissionVariant(p);
                    if (EntityOp.CREATE.getId().equals(variant)) {
                        target.setCreatePermissionVariant(permissionVariant);
                    } else if (EntityOp.READ.getId().equals(variant)) {
                        target.setReadPermissionVariant(permissionVariant);
                    } else if (EntityOp.UPDATE.getId().equals(variant)) {
                        target.setUpdatePermissionVariant(permissionVariant);
                    } else if (EntityOp.DELETE.getId().equals(variant)) {
                        target.setDeletePermissionVariant(permissionVariant);
                    }
                }
            }
        }
    }
}
Also used : Permission(com.haulmont.cuba.security.entity.Permission) PermissionVariant(com.haulmont.cuba.gui.app.security.entity.PermissionVariant)

Example 2 with PermissionVariant

use of com.haulmont.cuba.gui.app.security.entity.PermissionVariant 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 3 with PermissionVariant

use of com.haulmont.cuba.gui.app.security.entity.PermissionVariant 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 4 with PermissionVariant

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

the class ScreenPermissionsFrameCompanion method initPermissionColoredColumns.

@Override
public void initPermissionColoredColumns(TreeTable<BasicPermissionTarget> screenPermissionsTree) {
    screenPermissionsTree.addGeneratedColumn("permissionVariant", entity -> {
        PermissionVariant permissionVariant = entity.getPermissionVariant();
        if (permissionVariant == PermissionVariant.NOTSET)
            return null;
        String labelValue = "<span class=\"role-permission-" + permissionVariant.getColor() + "\">" + messages.getMessage(permissionVariant) + "</span>";
        Label label = componentsFactory.createComponent(Label.class);
        label.setHtmlEnabled(true);
        label.setValue(labelValue);
        return label;
    });
}
Also used : Label(com.haulmont.cuba.gui.components.Label) PermissionVariant(com.haulmont.cuba.gui.app.security.entity.PermissionVariant)

Example 5 with PermissionVariant

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

the class SpecificPermissionsFrameCompanion method initPermissionColoredColumns.

@Override
public void initPermissionColoredColumns(TreeTable<BasicPermissionTarget> specificPermissionsTree) {
    specificPermissionsTree.addGeneratedColumn("permissionVariant", entity -> {
        PermissionVariant permissionVariant = entity.getPermissionVariant();
        if (permissionVariant == PermissionVariant.NOTSET)
            return null;
        Label label = componentsFactory.createComponent(Label.class);
        label.setHtmlEnabled(true);
        String labelValue = "<span class=\"role-permission-" + permissionVariant.getColor() + "\">" + messages.getMessage(permissionVariant) + "</span>";
        label.setValue(labelValue);
        return label;
    });
}
Also used : Label(com.haulmont.cuba.gui.components.Label) PermissionVariant(com.haulmont.cuba.gui.app.security.entity.PermissionVariant)

Aggregations

PermissionVariant (com.haulmont.cuba.gui.app.security.entity.PermissionVariant)5 OperationPermissionTarget (com.haulmont.cuba.gui.app.security.entity.OperationPermissionTarget)2 Label (com.haulmont.cuba.gui.components.Label)2 Permission (com.haulmont.cuba.security.entity.Permission)1