Search in sources :

Example 1 with Permission

use of com.haulmont.cuba.security.entity.Permission 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 Permission

use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.

the class MultiplePermissionTargetsDatasource method loadPermissionVariants.

private void loadPermissionVariants(final MultiplePermissionTarget target) {
    for (Permission p : permissionDs.getItems()) {
        String permissionTargetString = p.getTarget();
        if (StringUtils.isNotEmpty(permissionTargetString)) {
            int delimiterIndex = permissionTargetString.lastIndexOf(Permission.TARGET_PATH_DELIMETER);
            if (delimiterIndex >= 0) {
                String attribute = permissionTargetString.substring(delimiterIndex + 1);
                String permissionTarget = permissionTargetString.substring(0, delimiterIndex);
                if (Objects.equals(permissionTarget, target.getPermissionValue())) {
                    target.assignPermissionVariant(attribute, getPermissionVariant(p));
                }
            }
        }
    }
}
Also used : Permission(com.haulmont.cuba.security.entity.Permission)

Example 3 with Permission

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

use of com.haulmont.cuba.security.entity.Permission 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 5 with Permission

use of com.haulmont.cuba.security.entity.Permission in project cuba by cuba-platform.

the class UiPermissionsFrame method markItemPermission.

protected void markItemPermission(UiPermissionVariant permissionVariant, UiPermissionTarget target) {
    if (target != null) {
        target.setPermissionVariant(permissionVariant);
        if (permissionVariant != UiPermissionVariant.NOTSET) {
            // Create permission
            int value = PermissionUiHelper.getPermissionValue(permissionVariant);
            PermissionUiHelper.createPermissionItem(uiPermissionsDs, roleDs, target.getPermissionValue(), PermissionType.UI, value);
        } else {
            // Remove permission
            Permission permission = null;
            for (Permission p : uiPermissionsDs.getItems()) {
                if (Objects.equals(p.getTarget(), target.getPermissionValue())) {
                    permission = p;
                    break;
                }
            }
            if (permission != null)
                uiPermissionsDs.removeItem(permission);
        }
    }
}
Also used : Permission(com.haulmont.cuba.security.entity.Permission)

Aggregations

Permission (com.haulmont.cuba.security.entity.Permission)15 Role (com.haulmont.cuba.security.entity.Role)4 PermissionVariant (com.haulmont.cuba.gui.app.security.entity.PermissionVariant)3 Test (org.junit.Test)3 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 BasicPermissionTarget (com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget)2 UiPermissionVariant (com.haulmont.cuba.gui.app.security.entity.UiPermissionVariant)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 DataService (com.haulmont.cuba.core.app.DataService)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 View (com.haulmont.cuba.core.global.View)1 RestorablePermissionDatasource (com.haulmont.cuba.gui.app.security.ds.RestorablePermissionDatasource)1 AttributePermissionVariant (com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant)1 OperationPermissionTarget (com.haulmont.cuba.gui.app.security.entity.OperationPermissionTarget)1 UiPermissionTarget (com.haulmont.cuba.gui.app.security.entity.UiPermissionTarget)1 PermissionValue (com.haulmont.cuba.gui.app.security.role.edit.PermissionValue)1 PermissionConfig (com.haulmont.cuba.gui.config.PermissionConfig)1