Merge "ls-groups: Support listing groups by group type"
This commit is contained in:
@@ -11,6 +11,7 @@ SYNOPSIS
|
||||
'ssh' -p <port> <host> 'gerrit ls-groups'
|
||||
[--project <NAME>]
|
||||
[--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
|
||||
--------
|
||||
|
||||
|
@@ -46,6 +46,7 @@ public class VisibleGroups {
|
||||
|
||||
private Collection<ProjectControl> projects;
|
||||
private boolean onlyVisibleToAll;
|
||||
private AccountGroup.Type groupType;
|
||||
|
||||
@Inject
|
||||
VisibleGroups(final Provider<IdentifiedUser> 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<AccountGroup> 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);
|
||||
|
@@ -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");
|
||||
|
Reference in New Issue
Block a user