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);
}
}
}
}
}
}
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));
}
}
}
}
}
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();
}
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);
}
}
}
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);
}
}
}
Aggregations