use of com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget in project cuba by cuba-platform.
the class MultiplePermissionTargetsDatasource method loadData.
@Override
protected void loadData(Map<String, Object> params) {
if (permissionDs == null)
return;
if (targets == null) {
targets = new ArrayList<>();
PermissionConfig permissionConfig = AppBeans.get(PermissionConfig.class);
List<MultiplePermissionTarget> entityAttrs = permissionConfig.getEntityAttributes(AppBeans.get(UserSessionSource.class).getLocale());
for (MultiplePermissionTarget target : entityAttrs) {
try {
MultiplePermissionTarget cloneTarget = target.clone();
loadPermissionVariants(cloneTarget);
attachListener(cloneTarget);
targets.add(cloneTarget);
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
}
clear();
targets.stream().filter(permittedEntityFilter).filter(t -> permissionsFilter == null || permissionsFilter.test(t)).forEach(t -> data.put(t.getId(), t));
}
use of com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget in project cuba by cuba-platform.
the class AttributePermissionsFrame method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
if (!PersistenceHelper.isNew(params.get("ITEM"))) {
assignedOnlyCheckBox.setValue(Boolean.TRUE);
}
assignedOnlyCheckBox.addValueChangeListener(e -> {
applyFilter();
});
attributeTargetsDs.setPermissionDs(propertyPermissionsDs);
attributeTargetsDs.setFilter(new EntityNameFilter<>(metadata, assignedOnlyCheckBox, systemLevelCheckBox, entityFilter));
propertyPermissionsDs.refresh();
// client specific code
companion.initPermissionColoredColumn(propertyPermissionsTable);
entityFilter.addEnterPressListener(e -> applyFilter());
attributeTargetsDs.addItemChangeListener(e -> {
MultiplePermissionTarget item = e.getItem();
boolean itemExists = item != null;
if (!selectedEntityPanel.isVisible() && itemExists) {
selectedEntityPanel.setVisible(true);
}
if (selectedEntityPanel.isVisible() && (item == null)) {
selectedEntityPanel.setVisible(false);
}
String name = null;
String localName = null;
if (itemExists) {
name = item.getEntityMetaClassName();
localName = item.getLocalName();
}
selectedTargetCaption.setVisible(itemExists);
selectedTargetCaption.setValue(name);
selectedTargetCaption.setDescription(name);
selectedTargetLocalCaption.setVisible(itemExists);
selectedTargetLocalCaption.setValue(localName);
selectedTargetLocalCaption.setDescription(localName);
clearEditGrid();
if (itemExists) {
compileEditPane(item);
}
});
attributeTargetsDs.refresh();
boolean isCreatePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.CREATE);
boolean isDeletePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.DELETE);
hasPermissionsToModifyPermission = isCreatePermitted && isDeletePermitted;
editPane.setEnabled(security.isEntityOpPermitted(metadata.getClass(Role.class), EntityOp.UPDATE));
}
use of com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget in project cuba by cuba-platform.
the class AttributePermissionsFrame method attachAllCheckboxListener.
protected void attachAllCheckboxListener(CheckBox checkBox, final AttributePermissionVariant activeVariant) {
checkBox.addValueChangeListener(e -> {
if (itemChanging) {
return;
}
if (propertyPermissionsTable.getSelected().isEmpty()) {
return;
}
itemChanging = true;
MultiplePermissionTarget item = propertyPermissionsTable.getSingleSelected();
if (item != null) {
for (AttributePermissionControl control : permissionControls) {
AttributePermissionVariant permissionVariant = PermissionUiHelper.getCheckBoxVariant(e.getValue(), activeVariant);
control.markTargetPermission(permissionVariant);
control.updateCheckers(permissionVariant);
}
// todo enforce value change
propertyPermissionsTable.repaint();
allModifyCheck.setValue(isAllModified());
allReadOnlyCheck.setValue(isAllReadOnly());
allHideCheck.setValue(isAllHide());
}
itemChanging = false;
});
}
Aggregations