Search in sources :

Example 1 with UiPermissionDescriptor

use of com.haulmont.cuba.gui.app.security.role.edit.UiPermissionDescriptor in project cuba by cuba-platform.

the class WindowCreationHelper method applyCompositeComponentPermission.

private static void applyCompositeComponentPermission(Window window, String screenId, Integer permissionValue, String componentId) {
    final Matcher matcher = INNER_COMPONENT_PATTERN.matcher(componentId);
    if (matcher.find()) {
        final String customComponentId = matcher.group(1);
        final String subComponentId = matcher.group(2);
        final Component compositeComponent = window.getComponent(customComponentId);
        if (compositeComponent != null) {
            if (compositeComponent instanceof Component.UiPermissionAware) {
                Component.UiPermissionAware uiPermissionAwareComponent = (Component.UiPermissionAware) compositeComponent;
                UiPermissionValue uiPermissionValue = UiPermissionValue.fromId(permissionValue);
                UiPermissionDescriptor permissionDescriptor;
                if (subComponentId.contains("<")) {
                    final Matcher actionMatcher = COMPONENT_ACTION_PATTERN.matcher(subComponentId);
                    if (actionMatcher.find()) {
                        final String actionHolderComponentId = actionMatcher.group(1);
                        final String actionId = actionMatcher.group(2);
                        permissionDescriptor = new UiPermissionDescriptor(uiPermissionValue, screenId, actionHolderComponentId, actionId);
                    } else {
                        log.warn(String.format("Incorrect permission definition for component %s in window %s", subComponentId, screenId));
                        return;
                    }
                } else {
                    permissionDescriptor = new UiPermissionDescriptor(uiPermissionValue, screenId, subComponentId);
                }
                uiPermissionAwareComponent.applyPermission(permissionDescriptor);
            }
        } else {
            log.info(String.format("Couldn't find component %s in window %s", componentId, screenId));
        }
    }
}
Also used : UiPermissionValue(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue) Matcher(java.util.regex.Matcher) Component(com.haulmont.cuba.gui.components.Component) UiPermissionDescriptor(com.haulmont.cuba.gui.app.security.role.edit.UiPermissionDescriptor)

Aggregations

UiPermissionDescriptor (com.haulmont.cuba.gui.app.security.role.edit.UiPermissionDescriptor)1 UiPermissionValue (com.haulmont.cuba.gui.app.security.role.edit.UiPermissionValue)1 Component (com.haulmont.cuba.gui.components.Component)1 Matcher (java.util.regex.Matcher)1