Merge branch 'stable-2.13'
* stable-2.13:
Show more fields in ls-users command
Add options to filter by active flag in ls-users command
Escape double dashes in documentation
Change-Id: Ibf4d331e983eef1e63bac4e40e2fb7a01738de21
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 12c3b97..8ead5ad 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/adminconsole/ListUsersCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/adminconsole/ListUsersCommand.java
@@ -20,28 +20,52 @@
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;
+import org.kohsuke.args4j.Option;
+
@RequiresCapability(value=GlobalCapability.ADMINISTRATE_SERVER, scope=CapabilityScope.CORE)
@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;
+
+ @Option(name = "--inactive-only", usage = "show only inactive users")
+ private boolean inactiveOnly = false;
@Inject
- ListUsersCommand(ReviewDb db) {
+ ListUsersCommand(ReviewDb db,
+ AccountResolver accountResolver) {
this.db = db;
+ this.accountResolver = accountResolver;
}
@Override
protected void run() throws UnloggedFailure, Failure, Exception {
ResultSet<Account> accounts = db.accounts().all();
for (Account account : accounts) {
+ if (activeOnly && !account.isActive()) {
+ continue;
+ }
+ 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())
@@ -49,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(db, id);
+ return accountFromResolver == null ? null
+ : accountFromResolver.getUserName();
+ }
}
diff --git a/src/main/resources/Documentation/cmd-ls-users.md b/src/main/resources/Documentation/cmd-ls-users.md
index a3ead52..db4aa9b 100644
--- a/src/main/resources/Documentation/cmd-ls-users.md
+++ b/src/main/resources/Documentation/cmd-ls-users.md
@@ -15,10 +15,13 @@
OPTIONS
-------
+`--active-only`
+> Show only active users
---help
+`--inactive-only`
+> Show only inactive users
--h
+`--help, -h`
> Display usage information.
ACCESS
diff --git a/src/main/resources/Documentation/cmd-show-account.md b/src/main/resources/Documentation/cmd-show-account.md
index c1455ec..96c3bba 100644
--- a/src/main/resources/Documentation/cmd-show-account.md
+++ b/src/main/resources/Documentation/cmd-show-account.md
@@ -20,24 +20,22 @@
OPTIONS
-------
-user
+`user`
> User to look up: This can be in one of several formats: LastName,\\\\ FirstName, email\@address.com, account id or an user name. Be sure to double-escape spaces. Case-sensitive
---show-groups
+`--show-groups`
> Show all groups user is a member of?
---filter-groups
+`--filter-groups`
> Filter group list?
---filter-string
+`--filter-string`
> String to perform group filtering on. Does not currently support regex. Case-insensitive.
---show-keys
+`--show-keys`
> Show users ssh public keys?
---help
-
--h
+`--help, -h`
> Display usage information.
ACCESS
diff --git a/src/main/resources/Documentation/cmd-show-repo-access.md b/src/main/resources/Documentation/cmd-show-repo-access.md
index 2ecd376..fa8d3b0 100644
--- a/src/main/resources/Documentation/cmd-show-repo-access.md
+++ b/src/main/resources/Documentation/cmd-show-repo-access.md
@@ -19,14 +19,13 @@
OPTIONS
-------
-repository
+`repository`
> Repository to show access for
--w
+`-w`
> Display without line width truncation
---help
--h
+`--help, -h`
> Display usage information.
ACCESS
diff --git a/src/main/resources/Documentation/cmd-show-repo-account-access.md b/src/main/resources/Documentation/cmd-show-repo-account-access.md
index e59913b..9743fda 100644
--- a/src/main/resources/Documentation/cmd-show-repo-account-access.md
+++ b/src/main/resources/Documentation/cmd-show-repo-account-access.md
@@ -19,17 +19,16 @@
OPTIONS
-------
-repository
+`repository`
> Repository to show access for
---user
+`--user`
> User to look up: This can be in one of several formats: LastName,\\\\ FirstName, email\@address.com, account id or an user name. Be sure to double-escape spaces. Case-sensitive
--w
+`-w`
> Display without line width truncation
---help
--h
+`--help, -h`
> Display usage information.
ACCESS