From 279f6f8b2c30a0b3723cc387337408a901da10ce Mon Sep 17 00:00:00 2001 From: Yaroslav Afenkin <91559310+yaroslavafenkin@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:42:37 +0200 Subject: [PATCH 1/3] [JENKINS-74027] Extract inline JavaScript from `CascadeChoiceParameter/index.jelly` --- .../cascade-choice-parameter.js | 20 ++++++++++++ .../CascadeChoiceParameter/index.jelly | 31 +++++++------------ 2 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 src/main/resources/org/biouno/unochoice/CascadeChoiceParameter/cascade-choice-parameter.js diff --git a/src/main/resources/org/biouno/unochoice/CascadeChoiceParameter/cascade-choice-parameter.js b/src/main/resources/org/biouno/unochoice/CascadeChoiceParameter/cascade-choice-parameter.js new file mode 100644 index 00000000..e4e5ccb3 --- /dev/null +++ b/src/main/resources/org/biouno/unochoice/CascadeChoiceParameter/cascade-choice-parameter.js @@ -0,0 +1,20 @@ +if (window.makeStaplerProxy) { + window.__old__makeStaplerProxy = window.makeStaplerProxy; + window.makeStaplerProxy = UnoChoice.makeStaplerProxy2; +} + +window.addEventListener("DOMContentLoaded", () => { + document.querySelectorAll(".cascade-choice-parameter-data-holder").forEach((dataHolder) => { + const { name, paramName, randomName, proxyName } = dataHolder.dataset; + const referencedParameters = dataHolder.dataset.referencedParameters.split(",").map((val) => val.trim()); + const filterable = dataHolder.dataset.filterable === "true"; + const filterLength = parseInt(dataHolder.dataset.filterLength); + + UnoChoice.renderCascadeChoiceParameter(`#${paramName}`, filterable, name, randomName, filterLength, paramName, referencedParameters, window[proxyName]); + }); + + if (window.makeStaplerProxy && window.__old__makeStaplerProxy) { + window.makeStaplerProxy = window.__old__makeStaplerProxy; + delete window["__old__makeStaplerProxy"]; + } +}); diff --git a/src/main/resources/org/biouno/unochoice/CascadeChoiceParameter/index.jelly b/src/main/resources/org/biouno/unochoice/CascadeChoiceParameter/index.jelly index 280a5184..358e9fc4 100644 --- a/src/main/resources/org/biouno/unochoice/CascadeChoiceParameter/index.jelly +++ b/src/main/resources/org/biouno/unochoice/CascadeChoiceParameter/index.jelly @@ -2,24 +2,15 @@ ${it.parameters.clear()} - - + + + + From 0aa7de7e0f88dbac4906f979ea7d20ebea0a5a67 Mon Sep 17 00:00:00 2001 From: Yaroslav Afenkin <91559310+yaroslavafenkin@users.noreply.github.com> Date: Thu, 7 Nov 2024 18:30:39 +0200 Subject: [PATCH 2/3] [JENKINS-74026] Extract inline JavaScript from `DynamicReferenceParameter/index.jelly` --- .../dynamic-reference-parameter.js | 28 ++++++++++++++ .../DynamicReferenceParameter/index.jelly | 37 ++++--------------- 2 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 src/main/resources/org/biouno/unochoice/DynamicReferenceParameter/dynamic-reference-parameter.js diff --git a/src/main/resources/org/biouno/unochoice/DynamicReferenceParameter/dynamic-reference-parameter.js b/src/main/resources/org/biouno/unochoice/DynamicReferenceParameter/dynamic-reference-parameter.js new file mode 100644 index 00000000..c5fc20ef --- /dev/null +++ b/src/main/resources/org/biouno/unochoice/DynamicReferenceParameter/dynamic-reference-parameter.js @@ -0,0 +1,28 @@ +if (window.makeStaplerProxy) { + window.__old__makeStaplerProxy = window.makeStaplerProxy; + window.makeStaplerProxy = UnoChoice.makeStaplerProxy2; +} + +window.addEventListener("DOMContentLoaded", () => { + document.querySelectorAll(".dynamic-reference-parameter-data-holder").forEach((dataHolder) => { + const { name, paramName, proxyName } = dataHolder.dataset; + const referencedParameters = dataHolder.dataset.referencedParameters.split(",").map((val) => val.trim()); + + UnoChoice.renderDynamicRenderParameter(`#${paramName}`, name, paramName, referencedParameters, window[proxyName]); + + // update spinner id + var rootElmt = document.querySelector(`#${paramName}`); + if (rootElmt) { + var divElmt = rootElmt.querySelector("div"); + if (divElmt) { + var spinnerId = divElmt.id.split("_").pop(); + document.querySelector(`#${paramName}-spinner`).setAttribute("id", spinnerId + "-spinner"); + } + } + }); + + if (window.makeStaplerProxy && window.__old__makeStaplerProxy) { + window.makeStaplerProxy = window.__old__makeStaplerProxy; + delete window["__old__makeStaplerProxy"]; + } +}); diff --git a/src/main/resources/org/biouno/unochoice/DynamicReferenceParameter/index.jelly b/src/main/resources/org/biouno/unochoice/DynamicReferenceParameter/index.jelly index b363f24d..7f35264a 100644 --- a/src/main/resources/org/biouno/unochoice/DynamicReferenceParameter/index.jelly +++ b/src/main/resources/org/biouno/unochoice/DynamicReferenceParameter/index.jelly @@ -55,33 +55,12 @@ - - + + + + From 8a373dcb1294a2548ffd2be62ef24a4dc9b71bc1 Mon Sep 17 00:00:00 2001 From: Yaroslav Afenkin <91559310+yaroslavafenkin@users.noreply.github.com> Date: Thu, 7 Nov 2024 19:42:13 +0200 Subject: [PATCH 3/3] Make test pass --- .../jenkins_cert_2008/TestGroovyScriptXssVulnerabilities.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/biouno/unochoice/jenkins_cert_2008/TestGroovyScriptXssVulnerabilities.java b/src/test/java/org/biouno/unochoice/jenkins_cert_2008/TestGroovyScriptXssVulnerabilities.java index 15cd8cde..ebaa6e4a 100644 --- a/src/test/java/org/biouno/unochoice/jenkins_cert_2008/TestGroovyScriptXssVulnerabilities.java +++ b/src/test/java/org/biouno/unochoice/jenkins_cert_2008/TestGroovyScriptXssVulnerabilities.java @@ -149,7 +149,7 @@ public void testReferenceParameterXss() throws IOException, SAXException { "random-name", script, DynamicReferenceParameter.ELEMENT_TYPE_FORMATTED_HTML, - null, + "", false); project.addProperty(new ParametersDefinitionProperty(parameter)); project.save();