Skip to content

Commit

Permalink
Merge branch 'global-credentialsId-JENKINS-38048' of https://github.c…
Browse files Browse the repository at this point in the history
…om/jglick/git-plugin into master-PR433-PR437-single-revision-and-global-config-credentials-dropdown
  • Loading branch information
MarkEWaite committed Oct 22, 2016
2 parents 20ff10b + b52b095 commit 086896a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/main/java/hudson/plugins/git/UserRemoteConfig.java
Expand Up @@ -5,9 +5,7 @@
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Util;
import hudson.model.AbstractDescribableImpl;
Expand Down Expand Up @@ -87,7 +85,8 @@ public static class DescriptorImpl extends Descriptor<UserRemoteConfig> {
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item project,
@QueryParameter String url,
@QueryParameter String credentialsId) {
if (project == null || !project.hasPermission(Item.EXTENDED_READ)) {
if (project == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
project != null && !project.hasPermission(Item.EXTENDED_READ)) {
return new StandardListBoxModel().includeCurrentValue(credentialsId);
}
return new StandardListBoxModel()
Expand All @@ -106,7 +105,8 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item project,
public FormValidation doCheckCredentialsId(@AncestorInPath Item project,
@QueryParameter String url,
@QueryParameter String value) {
if (project == null || !project.hasPermission(Item.EXTENDED_READ)) {
if (project == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
project != null && !project.hasPermission(Item.EXTENDED_READ)) {
return FormValidation.ok();
}

Expand Down Expand Up @@ -151,7 +151,8 @@ public FormValidation doCheckUrl(@AncestorInPath Item item,

// Normally this permission is hidden and implied by Item.CONFIGURE, so from a view-only form you will not be able to use this check.
// (TODO under certain circumstances being granted only USE_OWN might suffice, though this presumes a fix of JENKINS-31870.)
if (item == null || !item.hasPermission(CredentialsProvider.USE_ITEM)) {
if (item == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
item != null && !item.hasPermission(CredentialsProvider.USE_ITEM)) {
return FormValidation.ok();
}

Expand Down Expand Up @@ -187,7 +188,7 @@ public FormValidation doCheckUrl(@AncestorInPath Item item,
return FormValidation.ok();
}

private static StandardCredentials lookupCredentials(Item project, String credentialId, String uri) {
private static StandardCredentials lookupCredentials(@CheckForNull Item project, String credentialId, String uri) {
return (credentialId == null) ? null : CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(StandardCredentials.class, project, ACL.SYSTEM,
GitURIRequirementsBuilder.fromUri(uri).build()),
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/jenkins/plugins/git/GitSCMSource.java
Expand Up @@ -192,7 +192,8 @@ public String getDisplayName() {
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context,
@QueryParameter String remote,
@QueryParameter String credentialsId) {
if (context == null || !context.hasPermission(Item.EXTENDED_READ)) {
if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
context != null && !context.hasPermission(Item.EXTENDED_READ)) {
return new StandardListBoxModel().includeCurrentValue(credentialsId);
}
return new StandardListBoxModel()
Expand All @@ -209,7 +210,8 @@ public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner cont
public FormValidation doCheckCredentialsId(@AncestorInPath SCMSourceOwner context,
@QueryParameter String url,
@QueryParameter String value) {
if (context == null || !context.hasPermission(Item.EXTENDED_READ)) {
if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) ||
context != null && !context.hasPermission(Item.EXTENDED_READ)) {
return FormValidation.ok();
}

Expand Down

0 comments on commit 086896a

Please sign in to comment.