mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-03 03:38:33 +08:00
PL-8993 If an entity or entity attribute has read-only access user does not see it in DataGrid edit mode
This commit is contained in:
parent
990c576812
commit
cc8143cbcf
@ -79,7 +79,7 @@ org.hibernate/hibernate-core = 3.3.1.GA
|
||||
org.hibernate/hibernate-validator = 5.4.1.Final
|
||||
org.glassfish.web/javax.el = 2.2.6
|
||||
|
||||
com.vaadin = 7.7.8.cuba.5
|
||||
com.vaadin = 7.7.8.cuba.6
|
||||
com.vaadin/vaadin-shared = ${com.vaadin}
|
||||
com.vaadin/vaadin-server = ${com.vaadin}
|
||||
com.vaadin/vaadin-client = ${com.vaadin}
|
||||
|
@ -734,6 +734,8 @@ public class WebDataGrid<E extends Entity> extends WebAbstractComponent<CubaGrid
|
||||
}
|
||||
|
||||
assignAutoDebugId();
|
||||
|
||||
component.setCollectionDatasource(datasource);
|
||||
}
|
||||
|
||||
protected void addInitialColumns(CollectionDatasource datasource) {
|
||||
@ -3036,7 +3038,7 @@ public class WebDataGrid<E extends Entity> extends WebAbstractComponent<CubaGrid
|
||||
if (gridColumn != null) {
|
||||
return gridColumn.isEditable();
|
||||
}
|
||||
return editable && !generated && !isRepresentsCollection();
|
||||
return editable && !generated && !isRepresentsCollection() && isEditingPermitted();
|
||||
}
|
||||
|
||||
protected boolean isRepresentsCollection() {
|
||||
@ -3048,11 +3050,21 @@ public class WebDataGrid<E extends Entity> extends WebAbstractComponent<CubaGrid
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isEditingPermitted() {
|
||||
if (propertyPath != null) {
|
||||
MetaClass metaClass = propertyPath.getMetaProperty().getDomain();
|
||||
return owner.security.isEntityAttrUpdatePermitted(metaClass, propertyPath.toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEditable(boolean editable) {
|
||||
this.editable = editable;
|
||||
if (gridColumn != null) {
|
||||
gridColumn.setEditable(editable && !generated && !isRepresentsCollection());
|
||||
gridColumn.setEditable(editable && !generated
|
||||
&& !isRepresentsCollection()
|
||||
&& isEditingPermitted());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,12 @@
|
||||
|
||||
package com.haulmont.cuba.web.toolkit.ui;
|
||||
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.Security;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.security.entity.ConstraintOperationType;
|
||||
import com.haulmont.cuba.security.entity.EntityOp;
|
||||
import com.vaadin.data.Container;
|
||||
import com.vaadin.data.Validatable;
|
||||
import com.vaadin.data.Validator;
|
||||
@ -39,6 +45,10 @@ public class CubaGrid extends Grid implements Action.ShortcutNotifier {
|
||||
|
||||
protected Collection<Field<?>> editorFields = new ArrayList<>();
|
||||
|
||||
protected CollectionDatasource collectionDatasource;
|
||||
|
||||
protected Security security = AppBeans.get(Security.NAME);
|
||||
|
||||
public CubaGrid(CubaGridEditorFieldFactory editorFieldFactory) {
|
||||
this(null, null, editorFieldFactory);
|
||||
}
|
||||
@ -65,6 +75,14 @@ public class CubaGrid extends Grid implements Action.ShortcutNotifier {
|
||||
datasourceExtension.refreshCache();
|
||||
}
|
||||
|
||||
public CollectionDatasource getCollectionDatasource() {
|
||||
return collectionDatasource;
|
||||
}
|
||||
|
||||
public void setCollectionDatasource(CollectionDatasource collectionDatasource) {
|
||||
this.collectionDatasource = collectionDatasource;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doEditItem() {
|
||||
clearFields(editorFields);
|
||||
@ -85,6 +103,17 @@ public class CubaGrid extends Grid implements Action.ShortcutNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEditingPermitted(Object id) {
|
||||
if (collectionDatasource != null) {
|
||||
//noinspection unchecked
|
||||
Entity entity = collectionDatasource.getItem(id);
|
||||
return security.isEntityOpPermitted(collectionDatasource.getMetaClass(), EntityOp.UPDATE) &&
|
||||
(entity != null && security.isPermitted(entity, ConstraintOperationType.UPDATE));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void clearFields(Collection<Field<?>> fields) {
|
||||
for (Field<?> field : fields) {
|
||||
field.setParent(null);
|
||||
|
Loading…
Reference in New Issue
Block a user