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

[hp-application-automation-tools-plugin] Extract inline script block and event handlers in com/microfocus/application/automation/tools/run/UploadAppBuilder/config.jelly

XMLWordPrintable

      Problems

      == Inline Script Block
      Line: 69
      ----
      <script type="text/javascript">
              function useAuthentication(obj){
                  if(obj.checked){
                      document.getElementsByName("uploadApp.fsProxyUserName")[0].disabled=null;
                      document.getElementsByName("uploadApp.fsProxyPassword")[0].disabled=null;
                  }else{
                      document.getElementsByName("uploadApp.fsProxyUserName")[0].disabled="true";
                      document.getElementsByName("uploadApp.fsProxyPassword")[0].disabled="true";
                  }
              }
      
              function refreshWorkspaces(event,upload){
                    var saveWorkspace = event.target.previousElementSibling.value;
                    var mcUrl = document.getElementsByName("uploadApp.mcServerName")[0].value;
                    var authType = document.querySelector('input[name$="authModel"]:checked').value;
                    var mcUserName = document.getElementsByName("uploadApp.mcUserName")[0].value;
                    var mcPassword = document.getElementsByName("uploadApp.mcPassword")[0].value;
                    var mcTenantId = document.getElementsByName("uploadApp.mcTenantId")[0].value;
                    var mcExecToken = document.getElementsByName("uploadApp.mcExecToken")[0].value;
                    var useProxy = document.getElementsByName("proxySettings")[0].checked;
                    var proxyAddress = document.getElementsByName("uploadApp.fsProxyAddress")[0].value;
                    var useAuthentication = document.getElementsByName("uploadApp.fsUseAuthentication")[0].checked;
                    var proxyUserName = document.getElementsByName("uploadApp.fsProxyUserName")[0].value;
                    var proxyPassword = document.getElementsByName("uploadApp.fsProxyPassword")[0].value;
                    upload.getValidWorkspaces(mcUrl, authType, mcUserName, mcPassword, mcTenantId, mcExecToken, useProxy, proxyAddress, useAuthentication, proxyUserName, proxyPassword, function (r) {
                           const workspaces = r.responseJSON;
                           var str = renderWorkspaces(workspaces,saveWorkspace);
                           event.target.previousElementSibling.innerHTML= str;
                    });
              }
      
              var renderWorkspaces = function (workspaces, saveWorkspace){
                   let str = "";
                   workspaces.forEach((item) => {
                        if(saveWorkspace == ""){
                             if(item.name == "Shared assets"){
                                   str = str + "<option value=" + item.uuid.toString() + " selected=" + true + ">" + item.name + "</option>";
                             }else{
                                   str = str + "<option value=" + item.uuid.toString() + ">" + item.name + "</option>";
                             }
                        }else{
                             if(item.uuid == saveWorkspace){
                                   str = str + "<option value=" + item.uuid.toString() + " selected=" + true + ">" + item.name + "</option>";
                             }else{
                                   str = str + "<option value=" + item.uuid.toString() + ">" + item.name + "</option>";
                             }
                        }
                   });
                   return str;
              }
      
              window.addEventListener("load", (event) => {
                 var mcUrl = document.getElementsByName("uploadApp.mcServerName")[0].value;
                 var authType = document.querySelector('input[name$="authModel"]:checked').value;
                 var mcUserName = document.getElementsByName("uploadApp.mcUserName")[0].value;
                 var mcPassword = document.getElementsByName("uploadApp.mcPassword")[0].value;
                 var mcTenantId = document.getElementsByName("uploadApp.mcTenantId")[0].value;
                 var mcExecToken = document.getElementsByName("uploadApp.mcExecToken")[0].value;
                 var useProxy = document.getElementsByName("proxySettings")[0].checked;
                 var proxyAddress = document.getElementsByName("uploadApp.fsProxyAddress")[0].value;
                 var useAuthentication = document.getElementsByName("uploadApp.fsUseAuthentication")[0].checked;
                 var proxyUserName = document.getElementsByName("uploadApp.fsProxyUserName")[0].value;
                 var proxyPassword = document.getElementsByName("uploadApp.fsProxyPassword")[0].value;
                 upload.getValidWorkspaces(mcUrl, authType, mcUserName, mcPassword, mcTenantId, mcExecToken, useProxy, proxyAddress, useAuthentication, proxyUserName, proxyPassword, function (r){
                        const workspaces = r.responseJSON;
                        let items = document.getElementsByClassName("mcRefreshButton");
                        let len = items.length;
                        if(len > 0){
                             Array.prototype.forEach.call(items, function (element) {
                                    var saveWorkspace = element.previousElementSibling.value;
                                    var str = renderWorkspaces(workspaces,saveWorkspace);
                                    element.previousElementSibling.innerHTML= str;
                             });
                        }
                  });
             })
      
          </script>
      ----
      
      == Inline Event Handler
      Line: 185
      ----
      <f:checkbox title="Specify authentication" name="uploadApp.fsUseAuthentication" checked="${instance.uploadAppModel.useAuthentication}" onclick="useAuthentication(this)"/>
      ----
      
      == Inline Event Handler
      Line: 207
      ----
      <input class="mcRefreshButton" type="button" value="Refresh" onclick="refreshWorkspaces(event,upload)"/>
      ----
      

      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: