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

[JiraTestResultReporter] Extract inline script blocks and event handlers in org/jenkinsci/plugins/JiraTestResultReporter/JiraTestAction/badge.jelly

XMLWordPrintable

    • 245.v5a_2d45c771c9

      Problems

      == Inline Script Block
      Line: 3
      ----
      <script>
              /*
              Create a map of proxies, since this file will be included once for every test
              */
              if (typeof proxyMap === 'undefined') {
                  var proxyMap = [];
              }
              proxyMap["${it}"] = <st:bind value="${it}"/>;
          </script>
      ----
      
      == Inline Script Block
      Line: 34
      ----
      <script>
              function hideshow(which){
                  if (!document.getElementById)
                      return;
                  if (which.style.display=="block")
                      which.style.display="none";
                  else
                      which.style.display="block";
              }
      
      
              function doSubmit(issueLink, spinner, proxyString, errorsDiv) {
                  if(!issueLink.value)
                      return;
                  spinner.style.display="inline";
                  var proxy = proxyMap[proxyString];
                  proxy.setIssueKey(issueLink.value, function(t) {
                      if(t.responseText != "null") {
                          spinner.style.display="none"
                          applyErrorMessage(errorsDiv, t);
                      }
                      else {
                          location.reload();
                      }
                  });
              }
      
      
              function doClear(proxyString) {
                  var proxy = proxyMap[proxyString];
                  proxy.clearIssueKey(function(t) {
                      location.reload();
                  })
              }
      
              function createNewIssue(spinner, proxyString, errorsDiv) {
                  spinner.style.display="inline";
                  var proxy = proxyMap[proxyString];
                  var socketTimeout = setTimeout( function() {
                      spinner.style.display="none";
                      errorsDiv.innerHTML = "Error: Socket Timeout. The issue was probably created, but the server did not respond in a timely manner. Check JIRA to avoid creating duplicated issues.";
                      }, 30000);
                  proxy.createIssue( function(t) {
                      clearTimeout(socketTimeout);
                      if(t.responseText != "null") {
                          spinner.style.display="none";
                          applyErrorMessage(errorsDiv, t);
                      }
                      else {
                          location.reload();
                      }
                  });
              }
      
          </script>
      ----
      
      == Inline Event Handler
      Line: 15
      ----
      <l:icon class="icon-notepad icon-sm" onclick="hideshow(document.getElementById('jira-${it}'))" style="cursor:pointer"/>
      ----
      
      == Inline Event Handler
      Line: 18
      ----
      <a href="#jira" onClick="createNewIssue(document.getElementById('spinner-${it}'), '${it}', document.getElementById('jiraErrors-${it}'))">
      ----
      
      == Inline Event Handler
      Line: 20
      ----
      <img src="${resURL}/plugin/JiraTestResultReporter/submit.png" height="16" width="16" style="cursor:pointer"
                           onClick="doSubmit(document.getElementById('issueKeyInput-${it}'), document.getElementById('spinner-${it}'), '${it}', document.getElementById('jiraErrors-${it}'))" />
      ----
      
      == Inline Event Handler
      Line: 27
      ----
      <img src="${resURL}/plugin/JiraTestResultReporter/remove.png" onClick="doClear('${it}')"  height="16" width="16" style="cursor:pointer"/>
      ----
      

      Solutions

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

            yafenkin Yaroslav Afenkin
            basil Basil Crow
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: