Skip to content

Commit

Permalink
[JENKINS-9694] bot permissions didn't apply for userstat command
Browse files Browse the repository at this point in the history
  • Loading branch information
kutzi committed May 17, 2011
1 parent 4044cfa commit fc92b63
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main/java/hudson/plugins/im/bot/UserStatCommand.java
Expand Up @@ -2,6 +2,7 @@

import hudson.Extension;
import hudson.model.Hudson;
import hudson.model.Item;
import hudson.model.User;
import hudson.plugins.cigame.UserScoreProperty;
import hudson.plugins.im.Sender;
Expand All @@ -22,6 +23,12 @@ protected String getReply(Bot bot, Sender sender, String[] args) {
String userName = args[1];
User user = User.get(userName, false);
if (user != null) {

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

StringBuilder buf = new StringBuilder();
buf.append(userName).append(":");

Expand Down Expand Up @@ -51,11 +58,18 @@ protected String getReply(Bot bot, Sender sender, String[] args) {
}
return buf.toString();
} else {
return "Don't know a user named " + userName;
return sender.getNickname() + ": don't know a user named " + userName;
}
}

@Override
private String checkPermission(User user, Sender sender) {
if (!user.hasPermission(Item.READ)) {
return sender.getNickname() + ": you may not read that user!";
}
return null;
}

@Override
public String getHelp() {
return " <username> - prints information about a Hudson user";
}
Expand Down

0 comments on commit fc92b63

Please sign in to comment.