mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 20:28:00 +08:00
PL-9570 Enable usage of session parameters in query filter
This commit is contained in:
parent
ce9017a63c
commit
c14e8b93db
@ -211,4 +211,11 @@ public interface GlobalConfig extends Config {
|
||||
@DefaultBoolean(false)
|
||||
boolean getUserSessionLogEnabled();
|
||||
void setUserSessionLogEnabled(boolean enabled);
|
||||
|
||||
/**
|
||||
* @return whether the new (since 6.7) behavior regarding session parameters in query filter is enabled
|
||||
*/
|
||||
@Property("cuba.enableSessionParamsInQueryFilter")
|
||||
@DefaultBoolean(true)
|
||||
boolean getEnableSessionParamsInQueryFilter();
|
||||
}
|
@ -16,9 +16,7 @@
|
||||
*/
|
||||
package com.haulmont.cuba.core.global.filter;
|
||||
|
||||
import com.haulmont.cuba.core.global.QueryTransformer;
|
||||
import com.haulmont.cuba.core.global.QueryTransformerFactory;
|
||||
import com.haulmont.cuba.core.global.TemplateHelper;
|
||||
import com.haulmont.cuba.core.global.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.text.StrBuilder;
|
||||
import org.dom4j.Element;
|
||||
@ -27,6 +25,9 @@ import java.util.*;
|
||||
|
||||
public class QueryFilter extends FilterParser {
|
||||
|
||||
protected boolean enableSessionParams = AppBeans.get(Configuration.class)
|
||||
.getConfig(GlobalConfig.class).getEnableSessionParamsInQueryFilter();
|
||||
|
||||
public QueryFilter(Condition condition) {
|
||||
super(condition);
|
||||
}
|
||||
@ -101,18 +102,22 @@ public class QueryFilter extends FilterParser {
|
||||
|
||||
if (declaredParams.isEmpty())
|
||||
return true;
|
||||
|
||||
// Return true only if declared params have values and there is at least one non-session parameter among them.
|
||||
// This is necessary to exclude generic filter conditions that contain only session parameters. Otherwise
|
||||
// there is no way to handle exclusion. Unfortunately this imposes the restriction on custom filters design:
|
||||
// condition with session-only parameters must be avoided, they must be coded as part of main query body or as
|
||||
// part of another condition.
|
||||
boolean found = false;
|
||||
for (ParameterInfo paramInfo : declaredParams) {
|
||||
if (params.contains(paramInfo.getName())) {
|
||||
found = found || !paramInfo.getType().equals(ParameterInfo.Type.SESSION);
|
||||
if (enableSessionParams) {
|
||||
return declaredParams.stream()
|
||||
.allMatch(paramInfo -> params.contains(paramInfo.getName()));
|
||||
} else {
|
||||
// Return true only if declared params have values and there is at least one non-session parameter among them.
|
||||
// This is necessary to exclude generic filter conditions that contain only session parameters. Otherwise
|
||||
// there is no way to handle exclusion. Unfortunately this imposes the restriction on custom filters design:
|
||||
// condition with session-only parameters must be avoided, they must be coded as part of main query body or as
|
||||
// part of another condition.
|
||||
boolean found = false;
|
||||
for (ParameterInfo paramInfo : declaredParams) {
|
||||
if (params.contains(paramInfo.getName())) {
|
||||
found = found || !paramInfo.getType().equals(ParameterInfo.Type.SESSION);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user