From d3864994383a8b001a9ec8cccb896341cbaf0204 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Thu, 14 Feb 2013 08:23:42 -0800 Subject: [PATCH] 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 --- .../gerrit/httpd/rpc/BaseServiceImplementation.java | 4 ++++ .../com/google/gerrit/httpd/rpc/SuggestServiceImpl.java | 4 ++-- .../com/google/gerrit/server/account/GroupMembers.java | 9 +++++---- .../google/gerrit/server/config/GerritGlobalModule.java | 2 ++ .../google/gerrit/server/config/GerritRequestModule.java | 2 -- .../java/com/google/gerrit/server/patch/AddReviewer.java | 4 ++-- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/BaseServiceImplementation.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/BaseServiceImplementation.java index 62506f0431..b124824445 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/BaseServiceImplementation.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/BaseServiceImplementation.java @@ -48,6 +48,10 @@ public class BaseServiceImplementation { return null; } + protected CurrentUser getCurrentUser() { + return currentUser.get(); + } + /** * Executes action.run with an active ReviewDb connection. *

diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java index 1bde0daeb3..72cd3ccd8c 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java @@ -278,8 +278,8 @@ class SuggestServiceImpl extends BaseServiceImplementation implements } try { - final Set members = - groupMembersFactory.create().listAccounts(group.getUUID(), project); + final Set members = groupMembersFactory.create(getCurrentUser()) + .listAccounts(group.getUUID(), project); if (members.isEmpty()) { return false; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/GroupMembers.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/GroupMembers.java index 99ac5df650..08cf1a7983 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/account/GroupMembers.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/GroupMembers.java @@ -21,11 +21,12 @@ import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid; import com.google.gerrit.reviewdb.client.AccountGroupMember; 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.ProjectControl; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; import java.util.Collections; import java.util.HashSet; @@ -33,21 +34,21 @@ import java.util.Set; public class GroupMembers { public interface Factory { - GroupMembers create(); + GroupMembers create(CurrentUser currentUser); } private final GroupCache groupCache; private final GroupDetailFactory.Factory groupDetailFactory; private final AccountCache accountCache; private final ProjectControl.GenericFactory projectControl; - private final IdentifiedUser currentUser; + private final CurrentUser currentUser; @Inject GroupMembers(final GroupCache groupCache, final GroupDetailFactory.Factory groupDetailFactory, final AccountCache accountCache, final ProjectControl.GenericFactory projectControl, - final IdentifiedUser currentUser) { + @Assisted final CurrentUser currentUser) { this.groupCache = groupCache; this.groupDetailFactory = groupDetailFactory; this.accountCache = accountCache; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritGlobalModule.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritGlobalModule.java index 3a6d2db0da..4abe96ad19 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritGlobalModule.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritGlobalModule.java @@ -51,6 +51,7 @@ import com.google.gerrit.server.account.GroupControl; import com.google.gerrit.server.account.GroupDetailFactory; import com.google.gerrit.server.account.GroupIncludeCacheImpl; 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.InternalGroupBackend; import com.google.gerrit.server.account.PerformCreateGroup; @@ -174,6 +175,7 @@ public class GerritGlobalModule extends FactoryModule { factory(CreateChangeSender.Factory.class); factory(GroupDetailFactory.Factory.class); factory(GroupInfoCacheFactory.Factory.class); + factory(GroupMembers.Factory.class); factory(InternalUser.Factory.class); factory(MergedSender.Factory.class); factory(MergeFailSender.Factory.class); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java index 48e22ffe03..f4254cf62a 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java @@ -19,7 +19,6 @@ import static com.google.inject.Scopes.SINGLETON; import com.google.gerrit.server.ApprovalsUtil; import com.google.gerrit.server.IdentifiedUser; 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.PublishDraft; import com.google.gerrit.server.git.AsyncReceiveCommits; @@ -61,7 +60,6 @@ public class GerritRequestModule extends FactoryModule { factory(DeleteDraftPatchSet.Factory.class); factory(PublishDraft.Factory.class); factory(RemoveReviewer.Factory.class); - factory(GroupMembers.Factory.class); factory(CreateProject.Factory.class); factory(SuggestParentCandidates.Factory.class); factory(BanCommit.Factory.class); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/patch/AddReviewer.java b/gerrit-server/src/main/java/com/google/gerrit/server/patch/AddReviewer.java index 53fd182fd4..707d3b9b1d 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/patch/AddReviewer.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/patch/AddReviewer.java @@ -129,8 +129,8 @@ public class AddReviewer implements Callable { continue; } - final Set members = - groupMembersFactory.create().listAccounts(group.getGroupUUID(), + final Set members = groupMembersFactory.create(currentUser) + .listAccounts(group.getGroupUUID(), control.getProject().getNameKey()); if (members == null || members.size() == 0) { result.addError(new ReviewerResult.Error(