Move GroupMembers binding to GerritGlobalModule

The only request-scoped variable this needs is the current user, which
can be injected in the factory. Not requiring request scope means it
can now be used by new REST API handlers.

Change-Id: I033586f2234b88139e62a6288097dc7099bd0fcf
This commit is contained in:
Dave Borowitz 2013-02-14 08:23:42 -08:00 committed by Gerrit Code Review
parent 9bdb1bee26
commit d386499438
6 changed files with 15 additions and 10 deletions

View File

@ -48,6 +48,10 @@ public class BaseServiceImplementation {
return null; return null;
} }
protected CurrentUser getCurrentUser() {
return currentUser.get();
}
/** /**
* Executes <code>action.run</code> with an active ReviewDb connection. * Executes <code>action.run</code> with an active ReviewDb connection.
* <p> * <p>

View File

@ -278,8 +278,8 @@ class SuggestServiceImpl extends BaseServiceImplementation implements
} }
try { try {
final Set<Account> members = final Set<Account> members = groupMembersFactory.create(getCurrentUser())
groupMembersFactory.create().listAccounts(group.getUUID(), project); .listAccounts(group.getUUID(), project);
if (members.isEmpty()) { if (members.isEmpty()) {
return false; return false;

View File

@ -21,11 +21,12 @@ import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid; import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupMember; import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectControl; import com.google.gerrit.server.project.ProjectControl;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@ -33,21 +34,21 @@ import java.util.Set;
public class GroupMembers { public class GroupMembers {
public interface Factory { public interface Factory {
GroupMembers create(); GroupMembers create(CurrentUser currentUser);
} }
private final GroupCache groupCache; private final GroupCache groupCache;
private final GroupDetailFactory.Factory groupDetailFactory; private final GroupDetailFactory.Factory groupDetailFactory;
private final AccountCache accountCache; private final AccountCache accountCache;
private final ProjectControl.GenericFactory projectControl; private final ProjectControl.GenericFactory projectControl;
private final IdentifiedUser currentUser; private final CurrentUser currentUser;
@Inject @Inject
GroupMembers(final GroupCache groupCache, GroupMembers(final GroupCache groupCache,
final GroupDetailFactory.Factory groupDetailFactory, final GroupDetailFactory.Factory groupDetailFactory,
final AccountCache accountCache, final AccountCache accountCache,
final ProjectControl.GenericFactory projectControl, final ProjectControl.GenericFactory projectControl,
final IdentifiedUser currentUser) { @Assisted final CurrentUser currentUser) {
this.groupCache = groupCache; this.groupCache = groupCache;
this.groupDetailFactory = groupDetailFactory; this.groupDetailFactory = groupDetailFactory;
this.accountCache = accountCache; this.accountCache = accountCache;

View File

@ -51,6 +51,7 @@ import com.google.gerrit.server.account.GroupControl;
import com.google.gerrit.server.account.GroupDetailFactory; import com.google.gerrit.server.account.GroupDetailFactory;
import com.google.gerrit.server.account.GroupIncludeCacheImpl; import com.google.gerrit.server.account.GroupIncludeCacheImpl;
import com.google.gerrit.server.account.GroupInfoCacheFactory; import com.google.gerrit.server.account.GroupInfoCacheFactory;
import com.google.gerrit.server.account.GroupMembers;
import com.google.gerrit.server.account.IncludingGroupMembership; import com.google.gerrit.server.account.IncludingGroupMembership;
import com.google.gerrit.server.account.InternalGroupBackend; import com.google.gerrit.server.account.InternalGroupBackend;
import com.google.gerrit.server.account.PerformCreateGroup; import com.google.gerrit.server.account.PerformCreateGroup;
@ -174,6 +175,7 @@ public class GerritGlobalModule extends FactoryModule {
factory(CreateChangeSender.Factory.class); factory(CreateChangeSender.Factory.class);
factory(GroupDetailFactory.Factory.class); factory(GroupDetailFactory.Factory.class);
factory(GroupInfoCacheFactory.Factory.class); factory(GroupInfoCacheFactory.Factory.class);
factory(GroupMembers.Factory.class);
factory(InternalUser.Factory.class); factory(InternalUser.Factory.class);
factory(MergedSender.Factory.class); factory(MergedSender.Factory.class);
factory(MergeFailSender.Factory.class); factory(MergeFailSender.Factory.class);

View File

@ -19,7 +19,6 @@ import static com.google.inject.Scopes.SINGLETON;
import com.google.gerrit.server.ApprovalsUtil; import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.RequestCleanup; import com.google.gerrit.server.RequestCleanup;
import com.google.gerrit.server.account.GroupMembers;
import com.google.gerrit.server.changedetail.DeleteDraftPatchSet; import com.google.gerrit.server.changedetail.DeleteDraftPatchSet;
import com.google.gerrit.server.changedetail.PublishDraft; import com.google.gerrit.server.changedetail.PublishDraft;
import com.google.gerrit.server.git.AsyncReceiveCommits; import com.google.gerrit.server.git.AsyncReceiveCommits;
@ -61,7 +60,6 @@ public class GerritRequestModule extends FactoryModule {
factory(DeleteDraftPatchSet.Factory.class); factory(DeleteDraftPatchSet.Factory.class);
factory(PublishDraft.Factory.class); factory(PublishDraft.Factory.class);
factory(RemoveReviewer.Factory.class); factory(RemoveReviewer.Factory.class);
factory(GroupMembers.Factory.class);
factory(CreateProject.Factory.class); factory(CreateProject.Factory.class);
factory(SuggestParentCandidates.Factory.class); factory(SuggestParentCandidates.Factory.class);
factory(BanCommit.Factory.class); factory(BanCommit.Factory.class);

View File

@ -129,8 +129,8 @@ public class AddReviewer implements Callable<ReviewerResult> {
continue; continue;
} }
final Set<Account> members = final Set<Account> members = groupMembersFactory.create(currentUser)
groupMembersFactory.create().listAccounts(group.getGroupUUID(), .listAccounts(group.getGroupUUID(),
control.getProject().getNameKey()); control.getProject().getNameKey());
if (members == null || members.size() == 0) { if (members == null || members.size() == 0) {
result.addError(new ReviewerResult.Error( result.addError(new ReviewerResult.Error(