Skip to content

Commit

Permalink
[JENKINS-9694] bot permissions didn't apply for build command
Browse files Browse the repository at this point in the history
  • Loading branch information
kutzi committed May 15, 2011
1 parent e886062 commit b43fe93
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main/java/hudson/plugins/im/bot/BuildCommand.java
Expand Up @@ -7,12 +7,14 @@
import hudson.model.AbstractProject;
import hudson.model.BooleanParameterValue;
import hudson.model.Cause;
import hudson.model.Item;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.Queue;
import hudson.model.StringParameterValue;
import hudson.plugins.im.IMCause;
import hudson.plugins.im.Sender;
import hudson.security.Permission;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -62,6 +64,11 @@ public String getReply(Bot bot, Sender sender, String args[]) {
AbstractProject<?, ?> project = getJobProvider().getJobByName(jobName);
if (project != null) {

String checkPermission = checkPermission(sender, project);
if (checkPermission != null) {
return checkPermission;
}

String msg = "";
if (project.isInQueue()) {
Queue.Item queueItem = project.getQueueItem();
Expand Down Expand Up @@ -147,12 +154,20 @@ public String getReply(Bot bot, Sender sender, String args[]) {
}
}

private String giveSyntax(String sender, String cmd) {
private String checkPermission(Sender sender, AbstractProject<?, ?> project) {
if (!project.hasPermission(Item.BUILD)) {
return sender.getNickname() + ": you're not allowed to build job " + project.getDisplayName() + "!";
}
return null;
}

private String giveSyntax(String sender, String cmd) {
return sender + ": syntax is: '" + cmd + SYNTAX + "'";
}

public String getHelp() {
return HELP;
}


}

0 comments on commit b43fe93

Please sign in to comment.