Skip to content

Commit

Permalink
[JENKINS-46925] Do not show the Action if the thing is not configurable.
Browse files Browse the repository at this point in the history
The action was still showing up on projects that could never have
configuration added.  When you tried to add configuration you would get
the User X is missing the Item.Configure permission, but its just not
good UX, so hide the action in case System can not configure the thing
(ie it can never have config files)
  • Loading branch information
jtnord committed Sep 18, 2017
1 parent 5c4cf6c commit 21fa629
Showing 1 changed file with 19 additions and 1 deletion.
Expand Up @@ -10,6 +10,8 @@

import javax.servlet.ServletException;

import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.lib.configprovider.model.ContentType;
Expand All @@ -31,6 +33,7 @@
import hudson.model.Action;
import hudson.model.Item;
import hudson.model.Job;
import hudson.security.ACL;
import hudson.security.Permission;
import hudson.util.FormValidation;

Expand All @@ -53,7 +56,22 @@ public AbstractFolder<?> getFolder() {

@Override
public String getIconFileName() {
return folder.hasPermission(Item.EXTENDED_READ) ? ConfigFilesManagement.ICON_PATH : null;
// whilst you may be able to read configuration of a ComputedFolder they are not configurable, so the link should never be shown.
boolean hasPerm = folder.hasPermission(Item.EXTENDED_READ);
if (hasPerm) {
// check that the thing can store configuration (ie it is ultimately configurable)
// need to do this as System as a user with EXTENDED_READ but not configure should still see this.
// TODO use ACL.as when baseline is 2.14+
final SecurityContext impersonate = ACL.impersonate(ACL.SYSTEM);
try {
hasPerm = folder.hasPermission(Item.CONFIGURE);
}
finally {
SecurityContextHolder.setContext(impersonate);
}
}

return hasPerm ? ConfigFilesManagement.ICON_PATH : null;
}

/**
Expand Down

0 comments on commit 21fa629

Please sign in to comment.