Show more fields in ls-users command
The added fields are username and active flag.
Change-Id: I56314b2d2749cfcb0057f4ae90785425e32c29ba
diff --git a/src/main/java/com/googlesource/gerrit/plugins/adminconsole/ListUsersCommand.java b/src/main/java/com/googlesource/gerrit/plugins/adminconsole/ListUsersCommand.java
index af0af26..f304b0d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/adminconsole/ListUsersCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/adminconsole/ListUsersCommand.java
@@ -20,8 +20,10 @@
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.server.ReviewDb;
+import com.google.gerrit.server.account.AccountResolver;
import com.google.gerrit.sshd.CommandMetaData;
import com.google.gerrit.sshd.SshCommand;
+import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.ResultSet;
import com.google.inject.Inject;
@@ -31,6 +33,7 @@
@CommandMetaData(name = "ls-users", description = "List users")
public final class ListUsersCommand extends SshCommand {
private ReviewDb db;
+ private final AccountResolver accountResolver;
@Option(name = "--active-only", usage = "show only active users")
private boolean activeOnly = false;
@@ -39,8 +42,10 @@
private boolean inactiveOnly = false;
@Inject
- ListUsersCommand(ReviewDb db) {
+ ListUsersCommand(ReviewDb db,
+ AccountResolver accountResolver) {
this.db = db;
+ this.accountResolver = accountResolver;
}
@Override
@@ -53,9 +58,14 @@
if (inactiveOnly && account.isActive()) {
continue;
}
+ String username = getUsername(account);
String out = new StringBuilder()
.append(account.getId().toString())
.append(" |")
+ .append(Strings.isNullOrEmpty(username)
+ ? ""
+ : " " + username)
+ .append(" |")
.append(Strings.isNullOrEmpty(account.getFullName())
? ""
: " " + account.getFullName())
@@ -63,8 +73,19 @@
.append(Strings.isNullOrEmpty(account.getPreferredEmail())
? ""
: " " + account.getPreferredEmail())
+ .append(" |")
+ .append(account.isActive()
+ ? " active"
+ : " inactive")
.toString();
stdout.println(out);
}
}
+
+ private String getUsername(Account account) throws OrmException {
+ String id = account.getId().toString();
+ Account accountFromResolver = accountResolver.find(id);
+ return accountFromResolver == null ? null
+ : accountFromResolver.getUserName();
+ }
}