Search in sources :

Example 1 with UiPermissionTarget

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

the class UiPermissionsFrame method addUiPermission.

public void addUiPermission() {
    String screen = screenFilter.getValue();
    String component = componentTextField.getValue();
    if (StringUtils.isNotBlank(screen) && StringUtils.isNotBlank(component)) {
        UiPermissionTarget target = new UiPermissionTarget("ui:" + screen + ":" + component, screen + ":" + component, screen + ":" + component, UiPermissionVariant.NOTSET);
        target.setScreen(screen);
        target.setComponent(component);
        uiPermissionTargetsDs.addItem(target);
        uiPermissionsTable.expandPath(target);
        uiPermissionsTable.setSelected(target);
    }
}
Also used : UiPermissionTarget(com.haulmont.cuba.gui.app.security.entity.UiPermissionTarget)

Example 2 with UiPermissionTarget

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

the class UiPermissionsFrame method attachCheckBoxListener.

protected void attachCheckBoxListener(CheckBox checkBox, UiPermissionVariant activeVariant) {
    checkBox.addValueChangeListener(e -> {
        if (itemChanging)
            return;
        if (uiPermissionsTable.getSelected().isEmpty())
            return;
        itemChanging = true;
        UiPermissionVariant permissionVariant = PermissionUiHelper.getCheckBoxVariant(e.getValue(), activeVariant);
        UiPermissionTarget target = uiPermissionsTable.getSingleSelected();
        markItemPermission(permissionVariant, target);
        uiPermissionTargetsDs.updateItem(target);
        itemChanging = false;
    });
}
Also used : UiPermissionVariant(com.haulmont.cuba.gui.app.security.entity.UiPermissionVariant) UiPermissionTarget(com.haulmont.cuba.gui.app.security.entity.UiPermissionTarget)

Example 3 with UiPermissionTarget

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

the class UiPermissionsDatasource method loadData.

@Override
protected void loadData(Map<String, Object> params) {
    if (permissionDs == null)
        return;
    if (!data.isEmpty())
        return;
    clear();
    for (Permission p : permissionDs.getItems()) {
        String permissionTarget = p.getTarget();
        if (StringUtils.isNotEmpty(permissionTarget)) {
            int delimeterIndex = permissionTarget.lastIndexOf(Permission.TARGET_PATH_DELIMETER);
            if (delimeterIndex >= 0) {
                String component = permissionTarget.substring(delimeterIndex + 1);
                String screen = permissionTarget.substring(0, delimeterIndex);
                UiPermissionVariant permissionVariant = getPermissionVariant(p);
                String permissionValue = screen + Permission.TARGET_PATH_DELIMETER + component;
                UiPermissionTarget target = new UiPermissionTarget("ui:" + permissionValue, permissionValue, permissionValue);
                target.setPermissionVariant(permissionVariant);
                target.setComponent(component);
                target.setScreen(screen);
                includeItem(target);
            }
        }
    }
}
Also used : UiPermissionVariant(com.haulmont.cuba.gui.app.security.entity.UiPermissionVariant) Permission(com.haulmont.cuba.security.entity.Permission) UiPermissionTarget(com.haulmont.cuba.gui.app.security.entity.UiPermissionTarget)

Example 4 with UiPermissionTarget

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

the class UiPermissionsFrame method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
    Collection<WindowInfo> windows = sortWindowInfos(windowConfig.getWindows());
    Map<String, Object> screens = new LinkedHashMap<>();
    for (WindowInfo windowInfo : windows) {
        String id = windowInfo.getId();
        String menuId = "menu-config." + id;
        String localeMsg = messages.getMessage(AppConfig.getMessagesPack(), menuId);
        String title = menuId.equals(localeMsg) ? id : localeMsg + " (" + id + ")";
        screens.put(title, id);
    }
    screenFilter.setOptionsMap(screens);
    companion.initPermissionsColoredColumns(uiPermissionsTable);
    uiPermissionTargetsDs.addItemChangeListener(e -> {
        if (!selectedComponentPanel.isVisible() && (e.getItem() != null)) {
            selectedComponentPanel.setVisible(true);
        }
        if (selectedComponentPanel.isVisible() && (e.getItem() == null)) {
            selectedComponentPanel.setVisible(false);
        }
        updateCheckBoxes(e.getItem());
    });
    uiPermissionTargetsDs.addItemPropertyChangeListener(e -> {
        if ("permissionVariant".equals(e.getProperty())) {
            updateCheckBoxes(uiPermissionsTable.getSingleSelected());
        }
    });
    attachCheckBoxListener(readOnlyCheckBox, UiPermissionVariant.READ_ONLY);
    attachCheckBoxListener(hideCheckBox, UiPermissionVariant.HIDE);
    attachCheckBoxListener(showCheckBox, UiPermissionVariant.SHOW);
    uiPermissionTargetsDs.setPermissionDs(uiPermissionsDs);
    uiPermissionsDs.refresh();
    uiPermissionTargetsDs.refresh();
    boolean isCreatePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.CREATE);
    boolean isDeletePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.DELETE);
    boolean isRoleEditPermitted = security.isEntityOpPermitted(metadata.getClass(Role.class), EntityOp.UPDATE);
    final boolean hasPermissionsToModifyPermission = isCreatePermitted && isDeletePermitted && isRoleEditPermitted;
    RemoveAction removeAction = new RemoveAction(uiPermissionsTable, false);
    removeAction.setAfterRemoveHandler(removedItems -> {
        if (!removedItems.isEmpty()) {
            UiPermissionTarget removedPermission = (UiPermissionTarget) removedItems.iterator().next();
            markItemPermission(UiPermissionVariant.NOTSET, removedPermission);
        }
    });
    removeAction.setEnabled(hasPermissionsToModifyPermission);
    removeAction.setIcon(null);
    removeAction.setCaption(getMessage("actions.RemoveSelected"));
    removePermissionBtn.setAction(removeAction);
    uiPermissionsTable.addAction(removeAction);
    editPane.setEnabled(security.isEntityOpPermitted(Role.class, EntityOp.UPDATE));
    applyPermissions(hasPermissionsToModifyPermission);
}
Also used : WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) Role(com.haulmont.cuba.security.entity.Role) RemoveAction(com.haulmont.cuba.gui.components.actions.RemoveAction) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) UiPermissionTarget(com.haulmont.cuba.gui.app.security.entity.UiPermissionTarget)

Aggregations

UiPermissionTarget (com.haulmont.cuba.gui.app.security.entity.UiPermissionTarget)4 UiPermissionVariant (com.haulmont.cuba.gui.app.security.entity.UiPermissionVariant)2 RemoveAction (com.haulmont.cuba.gui.components.actions.RemoveAction)1 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)1 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)1 Permission (com.haulmont.cuba.security.entity.Permission)1 Role (com.haulmont.cuba.security.entity.Role)1