Remove access of groups related db tables from MembersCollection

Change-Id: Iad6a15df30d39de75357b144bbe3f905cca92780
This commit is contained in:
Alice Kober-Sotzek 2017-07-25 13:33:29 +02:00
parent c16a230c08
commit a3d9d3bb7c
2 changed files with 15 additions and 5 deletions

View File

@ -16,7 +16,9 @@ package com.google.gerrit.server.group;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.reviewdb.client.AccountGroupName;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gwtorm.server.OrmDuplicateKeyException;
@ -57,4 +59,10 @@ public class Groups {
public ImmutableList<AccountGroup> getAll(ReviewDb db) throws OrmException {
return ImmutableList.copyOf(db.accountGroups().all());
}
public boolean isMember(ReviewDb db, AccountGroup group, Account.Id accountId)
throws OrmException {
AccountGroupMember.Key key = new AccountGroupMember.Key(accountId, group.getId());
return db.accountGroupMembers().get(key) != null;
}
}

View File

@ -23,7 +23,7 @@ import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.extensions.restapi.TopLevelResource;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountsCollection;
@ -41,6 +41,7 @@ public class MembersCollection
private final DynamicMap<RestView<MemberResource>> views;
private final Provider<ListMembers> list;
private final AccountsCollection accounts;
private final Groups groups;
private final Provider<ReviewDb> db;
private final AddMembers put;
@ -49,11 +50,13 @@ public class MembersCollection
DynamicMap<RestView<MemberResource>> views,
Provider<ListMembers> list,
AccountsCollection accounts,
Groups groups,
Provider<ReviewDb> db,
AddMembers put) {
this.views = views;
this.list = list;
this.accounts = accounts;
this.groups = groups;
this.db = db;
this.put = put;
}
@ -67,14 +70,13 @@ public class MembersCollection
public MemberResource parse(GroupResource parent, IdString id)
throws MethodNotAllowedException, AuthException, ResourceNotFoundException, OrmException,
IOException, ConfigInvalidException {
if (parent.toAccountGroup() == null) {
AccountGroup group = parent.toAccountGroup();
if (group == null) {
throw new MethodNotAllowedException();
}
IdentifiedUser user = accounts.parse(TopLevelResource.INSTANCE, id).getUser();
AccountGroupMember.Key key =
new AccountGroupMember.Key(user.getAccountId(), parent.toAccountGroup().getId());
if (db.get().accountGroupMembers().get(key) != null
if (groups.isMember(db.get(), group, user.getAccountId())
&& parent.getControl().canSeeMember(user.getAccountId())) {
return new MemberResource(parent, user);
}