From 7df7ae4a85d2f6409aebdeee2bc1cd0719bd76fb Mon Sep 17 00:00:00 2001 From: Daniel Beck <1831569+daniel-beck@users.noreply.github.com> Date: Wed, 13 Dec 2023 21:00:43 +0100 Subject: [PATCH] [JENKINS-72443] Do not show copy option without visible items (#8763) Co-authored-by: Daniel Beck --- .../resources/hudson/model/View/newJob.jelly | 2 +- .../jenkins/model/NewJobCopyFromTest.java | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/src/test/java/jenkins/model/NewJobCopyFromTest.java diff --git a/core/src/main/resources/hudson/model/View/newJob.jelly b/core/src/main/resources/hudson/model/View/newJob.jelly index fa7f08da6055..f4f89e42af96 100644 --- a/core/src/main/resources/hudson/model/View/newJob.jelly +++ b/core/src/main/resources/hudson/model/View/newJob.jelly @@ -48,7 +48,7 @@ THE SOFTWARE.
- +

${%CopyOption.description}

diff --git a/test/src/test/java/jenkins/model/NewJobCopyFromTest.java b/test/src/test/java/jenkins/model/NewJobCopyFromTest.java new file mode 100644 index 000000000000..3a2150160a8b --- /dev/null +++ b/test/src/test/java/jenkins/model/NewJobCopyFromTest.java @@ -0,0 +1,32 @@ +package jenkins.model; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; + +import hudson.model.Item; +import java.io.IOException; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.hudson.test.MockAuthorizationStrategy; +import org.xml.sax.SAXException; + +public class NewJobCopyFromTest { + @Rule + public JenkinsRule j = new JenkinsRule(); + + @Test + public void checkLabel() throws IOException, SAXException { + try (JenkinsRule.WebClient wc = j.createWebClient()) { + // no items - validate assertion + assertThat(wc.goTo("newJob").getElementById("from"), is(nullValue())); + + // actual test + j.createFreeStyleProject(); + j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); + j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy().grant(Item.CREATE, Jenkins.READ).everywhere().toEveryone()); + assertThat(wc.goTo("newJob").getElementById("from"), is(nullValue())); + } + } +}