Search in sources :

Example 1 with ActionsPermissions

use of com.haulmont.cuba.gui.components.ActionsPermissions in project cuba by cuba-platform.

the class WindowCreationHelper method applyComponentActionPermission.

/**
 * Process permissions for actions in action holder
 *
 * @param window          Window
 * @param screenId        Screen Id
 * @param permissionValue Permission value
 * @param componentId     Component Id
 */
private static void applyComponentActionPermission(Window window, String screenId, Integer permissionValue, String componentId) {
    final Matcher matcher = COMPONENT_ACTION_PATTERN.matcher(componentId);
    if (matcher.find()) {
        final String customComponentId = matcher.group(1);
        final String actionId = matcher.group(2);
        final Component actionHolderComponent = window.getComponent(customComponentId);
        if (actionHolderComponent != null) {
            if (actionHolderComponent instanceof Component.SecuredActionsHolder) {
                ActionsPermissions permissions = ((Component.SecuredActionsHolder) actionHolderComponent).getActionsPermissions();
                if (permissionValue == UiPermissionValue.HIDE.getValue()) {
                    permissions.addHiddenActionPermission(actionId);
                } else if (permissionValue == UiPermissionValue.READ_ONLY.getValue()) {
                    permissions.addDisabledActionPermission(actionId);
                }
            } else {
                log.warn(String.format("Couldn't apply permission on action %s for component %s in window %s", actionId, customComponentId, screenId));
            }
        } else {
            log.info(String.format("Couldn't find component %s in window %s", componentId, screenId));
        }
    } else {
        log.warn(String.format("Incorrect permission definition for component %s in window %s", componentId, screenId));
    }
}
Also used : ActionsPermissions(com.haulmont.cuba.gui.components.ActionsPermissions) Matcher(java.util.regex.Matcher) Component(com.haulmont.cuba.gui.components.Component)

Aggregations

ActionsPermissions (com.haulmont.cuba.gui.components.ActionsPermissions)1 Component (com.haulmont.cuba.gui.components.Component)1 Matcher (java.util.regex.Matcher)1