Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-74602

[reqtify] Extract inline script blocks and event handler in io/jenkins/plugins/ReqtifyGenerateReport/config.jelly

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Minor Minor
    • reqtify-plugin

      Problems

      == Inline Script Block
      Line: 13
      ----
      <script>
                document.addEventListener("DOMContentLoaded", function() {
                var errorAlreadyChecked = false;
                var i = setInterval(function() {
                var reportsElement = document.getElementById("reports");
                if (reportsElement) {
                var isPending = reportsElement.classList.contains("select-ajax-pending");
                if (!isPending) {
                if (!errorAlreadyChecked) {
                clearInterval(i);
                showReqtifyError();
                errorAlreadyChecked = true;
                }
                }
                } else {
                console.error("Element with ID 'reports' not found.");
                }
                }, 1000);
                });
            </script>
      ----
      
      == Inline Script Block
      Line: 37
      ----
      <script>
                document.addEventListener("DOMContentLoaded", function() {
                var errorAlreadyChecked = false;
                var i = setInterval(function() {
                var templatesElement = document.getElementById("templates");
                if (templatesElement) {
                var isPending = templatesElement.classList.contains("select-ajax-pending");
                if (!isPending) {
                if (!errorAlreadyChecked) {
                clearInterval(i);
                showReqtifyError();
                errorAlreadyChecked = true;
                }
                }
                } else {
                console.error("Element with ID 'templates' not found.");
                }
                }, 1000);
                });
            </script>
      ----
      
      == Inline Script Block
      Line: 61
      ----
      <script>
                  document.addEventListener("DOMContentLoaded", function() {
                  var errorAlreadyChecked = false;
                  var i = setInterval(function() {
                  var filtersElement = document.getElementById("filters");
                  if (filtersElement) {
                  var isPending = filtersElement.classList.contains("select-ajax-pending");
                  if (!isPending) {
                  if (!errorAlreadyChecked) {
                  clearInterval(i);
                  showReqtifyError();
                  errorAlreadyChecked = true;
                  }
                  }
                  } else {
                  console.error("Element with ID 'filters' not found.");
                  }
                  }, 1000);
                  });
              </script>
      ----
      
      == Inline Script Block
      Line: 87
      ----
      <script>
               var url = window.location.pathname;
               var currentJob = url.match(new RegExp("job/(.*?)/"))[1];
               function getReportParameterValues() {
                  var e = document.getElementById("reports");
                  var functionName = e.options[e.selectedIndex].value;
                  backend.renderReportParamUI(functionName,currentJob, function(response){
                        if (response.status === 200) {
                        // Remove existing report parameters
                        document.querySelectorAll(".report-param").forEach(el => el.remove());
      
                        // Access the responseJSON
                        var htmlList = response.responseJSON;
      
                        // Ensure htmlList is an array
                        if (Array.isArray(htmlList)) {
                        htmlList.forEach((html) => {
                        var tr = document.getElementById("reports").parentElement.parentElement;
                        tr.insertAdjacentHTML('afterend', html);
                        });
                        } else {
                        console.error("Expected an array in responseJSON but got:", htmlList);
                        }
                        } else {
                        console.error("Error in response:", response.statusText);
                        }
                      showReqtifyError();
                  });
                }
              
                setTimeout(function() { 
                      backend.getSavedReport(currentJob, function(reportName){
                      if(reportName.responseJSON !== "") {
                          backend.renderReportParamUI(reportName.responseJSON,currentJob, function(response){
                                if (response.status === 200) {
                                // Remove existing report parameters
                                document.querySelectorAll(".report-param").forEach(el => el.remove());
      
                                // Access the responseJSON
                                var htmlList = response.responseJSON;
      
                                // Ensure htmlList is an array
                                if (Array.isArray(htmlList)) {
                                htmlList.forEach((html) => {
                                var tr = document.getElementById("reports").parentElement.parentElement;
                                tr.insertAdjacentHTML('afterend', html);
                                });
                                } else {
                                console.error("Expected an array in responseJSON but got:", htmlList);
                                }
                                } else {
                                console.error("Error in response:", response.statusText);
                                }
                              showReqtifyError();
                          });
                      }
                });     
              }, 1000);
                
                function showReqtifyError() {
                  backend.getReqtifyError(function(reqtifyError){
                      if(reqtifyError === undefined || reqtifyError === null) {
                          document.getElementById('reqtifyErrorDiv').style.display = 'none';   
                      } else {
                          document.getElementById('reqtifyErrorDiv').style.display = 'block';
                          document.getElementById('reqtifyErrorSpan').innerHTML = reqtifyError.responseJSON;   
                      }            
                  });        
                }                
        </script>
      ----
      
      == Inline Event Handler
      Line: 12
      ----
      <f:select id="reports" onclick="getReportParameterValues()" />
      ----
      

      Solutions

      https://www.jenkins.io/doc/developer/security/csp/#inline-javascript-blocks
      https://www.jenkins.io/doc/developer/security/csp/#inline-event-handlers

            Unassigned Unassigned
            basil Basil Crow
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: