-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSP compatibility improvements (#533)
- Loading branch information
Showing
14 changed files
with
109 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/resources/com/cloudbees/plugins/credentials/common/formBehaviour.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Behaviour.specify(".required-for-submit", 'required-for-submit', -99, function(requiredField) { | ||
const saveButton = requiredField.closest("form").querySelector('[name="Submit"]'); | ||
function updateSave() { | ||
const state = requiredField.value.length === 0; | ||
saveButton.disabled = state; | ||
} | ||
requiredField.addEventListener('input', updateSave); | ||
updateSave(saveButton); | ||
}); | ||
|
||
Behaviour.specify(".autofocus", "autofocus", 0, function(el) { | ||
el.focus(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...lugins/credentials/impl/CertificateCredentialsImpl/UploadedKeyStoreSource/configUpload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// multiple objects named "password" in the form => | ||
// extend findNearBy to allow selecting by id | ||
if (!findNearBy.patched) { | ||
var oldNearBy = findNearBy; | ||
findNearBy = function(el, name) { | ||
return name.charAt(0) == '#' ? document.querySelector(name.split('/')[0]) : oldNearBy(el, name); | ||
} | ||
findNearBy.patched = true; | ||
} | ||
|
||
Behaviour.specify(".certificate-file-upload", 'certificate-file-upload', -99, function(uploadedCertFileInput) { | ||
// Adding a onChange method on the file input to retrieve the value of the file content in a variable | ||
var fileId = uploadedCertFileInput.id; | ||
var _onchange = uploadedCertFileInput.onchange; | ||
if (typeof _onchange === "function") { | ||
uploadedCertFileInput.onchange = function() { fileOnChange(this); _onchange.call(this); } | ||
} else { | ||
uploadedCertFileInput.onchange = fileOnChange.bind(uploadedCertFileInput); | ||
} | ||
const base64field = uploadedCertFileInput.closest('.radioBlock-container').querySelector('[name="certificateBase64"]'); | ||
function fileOnChange() { | ||
// only trigger validation if the PKCS12 upload is selected | ||
if (uploadedCertFileInput.closest(".form-container").className.indexOf("-hidden") != -1) { | ||
return | ||
} | ||
try { // inspired by https://stackoverflow.com/a/754398 | ||
var uploadedCertFileInputFile = uploadedCertFileInput.files[0]; | ||
var reader = new FileReader(); | ||
reader.onload = function (evt) { | ||
base64field.value = btoa(evt.target.result); | ||
var uploadedKeystore = document.getElementById(fileId + "-textbox"); | ||
uploadedKeystore.onchange(uploadedKeystore); | ||
} | ||
reader.onerror = function (evt) { | ||
if (window.console !== null) { | ||
console.warn("Error during loading uploadedCertFile content", evt); | ||
} | ||
uploadedCertFile[fileId] = ''; | ||
} | ||
|
||
reader.readAsBinaryString(uploadedCertFileInputFile); | ||
} | ||
catch(e){ | ||
if (window.console !== null) { | ||
console.warn("Unable to retrieve uploadedCertFile content"); | ||
} | ||
} | ||
} | ||
|
||
// workaround for JENKINS-65616 | ||
// tweaks `checkDependsOn` to reference password by id instead of RelativePath | ||
var r = window.document.getElementById(fileId + "-textbox"); | ||
var p = findNextFormItem(r, 'password'); | ||
if (p) { | ||
const dependsOn = r.getAttribute('checkDependsOn'); | ||
if (!dependsOn.includes(p.id)) { | ||
r.setAttribute('checkDependsOn', dependsOn + ' #' + p.id + "/password"); | ||
} | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.