Search in sources :

Example 1 with BasicPermissionTarget

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

the class BasicPermissionTreeDatasource method cloneNode.

private Node<BasicPermissionTarget> cloneNode(Node<BasicPermissionTarget> node) {
    Node<BasicPermissionTarget> clone = new Node<>();
    try {
        BasicPermissionTarget targetClone = node.data.clone();
        clone.setData(targetClone);
    } catch (CloneNotSupportedException e) {
        throw new RuntimeException(e);
    }
    for (Node<BasicPermissionTarget> childNode : node.getChildren()) {
        clone.addChild(cloneNode(childNode));
    }
    return clone;
}
Also used : Node(com.haulmont.bali.datastruct.Node) BasicPermissionTarget(com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget)

Example 2 with BasicPermissionTarget

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

the class ScreenPermissionsFrame method markItemPermission.

protected void markItemPermission(PermissionVariant permissionVariant) {
    for (BasicPermissionTarget target : screenPermissionsTree.getSelected()) {
        target.setPermissionVariant(permissionVariant);
        if (permissionVariant != PermissionVariant.NOTSET) {
            // Create permission
            int value = PermissionUiHelper.getPermissionValue(permissionVariant);
            PermissionUiHelper.createPermissionItem(screenPermissionsDs, roleDs, target.getPermissionValue(), PermissionType.SCREEN, value);
        } else {
            // Remove permission
            Permission permission = null;
            for (Permission p : screenPermissionsDs.getItems()) {
                if (Objects.equals(p.getTarget(), target.getPermissionValue())) {
                    permission = p;
                    break;
                }
            }
            if (permission != null) {
                screenPermissionsDs.removeItem(permission);
            }
        }
    }
    // trigger generated column update
    screenPermissionsTree.repaint();
}
Also used : Permission(com.haulmont.cuba.security.entity.Permission) BasicPermissionTarget(com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget)

Example 3 with BasicPermissionTarget

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

the class SpecificPermissionsFrame method markItemPermission.

protected void markItemPermission(PermissionVariant permissionVariant) {
    for (BasicPermissionTarget target : specificPermissionsTree.getSelected()) {
        if (!target.getId().startsWith(CATEGORY_PREFIX)) {
            target.setPermissionVariant(permissionVariant);
            if (permissionVariant != PermissionVariant.NOTSET) {
                // Create permission
                int value = PermissionUiHelper.getPermissionValue(permissionVariant);
                PermissionUiHelper.createPermissionItem(specificPermissionsDs, roleDs, target.getPermissionValue(), PermissionType.SPECIFIC, value);
            } else {
                // Remove permission
                Permission permission = null;
                for (Permission p : specificPermissionsDs.getItems()) {
                    if (Objects.equals(p.getTarget(), target.getPermissionValue())) {
                        permission = p;
                        break;
                    }
                }
                if (permission != null) {
                    specificPermissionsDs.removeItem(permission);
                }
            }
            // trigger generated column update
            specificPermissionsTreeDs.updateItem(target);
        }
    }
}
Also used : Permission(com.haulmont.cuba.security.entity.Permission) BasicPermissionTarget(com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget)

Example 4 with BasicPermissionTarget

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

the class SpecificPermissionTreeDatasource method filterPermitted.

private Tree<BasicPermissionTarget> filterPermitted(Tree<BasicPermissionTarget> permissions) {
    UserSession session = uss.getUserSession();
    List<Node<BasicPermissionTarget>> newRootNodes = permissions.getRootNodes().stream().map(root -> filterNode(session, root)).filter(// empty nodes
    root -> root.getNumberOfChildren() > 0).collect(Collectors.toCollection(LinkedList::new));
    return new Tree<>(newRootNodes);
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession) BasicPermissionTarget(com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget) List(java.util.List) PermissionConfig(com.haulmont.cuba.gui.config.PermissionConfig) Tree(com.haulmont.bali.datastruct.Tree) Node(com.haulmont.bali.datastruct.Node) LinkedList(java.util.LinkedList) AppBeans(com.haulmont.cuba.core.global.AppBeans) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Collectors(java.util.stream.Collectors) UserSession(com.haulmont.cuba.security.global.UserSession) Node(com.haulmont.bali.datastruct.Node) Tree(com.haulmont.bali.datastruct.Tree)

Example 5 with BasicPermissionTarget

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

the class SpecificPermissionsFrame method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    specificPermissionsTree.setStyleProvider(new BasicPermissionTreeStyleProvider());
    companion.initPermissionColoredColumns(specificPermissionsTree);
    specificPermissionsTreeDs.addItemChangeListener(e -> {
        boolean visible = false;
        if (e.getItem() != null) {
            for (BasicPermissionTarget target : specificPermissionsTree.getSelected()) {
                visible |= !target.getId().startsWith(CATEGORY_PREFIX);
            }
        }
        selectedPermissionPanel.setVisible(visible);
        updateCheckBoxes(e.getItem());
    });
    specificPermissionsTreeDs.addItemPropertyChangeListener(e -> {
        if ("permissionVariant".equals(e.getProperty())) {
            updateCheckBoxes(e.getItem());
        }
    });
    allowCheckBox.addValueChangeListener(e -> {
        if (!itemChanging) {
            itemChanging = true;
            markItemPermission(PermissionUiHelper.getCheckBoxVariant(e.getValue(), PermissionVariant.ALLOWED));
            itemChanging = false;
        }
    });
    disallowCheckBox.addValueChangeListener(e -> {
        if (!itemChanging) {
            itemChanging = true;
            markItemPermission(PermissionUiHelper.getCheckBoxVariant(e.getValue(), PermissionVariant.DISALLOWED));
            itemChanging = false;
        }
    });
    specificPermissionsDs.refresh();
    specificPermissionsTreeDs.setPermissionDs(specificPermissionsDs);
    specificPermissionsTreeDs.refresh();
    specificPermissionsTree.expandAll();
    boolean isCreatePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.CREATE);
    boolean isDeletePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.DELETE);
    boolean hasPermissionsToModifyPermission = isCreatePermitted && isDeletePermitted;
    applyPermissions(hasPermissionsToModifyPermission);
    specificEditPane.setEnabled(security.isEntityOpPermitted(metadata.getClass(Role.class), EntityOp.UPDATE));
}
Also used : BasicPermissionTreeStyleProvider(com.haulmont.cuba.gui.app.security.role.edit.BasicPermissionTreeStyleProvider) BasicPermissionTarget(com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget)

Aggregations

BasicPermissionTarget (com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget)5 Node (com.haulmont.bali.datastruct.Node)2 Permission (com.haulmont.cuba.security.entity.Permission)2 Tree (com.haulmont.bali.datastruct.Tree)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 BasicPermissionTreeStyleProvider (com.haulmont.cuba.gui.app.security.role.edit.BasicPermissionTreeStyleProvider)1 PermissionConfig (com.haulmont.cuba.gui.config.PermissionConfig)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1