Skip to content

The Unified and Autonomous Development Platform

Fix field/param visibility issue

robin shen65078bcd51b2
diff --git a/core/src/main/java/io/onedev/server/util/inputspec/choiceinput/choiceprovider/ScriptingChoices.java b/core/src/main/java/io/onedev/server/util/inputspec/choiceinput/choiceprovider/ScriptingChoices.java
index d3cd786b74..256056abcc 100644
--- a/core/src/main/java/io/onedev/server/util/inputspec/choiceinput/choiceprovider/ScriptingChoices.java
+++ b/core/src/main/java/io/onedev/server/util/inputspec/choiceinput/choiceprovider/ScriptingChoices.java
@@ -1,12 +1,14 @@
package io.onedev.server.util.inputspec.choiceinput.choiceprovider;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.hibernate.validator.constraints.NotEmpty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import io.onedev.server.OneException;
import io.onedev.server.util.GroovyUtils;
import io.onedev.server.web.editable.annotation.Editable;
import io.onedev.server.web.editable.annotation.OmitName;
@@ -42,7 +44,17 @@ public class ScriptingChoices extends ChoiceProvider {
Map<String, Object> variables = new HashMap<>();
variables.put("allPossible", allPossible);
try {
- return (Map<String, String>) GroovyUtils.evalScript(getScript(), variables);
+ Object result = GroovyUtils.evalScript(getScript(), variables);
+ if (result instanceof Map) {
+ return (Map<String, String>) result;
+ } else if (result instanceof List) {
+ Map<String, String> choices = new HashMap<>();
+ for (String item: (List<String>)result)
+ choices.put(item, null);
+ return choices;
+ } else {
+ throw new OneException("Script should return either a Map or a List");
+ }
} catch (RuntimeException e) {
if (allPossible) {
logger.error("Error getting all possible choices", e);
diff --git a/core/src/main/java/io/onedev/server/web/component/issue/operation/IssueOperationsPanel.java b/core/src/main/java/io/onedev/server/web/component/issue/operation/IssueOperationsPanel.java
index 2f50fcb8f9..fa576d8e06 100644
--- a/core/src/main/java/io/onedev/server/web/component/issue/operation/IssueOperationsPanel.java
+++ b/core/src/main/java/io/onedev/server/web/component/issue/operation/IssueOperationsPanel.java
@@ -184,16 +184,18 @@ public abstract class IssueOperationsPanel extends Panel {
if (getIssue().getMilestone() != null)
criterias.add(IssueQuery.quote(IssueConstants.FIELD_MILESTONE) + " is " + IssueQuery.quote(getIssue().getMilestoneName()));
for (Map.Entry<String, Input> entry: getIssue().getFieldInputs().entrySet()) {
- List<String> strings = entry.getValue().getValues();
- if (strings.isEmpty()) {
- criterias.add(IssueQuery.quote(entry.getKey()) + " is empty");
- } else {
- InputSpec field = issueSetting.getFieldSpec(entry.getKey());
- if (field instanceof ChoiceInput && ((ChoiceInput)field).isAllowMultiple()) {
- for (String string: strings)
- criterias.add(IssueQuery.quote(entry.getKey()) + " contains " + IssueQuery.quote(string));
- } else if (!(field instanceof DateInput)) {
- criterias.add(IssueQuery.quote(entry.getKey()) + " is " + IssueQuery.quote(strings.iterator().next()));
+ if (getIssue().isFieldVisible(entry.getKey())) {
+ List<String> strings = entry.getValue().getValues();
+ if (strings.isEmpty()) {
+ criterias.add(IssueQuery.quote(entry.getKey()) + " is empty");
+ } else {
+ InputSpec field = issueSetting.getFieldSpec(entry.getKey());
+ if (field instanceof ChoiceInput && ((ChoiceInput)field).isAllowMultiple()) {
+ for (String string: strings)
+ criterias.add(IssueQuery.quote(entry.getKey()) + " contains " + IssueQuery.quote(string));
+ } else if (!(field instanceof DateInput)) {
+ criterias.add(IssueQuery.quote(entry.getKey()) + " is " + IssueQuery.quote(strings.iterator().next()));
+ }
}
}
}
diff --git a/core/src/main/java/io/onedev/server/web/editable/PropertyDescriptor.java b/core/src/main/java/io/onedev/server/web/editable/PropertyDescriptor.java
index bd527cadce..e858cbabee 100644
--- a/core/src/main/java/io/onedev/server/web/editable/PropertyDescriptor.java
+++ b/core/src/main/java/io/onedev/server/web/editable/PropertyDescriptor.java
@@ -35,7 +35,7 @@ public class PropertyDescriptor implements Serializable {
private boolean propertyExcluded;
- private final Set<String> dependencyPropertyNames = new HashSet<>();
+ private Set<String> dependencyPropertyNames = new HashSet<>();
private transient Method propertyGetter;
@@ -133,8 +133,15 @@ public class PropertyDescriptor implements Serializable {
if (!checkedPropertyNames.add(getPropertyName()))
return false;
+ Set<String> prevDependencyPropertyNames = new HashSet<>(getDependencyPropertyNames());
OneContext.push(oneContext);
try {
+ /*
+ * Sometimes, the dependency may include properties introduced while evaluating available choices
+ * of a choice input. We clear it temporarily here in order to make visibility of the property
+ * consistent of BeanViewer, Issue.isFieldVisible, or Build.isParamVisible
+ */
+ getDependencyPropertyNames().clear();
ShowCondition showCondition = getPropertyGetter().getAnnotation(ShowCondition.class);
if (showCondition != null && !(boolean)ReflectionUtils.invokeStaticMethod(getBeanClass(), showCondition.value()))
return false;
@@ -145,6 +152,7 @@ public class PropertyDescriptor implements Serializable {
}
return true;
} finally {
+ getDependencyPropertyNames().addAll(prevDependencyPropertyNames);
OneContext.pop();
}
}
@@ -153,6 +161,10 @@ public class PropertyDescriptor implements Serializable {
return dependencyPropertyNames;
}
+ public void setDependencyPropertyNames(Set<String> dependencyPropertyNames) {
+ this.dependencyPropertyNames = dependencyPropertyNames;
+ }
+
public String getDisplayName() {
return EditableUtils.getDisplayName(getPropertyGetter());
}