提交 a00166bf 编写于 作者: A A. Jard 提交者: Oleg Nenashev

[JENKINS-60579] - Allow the usage of DescriptorVisibilityFilter to filter View...

[JENKINS-60579] - Allow the usage of DescriptorVisibilityFilter to filter View properties on UI. (#4404)

* [JENKINS-60579] Functionnal test on View that shows the issue for invisible properties.

* [JENKINS-60579] Apply the visibility filter on View for configuration.

* [JENKINS-60579] Better configuration for testing on invisible property on view.

* [JENKINS-60579] Move tests on ViewPropertyTest.

* [JENKINS-60579]adding the since on getVisiblePropertyDescriptors.
上级 867bc2cb
......@@ -322,8 +322,9 @@ public abstract class View extends AbstractModelObject implements AccessControll
}
/**
* Returns all the {@link LabelAtomPropertyDescriptor}s that can be potentially configured
* on this label.
* Returns all the {@link ViewPropertyDescriptor}s that can be potentially configured
* on this view. Returns both {@link ViewPropertyDescriptor}s visible and invisible for user, see
* {@link View#getVisiblePropertyDescriptors} to filter invisible one.
*/
public List<ViewPropertyDescriptor> getApplicablePropertyDescriptors() {
List<ViewPropertyDescriptor> r = new ArrayList<>();
......@@ -334,6 +335,15 @@ public abstract class View extends AbstractModelObject implements AccessControll
return r;
}
/**
* @return all the {@link ViewPropertyDescriptor}s that can be potentially configured on this View and are visible
* for the user. Use {@link DescriptorVisibilityFilter} to make a View property invisible for users.
* @since 2.214
*/
public List<ViewPropertyDescriptor> getVisiblePropertyDescriptors() {
return DescriptorVisibilityFilter.apply(this, getApplicablePropertyDescriptors());
}
public void save() throws IOException {
// persistence is a part of the owner
// due to initialization timing issue, it can be null when this method is called
......
......@@ -52,7 +52,7 @@ THE SOFTWARE.
<st:include page="configure-entries.jelly" optional="true" />
<!-- view property configurations -->
<f:descriptorList descriptors="${it.getApplicablePropertyDescriptors()}" instances="${it.properties}" />
<f:descriptorList descriptors="${it.getVisiblePropertyDescriptors()}" instances="${it.properties}" />
<f:bottomButtonBar>
<f:submit value="${%OK}" />
......
......@@ -26,13 +26,23 @@ package hudson.model;
import java.util.Arrays;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import jenkins.model.DirectlyModifiableTopLevelItemGroup;
import static org.junit.Assert.*;
import org.awaitility.Awaitility;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockFolder;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.StaplerRequest;
import net.sf.json.JSONObject;
public class ViewDescriptorTest {
......@@ -75,4 +85,96 @@ public class ViewDescriptorTest {
assertEquals(new TreeSet<>(Arrays.asList(values)), new TreeSet<>(c.getValues()));
}
@Test
@Issue("JENKINS-60579")
public void invisiblePropertiesOnViewShoudBePersisted() throws Exception {
//GIVEN a listView that have an invisible property
ListView myListView = new ListView("Rock");
myListView.setRecurse(true);
myListView.setIncludeRegex(".*");
CustomInvisibleProperty invisibleProperty = new CustomInvisibleProperty();
invisibleProperty.setSomeProperty("You cannot see me.");
invisibleProperty.setView(myListView);
myListView.getProperties().add(invisibleProperty);
r.jenkins.addView(myListView);
assertEquals(r.jenkins.getView("Rock").getProperties().get(CustomInvisibleProperty.class).getSomeProperty(),
"You cannot see me.");
//WHEN the users goes with "Edit View" on the configure page
JenkinsRule.WebClient webClient = r.createWebClient();
HtmlPage editViewPage = webClient.getPage(myListView, "configure");
//THEN the invisible property is not displayed on page
assertFalse("CustomInvisibleProperty should not be displayed on the View edition page UI.",
editViewPage.asText().contains("CustomInvisibleProperty"));
HtmlForm editViewForm = editViewPage.getFormByName("viewConfig");
editViewForm.getTextAreaByName("description").type("This list view is awesome !");
r.submit(editViewForm);
//Check that the description is updated on view
Awaitility.waitAtMost(3, TimeUnit.SECONDS).until(() -> webClient.getPage(myListView)
.asText()
.contains("This list view is awesome !"));
//AND THEN after View save, the invisible property is still persisted with the View.
assertNotNull("The CustomInvisibleProperty should be persisted on the View.",
r.jenkins.getView("Rock").getProperties().get(CustomInvisibleProperty.class));
assertEquals(r.jenkins.getView("Rock").getProperties().get(CustomInvisibleProperty.class).getSomeProperty(),
"You cannot see me.");
}
private static class CustomInvisibleProperty extends ViewProperty {
private String someProperty;
public void setSomeProperty(String someProperty) {
this.someProperty = someProperty;
}
public String getSomeProperty() {
return this.someProperty;
}
public CustomInvisibleProperty() {
this.someProperty = "undefined";
}
@Override
public ViewProperty reconfigure(StaplerRequest req, JSONObject form) {
return this;
}
@TestExtension
public static final class CustomInvisibleDescriptorImpl extends ViewPropertyDescriptor {
@Override
public String getId() {
return "CustomInvisibleDescriptorImpl";
}
@Override
public boolean isEnabledFor(View view) {
return true;
}
}
@TestExtension
public static final class CustomInvisibleDescriptorVisibilityFilterImpl extends DescriptorVisibilityFilter {
@Override
public boolean filter(Object context, Descriptor descriptor) {
return false;
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册