use of com.haulmont.cuba.core.sys.persistence.CubaEntityFetchGroup in project cuba by cuba-platform.
the class AttributeSecuritySupport method applySecurityToFetchGroup.
protected void applySecurityToFetchGroup(Entity entity) {
if (entity == null) {
return;
}
MetaClass metaClass = metadata.getClassNN(entity.getClass());
FetchGroupTracker fetchGroupTracker = (FetchGroupTracker) entity;
FetchGroup fetchGroup = fetchGroupTracker._persistence_getFetchGroup();
SecurityState securityState = getSecurityState(entity);
if (fetchGroup != null) {
List<String> attributesToRemove = new ArrayList<>();
for (String attrName : fetchGroup.getAttributeNames()) {
String[] parts = attrName.split("\\.");
if (parts.length > 0 && BaseEntityInternalAccess.isHiddenOrReadOnly(securityState, parts[0])) {
attributesToRemove.add(attrName);
} else {
MetaClass currentMetaClass = metaClass;
for (String part : parts) {
if (!security.isEntityAttrUpdatePermitted(currentMetaClass, part)) {
attributesToRemove.add(attrName);
break;
}
MetaProperty metaProperty = currentMetaClass.getPropertyNN(part);
if (metaProperty.getRange().isClass()) {
currentMetaClass = metaProperty.getRange().asClass();
}
}
}
}
if (!attributesToRemove.isEmpty()) {
List<String> attributeNames = new ArrayList<>(fetchGroup.getAttributeNames());
attributeNames.removeAll(attributesToRemove);
fetchGroupTracker._persistence_setFetchGroup(new CubaEntityFetchGroup(attributeNames));
}
} else {
List<String> attributeNames = new ArrayList<>();
for (MetaProperty metaProperty : metaClass.getProperties()) {
String propertyName = metaProperty.getName();
if (metadataTools.isSystem(metaProperty)) {
attributeNames.add(propertyName);
}
if (security.isEntityAttrUpdatePermitted(metaClass, propertyName) && !BaseEntityInternalAccess.isHiddenOrReadOnly(securityState, propertyName)) {
attributeNames.add(metaProperty.getName());
}
}
fetchGroupTracker._persistence_setFetchGroup(new CubaEntityFetchGroup(attributeNames));
}
}
Aggregations