When listing groups don't try to include members for external groups

When listing groups via REST don't try to include members and included
groups for external groups. Members and included groups can only be
listed for internal groups.

Change-Id: I1431a5908549c38b9a55f73baf47af801422909b
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-03-08 16:12:41 +01:00
parent 3f4a022b6b
commit 5aef4f3614
8 changed files with 27 additions and 25 deletions

View File

@@ -16,7 +16,6 @@ package com.google.gerrit.server.account;
import com.google.common.collect.Lists;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.Account;
@@ -41,7 +40,7 @@ public class GetGroups implements RestReadView<AccountResource> {
@Override
public List<GroupInfo> apply(AccountResource resource)
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
throws ResourceNotFoundException, OrmException {
IdentifiedUser user = resource.getUser();
Account.Id userId = user.getAccountId();
List<GroupInfo> groups = Lists.newArrayList();

View File

@@ -24,7 +24,6 @@ import com.google.gerrit.common.errors.PermissionDeniedException;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.restapi.TopLevelResource;
@@ -80,7 +79,7 @@ class CreateGroup implements RestModifyView<TopLevelResource, Input> {
@Override
public GroupInfo apply(TopLevelResource resource, Input input)
throws ResourceNotFoundException, AuthException, BadRequestException,
NameAlreadyUsedException, MethodNotAllowedException, OrmException {
NameAlreadyUsedException, OrmException {
if (input == null) {
input = new Input();
}

View File

@@ -15,7 +15,6 @@
package com.google.gerrit.server.group;
import com.google.gerrit.common.groups.ListGroupsOption;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.server.group.GroupJson.GroupInfo;
@@ -33,7 +32,7 @@ public class GetDetail implements RestReadView<GroupResource> {
@Override
public GroupInfo apply(GroupResource rsrc) throws ResourceNotFoundException,
MethodNotAllowedException, OrmException {
OrmException {
return json.format(rsrc);
}
}

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.server.group;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.server.group.GroupJson.GroupInfo;
@@ -31,7 +30,7 @@ class GetGroup implements RestReadView<GroupResource> {
@Override
public GroupInfo apply(GroupResource resource)
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
throws ResourceNotFoundException, OrmException {
return json.format(resource.getGroup());
}
}

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.server.group;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.server.group.GroupJson.GroupInfo;
@@ -31,7 +30,7 @@ public class GetIncludedGroup implements RestReadView<IncludedGroupResource> {
@Override
public GroupInfo apply(IncludedGroupResource rsrc)
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
throws ResourceNotFoundException, OrmException {
return json.format(rsrc.getMemberDescription());
}
}

View File

@@ -15,7 +15,6 @@
package com.google.gerrit.server.group;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.AccountGroup;
@@ -37,7 +36,7 @@ public class GetOwner implements RestReadView<GroupResource> {
@Override
public GroupInfo apply(GroupResource resource)
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
throws ResourceNotFoundException, OrmException {
AccountGroup group = resource.toAccountGroup();
if (group == null) {
throw new ResourceNotFoundException();

View File

@@ -65,15 +65,15 @@ public class GroupJson {
return this;
}
public GroupInfo format(GroupResource rsrc)
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
public GroupInfo format(GroupResource rsrc) throws ResourceNotFoundException,
OrmException {
GroupInfo info = init(rsrc.getGroup());
initMembersAndIncludes(rsrc, info);
return info;
}
public GroupInfo format(GroupDescription.Basic group)
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
throws ResourceNotFoundException, OrmException {
GroupInfo info = init(group);
if (options.contains(MEMBERS) || options.contains(INCLUDES)) {
GroupResource rsrc =
@@ -107,15 +107,25 @@ public class GroupJson {
}
private GroupInfo initMembersAndIncludes(GroupResource rsrc, GroupInfo info)
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
if (options.contains(MEMBERS)) {
info.members = listMembers.get().apply(rsrc);
throws ResourceNotFoundException, OrmException {
if (rsrc.toAccountGroup() == null) {
return info;
}
try {
if (options.contains(MEMBERS)) {
info.members = listMembers.get().apply(rsrc);
}
if (options.contains(INCLUDES)) {
info.includes = listIncludes.get().apply(rsrc);
if (options.contains(INCLUDES)) {
info.includes = listIncludes.get().apply(rsrc);
}
return info;
} catch (MethodNotAllowedException e) {
// should never happen, this exception is only thrown if we would try to
// list members/includes of an external group, but in case of an external
// group we return before
throw new IllegalStateException(e);
}
return info;
}
public static class GroupInfo {

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.common.groups.ListGroupsOption;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestReadView;
@@ -147,8 +146,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
new TypeToken<Map<String, GroupInfo>>() {}.getType());
}
public List<GroupInfo> get() throws ResourceNotFoundException,
MethodNotAllowedException, OrmException {
public List<GroupInfo> get() throws ResourceNotFoundException, OrmException {
List<GroupInfo> groupInfos;
if (user != null) {
if (owned) {
@@ -189,7 +187,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
}
private List<GroupInfo> getGroupsOwnedBy(IdentifiedUser user)
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
throws ResourceNotFoundException, OrmException {
List<GroupInfo> groups = Lists.newArrayList();
for (AccountGroup g : filterGroups(groupCache.all())) {
GroupControl ctl = groupControlFactory.controlFor(g);