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:
parent
9bdb1bee26
commit
d386499438
@ -48,6 +48,10 @@ public class BaseServiceImplementation {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected CurrentUser getCurrentUser() {
|
||||
return currentUser.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes <code>action.run</code> with an active ReviewDb connection.
|
||||
* <p>
|
||||
|
@ -278,8 +278,8 @@ class SuggestServiceImpl extends BaseServiceImplementation implements
|
||||
}
|
||||
|
||||
try {
|
||||
final Set<Account> members =
|
||||
groupMembersFactory.create().listAccounts(group.getUUID(), project);
|
||||
final Set<Account> members = groupMembersFactory.create(getCurrentUser())
|
||||
.listAccounts(group.getUUID(), project);
|
||||
|
||||
if (members.isEmpty()) {
|
||||
return false;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -129,8 +129,8 @@ public class AddReviewer implements Callable<ReviewerResult> {
|
||||
continue;
|
||||
}
|
||||
|
||||
final Set<Account> members =
|
||||
groupMembersFactory.create().listAccounts(group.getGroupUUID(),
|
||||
final Set<Account> members = groupMembersFactory.create(currentUser)
|
||||
.listAccounts(group.getGroupUUID(),
|
||||
control.getProject().getNameKey());
|
||||
if (members == null || members.size() == 0) {
|
||||
result.addError(new ReviewerResult.Error(
|
||||
|
Loading…
Reference in New Issue
Block a user