Skip to content

Commit

Permalink
Add checkbox to c:select to include user credentials
Browse files Browse the repository at this point in the history
This allows the user to opt in to providing their own user credentials
(when they have the appropriate permissions) and adds a caution message
for users to take care with user credentials based on where you're
providing those credentials.

Signed-off-by: Matt Sicker <boards@gmail.com>
  • Loading branch information
jvz committed Jul 10, 2019
1 parent fca06b8 commit 8318894
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public StandardListBoxModel doFillDefaultValueItems(@AncestorInPath Item context
public StandardListBoxModel doFillValueItems(@AncestorInPath Item context,
@QueryParameter(required = true) String credentialType,
@QueryParameter String value,
@QueryParameter boolean required) {
@QueryParameter boolean required,
@QueryParameter boolean includeUser) {
// TODO switch to Jenkins.getInstance() once 2.0+ is the baseline
Jenkins jenkins = Jenkins.getActiveInstance();
final ACL acl = context == null ? jenkins.getACL() : context.getACL();
Expand All @@ -194,7 +195,7 @@ public StandardListBoxModel doFillValueItems(@AncestorInPath Item context,
if (!required) {
result.includeEmptyValue();
}
if (!isSystem && acl.hasPermission(CredentialsProvider.USE_OWN)) {
if (!isSystem && acl.hasPermission(CredentialsProvider.USE_OWN) && includeUser) {
result.includeAs(authentication, context, typeClass, domainRequirements);
}
if (acl.hasPermission(CredentialsProvider.USE_ITEM) || isSystem || itemAuthentication
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/lib/credentials/select.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@
</j:if>
<div field-disabled="${paramValue?'true':null}"
class="credentials-select-content-select ${paramValue?'credentials-select-content-inactive':'credentials-select-content-active'}">
<!-- TODO: help links -->
<!-- TODO: update the build-with-parameters.png screenshot in documentation -->
<div class="include-user-credentials">
<div class="warning user-credentials-caution" style="display:none">
${%userCredentialsCaution}
</div>
<label field-disabled="true">
<input type="checkbox" name="includeUser"/>
${%includeUserCredentials}
</label>
</div>
<f:select clazz="${attrs.clazz} credentials-select" field="${attrs.field}"
default="${paramDefault?'':attrs.default}" value="${paramValue?(paramDefault?'':attrs.default):value}"
checkMethod="${attrs.checkMethod}"/>
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/lib/credentials/select.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@
invalidExpression=A valid parameter expression consists of the parameter name enclosed \
within <code>$'{'</code> and <code>'}'</code>
fixedSelection=Specific credentials
paramExpression=Parameter expression
paramExpression=Parameter expression
includeUserCredentials=List user credentials
userCredentialsCaution=Only provide user credentials to trusted builds
12 changes: 12 additions & 0 deletions src/main/resources/lib/credentials/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@ Behaviour.specify("INPUT.credentials-select", 'credentials-select', -100, functi
}).bind($(x));
x.onchange();
});
Behaviour.specify("DIV.include-user-credentials", 'include-user-credentials', 0, function (e) {
var includeUserCheckbox = e.querySelector("input[name='includeUser']");
var caution = e.querySelector("div.user-credentials-caution");
includeUserCheckbox.addEventListener('click', function (evt) {
if (this.checked) {
caution.setAttribute('style', 'display:block');
} else {
caution.setAttribute('style', 'display:none');
}
layoutUpdateCallback.call();
});
})
window.setTimeout(function() {
// HACK: can be removed once base version of Jenkins has fix of https://issues.jenkins-ci.org/browse/JENKINS-26578
// need to apply the new behaviours to existing objects
Expand Down

0 comments on commit 8318894

Please sign in to comment.