James Moger
2014-03-14 2331e7936c27e32b7d6d251b3637efc0e1184a81
Support admin commands that respect user permissions
4 files modified
14 ■■■■ changed files
src/main/java/com/gitblit/transport/ssh/CommandMetaData.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/commands/CreateRepository.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/commands/SetAccountCommand.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/CommandMetaData.java
@@ -28,5 +28,6 @@
public @interface CommandMetaData {
String name();
String description() default "";
boolean admin() default false;
boolean hidden() default false;
}
src/main/java/com/gitblit/transport/ssh/commands/CreateRepository.java
@@ -20,7 +20,7 @@
import com.gitblit.transport.ssh.CommandMetaData;
@CommandMetaData(name = "create-repository", description = "Create new GIT repository", hidden = true)
@CommandMetaData(name = "create-repository", description = "Create new GIT repository", admin = true, hidden = true)
public class CreateRepository extends SshCommand {
  @Option(name = "--name", aliases = {"-n"}, required = true, metaVar = "NAME", usage = "name of repository to be created")
src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java
@@ -93,6 +93,12 @@
      }
      Command cmd = getCommand();
      if (cmd.getClass().isAnnotationPresent(CommandMetaData.class)) {
          CommandMetaData meta = cmd.getClass().getAnnotation(CommandMetaData.class);
          if (meta.admin() && !ctx.getClient().getUser().canAdmin()) {
              throw new UnloggedFailure(1, MessageFormat.format("{0} requires admin permissions", commandName));
          }
      }
      if (cmd instanceof BaseCommand) {
        BaseCommand bc = (BaseCommand) cmd;
        if (getName().isEmpty()) {
@@ -162,6 +168,9 @@
      final Class<? extends Command> c = m.get(name);
      CommandMetaData meta = c.getAnnotation(CommandMetaData.class);
      if (meta != null) {
        if (meta.admin() && !ctx.getClient().getUser().canAdmin()) {
            continue;
        }
        if (meta.hidden()) {
            continue;
        }
src/main/java/com/gitblit/transport/ssh/commands/SetAccountCommand.java
@@ -26,7 +26,7 @@
import com.gitblit.transport.ssh.IKeyManager;
/** Set a user's account settings. **/
@CommandMetaData(name = "set-account", description = "Change an account's settings")
@CommandMetaData(name = "set-account", description = "Change an account's settings", admin = true)
public class SetAccountCommand extends BaseKeyCommand {
    private static final String ALL = "ALL";