ls-groups: Support listing groups by group type
Change-Id: I4d25212f2b64de9b89481ee999381c69d4033c13 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -11,6 +11,7 @@ SYNOPSIS
|
|||||||
'ssh' -p <port> <host> 'gerrit ls-groups'
|
'ssh' -p <port> <host> 'gerrit ls-groups'
|
||||||
[--project <NAME>]
|
[--project <NAME>]
|
||||||
[--visible-to-all]
|
[--visible-to-all]
|
||||||
|
[--type {internal | ldap | system}]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
@@ -44,6 +45,16 @@ OPTIONS
|
|||||||
(groups that are explicitly marked as visible to all registered
|
(groups that are explicitly marked as visible to all registered
|
||||||
users).
|
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
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@@ -46,6 +46,7 @@ public class VisibleGroups {
|
|||||||
|
|
||||||
private Collection<ProjectControl> projects;
|
private Collection<ProjectControl> projects;
|
||||||
private boolean onlyVisibleToAll;
|
private boolean onlyVisibleToAll;
|
||||||
|
private AccountGroup.Type groupType;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
VisibleGroups(final Provider<IdentifiedUser> currentUser,
|
VisibleGroups(final Provider<IdentifiedUser> currentUser,
|
||||||
@@ -66,6 +67,10 @@ public class VisibleGroups {
|
|||||||
this.onlyVisibleToAll = onlyVisibleToAll;
|
this.onlyVisibleToAll = onlyVisibleToAll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setGroupType(final AccountGroup.Type groupType) {
|
||||||
|
this.groupType = groupType;
|
||||||
|
}
|
||||||
|
|
||||||
public GroupList get() throws OrmException, NoSuchGroupException {
|
public GroupList get() throws OrmException, NoSuchGroupException {
|
||||||
final Iterable<AccountGroup> groups;
|
final Iterable<AccountGroup> groups;
|
||||||
if (projects != null && !projects.isEmpty()) {
|
if (projects != null && !projects.isEmpty()) {
|
||||||
@@ -103,7 +108,8 @@ public class VisibleGroups {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (onlyVisibleToAll && !group.isVisibleToAll()) {
|
if ((onlyVisibleToAll && !group.isVisibleToAll())
|
||||||
|
|| (groupType != null && !groupType.equals(group.getType()))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
filteredGroups.add(group);
|
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.data.GroupList;
|
||||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||||
import com.google.gerrit.server.account.VisibleGroups;
|
import com.google.gerrit.server.account.VisibleGroups;
|
||||||
|
import com.google.gerrit.reviewdb.AccountGroup;
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
import com.google.gerrit.sshd.BaseCommand;
|
import com.google.gerrit.sshd.BaseCommand;
|
||||||
import com.google.gwtorm.client.OrmException;
|
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")
|
@Option(name = "--visible-to-all", usage = "to list only groups that are visible to all registered users")
|
||||||
private boolean visibleToAll;
|
private boolean visibleToAll;
|
||||||
|
|
||||||
|
@Option(name = "--type", usage = "type of group")
|
||||||
|
private AccountGroup.Type groupType;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(final Environment env) throws IOException {
|
public void start(final Environment env) throws IOException {
|
||||||
startThread(new CommandRunnable() {
|
startThread(new CommandRunnable() {
|
||||||
@@ -61,6 +65,7 @@ public class ListGroupsCommand extends BaseCommand {
|
|||||||
final VisibleGroups visibleGroups = visibleGroupsFactory.create();
|
final VisibleGroups visibleGroups = visibleGroupsFactory.create();
|
||||||
visibleGroups.setProjects(projects);
|
visibleGroups.setProjects(projects);
|
||||||
visibleGroups.setOnlyVisibleToAll(visibleToAll);
|
visibleGroups.setOnlyVisibleToAll(visibleToAll);
|
||||||
|
visibleGroups.setGroupType(groupType);
|
||||||
final GroupList groupList = visibleGroups.get();
|
final GroupList groupList = visibleGroups.get();
|
||||||
for (final GroupDetail groupDetail : groupList.getGroups()) {
|
for (final GroupDetail groupDetail : groupList.getGroups()) {
|
||||||
stdout.print(groupDetail.group.getName() + "\n");
|
stdout.print(groupDetail.group.getName() + "\n");
|
||||||
|
Reference in New Issue
Block a user