diff --git a/Documentation/cmd-ls-groups.txt b/Documentation/cmd-ls-groups.txt index 78b2f2eb7c..961e0633b2 100644 --- a/Documentation/cmd-ls-groups.txt +++ b/Documentation/cmd-ls-groups.txt @@ -11,6 +11,7 @@ SYNOPSIS 'ssh' -p 'gerrit ls-groups' [--project ] [--visible-to-all] + [--type {internal | ldap | system}] DESCRIPTION ----------- @@ -44,6 +45,16 @@ OPTIONS (groups that are explicitly marked as visible to all registered users). +--type:: + Display only groups of the specified type. If not specified, + groups of all types are displayed. Supported types: ++ +-- +`internal`:: Any group defined within Gerrit. +`ldap`:: Any group defined by an external LDAP database. +`system`:: Any system defined and managed group. +-- + EXAMPLES -------- diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/VisibleGroups.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/VisibleGroups.java index 94eed9f971..fb4ecd72d1 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/VisibleGroups.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/VisibleGroups.java @@ -46,6 +46,7 @@ public class VisibleGroups { private Collection projects; private boolean onlyVisibleToAll; + private AccountGroup.Type groupType; @Inject VisibleGroups(final Provider currentUser, @@ -66,6 +67,10 @@ public class VisibleGroups { this.onlyVisibleToAll = onlyVisibleToAll; } + public void setGroupType(final AccountGroup.Type groupType) { + this.groupType = groupType; + } + public GroupList get() throws OrmException, NoSuchGroupException { final Iterable groups; if (projects != null && !projects.isEmpty()) { @@ -103,7 +108,8 @@ public class VisibleGroups { continue; } } - if (onlyVisibleToAll && !group.isVisibleToAll()) { + if ((onlyVisibleToAll && !group.isVisibleToAll()) + || (groupType != null && !groupType.equals(group.getType()))) { continue; } filteredGroups.add(group); diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ListGroupsCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ListGroupsCommand.java index 7a9bd70827..5d2742cffc 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ListGroupsCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ListGroupsCommand.java @@ -18,6 +18,7 @@ import com.google.gerrit.common.data.GroupDetail; import com.google.gerrit.common.data.GroupList; import com.google.gerrit.common.errors.NoSuchGroupException; import com.google.gerrit.server.account.VisibleGroups; +import com.google.gerrit.reviewdb.AccountGroup; import com.google.gerrit.server.project.ProjectControl; import com.google.gerrit.sshd.BaseCommand; import com.google.gwtorm.client.OrmException; @@ -44,6 +45,9 @@ public class ListGroupsCommand extends BaseCommand { @Option(name = "--visible-to-all", usage = "to list only groups that are visible to all registered users") private boolean visibleToAll; + @Option(name = "--type", usage = "type of group") + private AccountGroup.Type groupType; + @Override public void start(final Environment env) throws IOException { startThread(new CommandRunnable() { @@ -61,6 +65,7 @@ public class ListGroupsCommand extends BaseCommand { final VisibleGroups visibleGroups = visibleGroupsFactory.create(); visibleGroups.setProjects(projects); visibleGroups.setOnlyVisibleToAll(visibleToAll); + visibleGroups.setGroupType(groupType); final GroupList groupList = visibleGroups.get(); for (final GroupDetail groupDetail : groupList.getGroups()) { stdout.print(groupDetail.group.getName() + "\n");