use of com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget in project cuba by cuba-platform.
the class BasicPermissionTreeDatasource method cloneNode.
private Node<BasicPermissionTarget> cloneNode(Node<BasicPermissionTarget> node) {
Node<BasicPermissionTarget> clone = new Node<>();
try {
BasicPermissionTarget targetClone = node.data.clone();
clone.setData(targetClone);
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
for (Node<BasicPermissionTarget> childNode : node.getChildren()) {
clone.addChild(cloneNode(childNode));
}
return clone;
}
use of com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget 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.gui.app.security.entity.BasicPermissionTarget 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.gui.app.security.entity.BasicPermissionTarget in project cuba by cuba-platform.
the class SpecificPermissionTreeDatasource method filterPermitted.
private Tree<BasicPermissionTarget> filterPermitted(Tree<BasicPermissionTarget> permissions) {
UserSession session = uss.getUserSession();
List<Node<BasicPermissionTarget>> newRootNodes = permissions.getRootNodes().stream().map(root -> filterNode(session, root)).filter(// empty nodes
root -> root.getNumberOfChildren() > 0).collect(Collectors.toCollection(LinkedList::new));
return new Tree<>(newRootNodes);
}
use of com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget in project cuba by cuba-platform.
the class SpecificPermissionsFrame method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
specificPermissionsTree.setStyleProvider(new BasicPermissionTreeStyleProvider());
companion.initPermissionColoredColumns(specificPermissionsTree);
specificPermissionsTreeDs.addItemChangeListener(e -> {
boolean visible = false;
if (e.getItem() != null) {
for (BasicPermissionTarget target : specificPermissionsTree.getSelected()) {
visible |= !target.getId().startsWith(CATEGORY_PREFIX);
}
}
selectedPermissionPanel.setVisible(visible);
updateCheckBoxes(e.getItem());
});
specificPermissionsTreeDs.addItemPropertyChangeListener(e -> {
if ("permissionVariant".equals(e.getProperty())) {
updateCheckBoxes(e.getItem());
}
});
allowCheckBox.addValueChangeListener(e -> {
if (!itemChanging) {
itemChanging = true;
markItemPermission(PermissionUiHelper.getCheckBoxVariant(e.getValue(), PermissionVariant.ALLOWED));
itemChanging = false;
}
});
disallowCheckBox.addValueChangeListener(e -> {
if (!itemChanging) {
itemChanging = true;
markItemPermission(PermissionUiHelper.getCheckBoxVariant(e.getValue(), PermissionVariant.DISALLOWED));
itemChanging = false;
}
});
specificPermissionsDs.refresh();
specificPermissionsTreeDs.setPermissionDs(specificPermissionsDs);
specificPermissionsTreeDs.refresh();
specificPermissionsTree.expandAll();
boolean isCreatePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.CREATE);
boolean isDeletePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.DELETE);
boolean hasPermissionsToModifyPermission = isCreatePermitted && isDeletePermitted;
applyPermissions(hasPermissionsToModifyPermission);
specificEditPane.setEnabled(security.isEntityOpPermitted(metadata.getClass(Role.class), EntityOp.UPDATE));
}
Aggregations