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:
@@ -16,7 +16,6 @@ package com.google.gerrit.server.account;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
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.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
@@ -41,7 +40,7 @@ public class GetGroups implements RestReadView<AccountResource> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GroupInfo> apply(AccountResource resource)
|
public List<GroupInfo> apply(AccountResource resource)
|
||||||
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
|
throws ResourceNotFoundException, OrmException {
|
||||||
IdentifiedUser user = resource.getUser();
|
IdentifiedUser user = resource.getUser();
|
||||||
Account.Id userId = user.getAccountId();
|
Account.Id userId = user.getAccountId();
|
||||||
List<GroupInfo> groups = Lists.newArrayList();
|
List<GroupInfo> groups = Lists.newArrayList();
|
||||||
|
@@ -24,7 +24,6 @@ import com.google.gerrit.common.errors.PermissionDeniedException;
|
|||||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
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.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||||
@@ -80,7 +79,7 @@ class CreateGroup implements RestModifyView<TopLevelResource, Input> {
|
|||||||
@Override
|
@Override
|
||||||
public GroupInfo apply(TopLevelResource resource, Input input)
|
public GroupInfo apply(TopLevelResource resource, Input input)
|
||||||
throws ResourceNotFoundException, AuthException, BadRequestException,
|
throws ResourceNotFoundException, AuthException, BadRequestException,
|
||||||
NameAlreadyUsedException, MethodNotAllowedException, OrmException {
|
NameAlreadyUsedException, OrmException {
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
input = new Input();
|
input = new Input();
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
package com.google.gerrit.server.group;
|
package com.google.gerrit.server.group;
|
||||||
|
|
||||||
import com.google.gerrit.common.groups.ListGroupsOption;
|
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.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||||
@@ -33,7 +32,7 @@ public class GetDetail implements RestReadView<GroupResource> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupInfo apply(GroupResource rsrc) throws ResourceNotFoundException,
|
public GroupInfo apply(GroupResource rsrc) throws ResourceNotFoundException,
|
||||||
MethodNotAllowedException, OrmException {
|
OrmException {
|
||||||
return json.format(rsrc);
|
return json.format(rsrc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.group;
|
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.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||||
@@ -31,7 +30,7 @@ class GetGroup implements RestReadView<GroupResource> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupInfo apply(GroupResource resource)
|
public GroupInfo apply(GroupResource resource)
|
||||||
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
|
throws ResourceNotFoundException, OrmException {
|
||||||
return json.format(resource.getGroup());
|
return json.format(resource.getGroup());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.group;
|
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.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||||
@@ -31,7 +30,7 @@ public class GetIncludedGroup implements RestReadView<IncludedGroupResource> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupInfo apply(IncludedGroupResource rsrc)
|
public GroupInfo apply(IncludedGroupResource rsrc)
|
||||||
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
|
throws ResourceNotFoundException, OrmException {
|
||||||
return json.format(rsrc.getMemberDescription());
|
return json.format(rsrc.getMemberDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
package com.google.gerrit.server.group;
|
package com.google.gerrit.server.group;
|
||||||
|
|
||||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
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.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
@@ -37,7 +36,7 @@ public class GetOwner implements RestReadView<GroupResource> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupInfo apply(GroupResource resource)
|
public GroupInfo apply(GroupResource resource)
|
||||||
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
|
throws ResourceNotFoundException, OrmException {
|
||||||
AccountGroup group = resource.toAccountGroup();
|
AccountGroup group = resource.toAccountGroup();
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
throw new ResourceNotFoundException();
|
throw new ResourceNotFoundException();
|
||||||
|
@@ -65,15 +65,15 @@ public class GroupJson {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroupInfo format(GroupResource rsrc)
|
public GroupInfo format(GroupResource rsrc) throws ResourceNotFoundException,
|
||||||
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
|
OrmException {
|
||||||
GroupInfo info = init(rsrc.getGroup());
|
GroupInfo info = init(rsrc.getGroup());
|
||||||
initMembersAndIncludes(rsrc, info);
|
initMembersAndIncludes(rsrc, info);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroupInfo format(GroupDescription.Basic group)
|
public GroupInfo format(GroupDescription.Basic group)
|
||||||
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
|
throws ResourceNotFoundException, OrmException {
|
||||||
GroupInfo info = init(group);
|
GroupInfo info = init(group);
|
||||||
if (options.contains(MEMBERS) || options.contains(INCLUDES)) {
|
if (options.contains(MEMBERS) || options.contains(INCLUDES)) {
|
||||||
GroupResource rsrc =
|
GroupResource rsrc =
|
||||||
@@ -107,7 +107,11 @@ public class GroupJson {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GroupInfo initMembersAndIncludes(GroupResource rsrc, GroupInfo info)
|
private GroupInfo initMembersAndIncludes(GroupResource rsrc, GroupInfo info)
|
||||||
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
|
throws ResourceNotFoundException, OrmException {
|
||||||
|
if (rsrc.toAccountGroup() == null) {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
try {
|
||||||
if (options.contains(MEMBERS)) {
|
if (options.contains(MEMBERS)) {
|
||||||
info.members = listMembers.get().apply(rsrc);
|
info.members = listMembers.get().apply(rsrc);
|
||||||
}
|
}
|
||||||
@@ -116,6 +120,12 @@ public class GroupJson {
|
|||||||
info.includes = listIncludes.get().apply(rsrc);
|
info.includes = listIncludes.get().apply(rsrc);
|
||||||
}
|
}
|
||||||
return info;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GroupInfo {
|
public static class GroupInfo {
|
||||||
|
@@ -25,7 +25,6 @@ import com.google.gerrit.common.errors.NoSuchGroupException;
|
|||||||
import com.google.gerrit.common.groups.ListGroupsOption;
|
import com.google.gerrit.common.groups.ListGroupsOption;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
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.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||||
@@ -147,8 +146,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
|||||||
new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GroupInfo> get() throws ResourceNotFoundException,
|
public List<GroupInfo> get() throws ResourceNotFoundException, OrmException {
|
||||||
MethodNotAllowedException, OrmException {
|
|
||||||
List<GroupInfo> groupInfos;
|
List<GroupInfo> groupInfos;
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
if (owned) {
|
if (owned) {
|
||||||
@@ -189,7 +187,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<GroupInfo> getGroupsOwnedBy(IdentifiedUser user)
|
private List<GroupInfo> getGroupsOwnedBy(IdentifiedUser user)
|
||||||
throws ResourceNotFoundException, MethodNotAllowedException, OrmException {
|
throws ResourceNotFoundException, OrmException {
|
||||||
List<GroupInfo> groups = Lists.newArrayList();
|
List<GroupInfo> groups = Lists.newArrayList();
|
||||||
for (AccountGroup g : filterGroups(groupCache.all())) {
|
for (AccountGroup g : filterGroups(groupCache.all())) {
|
||||||
GroupControl ctl = groupControlFactory.controlFor(g);
|
GroupControl ctl = groupControlFactory.controlFor(g);
|
||||||
|
Reference in New Issue
Block a user