Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix accessing folder credentials #154

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ public String getStoreBaseUrl(String itUrl) {
public boolean isVisible() {
if (context instanceof AccessControlled) {
AccessControlled accessControlled = (AccessControlled) this.context;
if (accessControlled.hasPermission(Jenkins.ADMINISTER) || !accessControlled.hasPermission(CredentialsProvider.VIEW)) {
// must have permission, Administrator's view credentials from 'Manage Jenkins'
if (isVisibleForAdministrator(accessControlled) || !accessControlled.hasPermission(CredentialsProvider.VIEW)) {
// must have permission
return false;
}
}

for (CredentialsProvider p : CredentialsProvider.enabled(context)) {
if (p.hasCredentialsDescriptors()) {
// at least one provider must have the potential for at least one type
Expand All @@ -240,6 +240,16 @@ public boolean isVisible() {
return false;
}

/**
* Administrator's view credentials from 'Manage Jenkins', except when it's a folder.
* @param accessControlled an access controlled object.
* @return whether the action should be visible or not if the user is an administrator.
*/
private boolean isVisibleForAdministrator(AccessControlled accessControlled) {
return accessControlled.hasPermission(Jenkins.ADMINISTER) &&
!accessControlled.getClass().getName().equals("com.cloudbees.hudson.plugins.folder.Folder");
}

/**
* Expose a Jenkins {@link Api}.
*
Expand Down