ls-groups: Support listing of groups for a user
Add a new option to the 'ls-groups' command that allows to list the groups for a certain user. Change-Id: Ie3833c7441b399466a9881e901e3540342e6b3f9 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -10,6 +10,7 @@ SYNOPSIS
|
|||||||
[verse]
|
[verse]
|
||||||
'ssh' -p <port> <host> 'gerrit ls-groups'
|
'ssh' -p <port> <host> 'gerrit ls-groups'
|
||||||
[--project <NAME>]
|
[--project <NAME>]
|
||||||
|
[--user <NAME>]
|
||||||
[--visible-to-all]
|
[--visible-to-all]
|
||||||
[--type {internal | ldap | system}]
|
[--type {internal | ldap | system}]
|
||||||
|
|
||||||
@@ -39,6 +40,19 @@ OPTIONS
|
|||||||
Multiple --project options may be specified to specify additional
|
Multiple --project options may be specified to specify additional
|
||||||
projects. In this case all groups are listed that have a
|
projects. In this case all groups are listed that have a
|
||||||
permission for any of the specified projects.
|
permission for any of the specified projects.
|
||||||
|
+
|
||||||
|
This option can't be used together with the '--user' option.
|
||||||
|
|
||||||
|
--user::
|
||||||
|
-u::
|
||||||
|
User for which the groups should be listed. Only groups are
|
||||||
|
listed that contain this user as a member.
|
||||||
|
+
|
||||||
|
The calling user can list the groups for the own user or must be a
|
||||||
|
member of the privileged 'Administrators' group to list the groups
|
||||||
|
for other users.
|
||||||
|
+
|
||||||
|
This option can't be used together with the '--project' option.
|
||||||
|
|
||||||
--visible-to-all::
|
--visible-to-all::
|
||||||
Displays only groups that are visible to all registered users
|
Displays only groups that are visible to all registered users
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ 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.Account;
|
||||||
import com.google.gerrit.reviewdb.AccountGroup;
|
import com.google.gerrit.reviewdb.AccountGroup;
|
||||||
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
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;
|
||||||
@@ -37,6 +39,8 @@ public class ListGroupsCommand extends BaseCommand {
|
|||||||
@Inject
|
@Inject
|
||||||
private VisibleGroups.Factory visibleGroupsFactory;
|
private VisibleGroups.Factory visibleGroupsFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private IdentifiedUser.GenericFactory userFactory;
|
||||||
|
|
||||||
@Option(name = "--project", aliases = {"-p"},
|
@Option(name = "--project", aliases = {"-p"},
|
||||||
usage = "projects for which the groups should be listed")
|
usage = "projects for which the groups should be listed")
|
||||||
@@ -48,6 +52,10 @@ public class ListGroupsCommand extends BaseCommand {
|
|||||||
@Option(name = "--type", usage = "type of group")
|
@Option(name = "--type", usage = "type of group")
|
||||||
private AccountGroup.Type groupType;
|
private AccountGroup.Type groupType;
|
||||||
|
|
||||||
|
@Option(name = "--user", aliases = {"-u"},
|
||||||
|
usage = "user for which the groups should be listed")
|
||||||
|
private Account.Id user;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(final Environment env) throws IOException {
|
public void start(final Environment env) throws IOException {
|
||||||
startThread(new CommandRunnable() {
|
startThread(new CommandRunnable() {
|
||||||
@@ -62,12 +70,18 @@ public class ListGroupsCommand extends BaseCommand {
|
|||||||
private void display() throws Failure {
|
private void display() throws Failure {
|
||||||
final PrintWriter stdout = toPrintWriter(out);
|
final PrintWriter stdout = toPrintWriter(out);
|
||||||
try {
|
try {
|
||||||
|
if (user != null && !projects.isEmpty()) {
|
||||||
|
throw new UnloggedFailure(1, "fatal: --user and --project options are not compatible.");
|
||||||
|
}
|
||||||
|
|
||||||
final VisibleGroups visibleGroups = visibleGroupsFactory.create();
|
final VisibleGroups visibleGroups = visibleGroupsFactory.create();
|
||||||
visibleGroups.setOnlyVisibleToAll(visibleToAll);
|
visibleGroups.setOnlyVisibleToAll(visibleToAll);
|
||||||
visibleGroups.setGroupType(groupType);
|
visibleGroups.setGroupType(groupType);
|
||||||
final GroupList groupList;
|
final GroupList groupList;
|
||||||
if (!projects.isEmpty()) {
|
if (!projects.isEmpty()) {
|
||||||
groupList = visibleGroups.get(projects);
|
groupList = visibleGroups.get(projects);
|
||||||
|
} else if (user != null) {
|
||||||
|
groupList = visibleGroups.get(userFactory.create(user));
|
||||||
} else {
|
} else {
|
||||||
groupList = visibleGroups.get();
|
groupList = visibleGroups.get();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user