Remove ProjectControl from the group stack
This is a step towards using PermissionBackend everywheren and make ProjectControl package-private. Change-Id: Ic9f9392c446382b227abb506c0f0ae292c08963b
This commit is contained in:
@@ -111,7 +111,7 @@ public class ReviewersUtil {
|
||||
private final AccountQueryBuilder accountQueryBuilder;
|
||||
private final Provider<AccountQueryProcessor> queryProvider;
|
||||
private final GroupBackend groupBackend;
|
||||
private final GroupMembers.Factory groupMembersFactory;
|
||||
private final GroupMembers groupMembers;
|
||||
private final Provider<CurrentUser> currentUser;
|
||||
private final ReviewerRecommender reviewerRecommender;
|
||||
private final Metrics metrics;
|
||||
@@ -122,7 +122,7 @@ public class ReviewersUtil {
|
||||
AccountQueryBuilder accountQueryBuilder,
|
||||
Provider<AccountQueryProcessor> queryProvider,
|
||||
GroupBackend groupBackend,
|
||||
GroupMembers.Factory groupMembersFactory,
|
||||
GroupMembers groupMembers,
|
||||
Provider<CurrentUser> currentUser,
|
||||
ReviewerRecommender reviewerRecommender,
|
||||
Metrics metrics) {
|
||||
@@ -133,7 +133,7 @@ public class ReviewersUtil {
|
||||
this.queryProvider = queryProvider;
|
||||
this.currentUser = currentUser;
|
||||
this.groupBackend = groupBackend;
|
||||
this.groupMembersFactory = groupMembersFactory;
|
||||
this.groupMembers = groupMembers;
|
||||
this.reviewerRecommender = reviewerRecommender;
|
||||
this.metrics = metrics;
|
||||
}
|
||||
@@ -303,10 +303,7 @@ public class ReviewersUtil {
|
||||
}
|
||||
|
||||
try {
|
||||
Set<Account> members =
|
||||
groupMembersFactory
|
||||
.create(currentUser.get())
|
||||
.listAccounts(group.getUUID(), project.getNameKey());
|
||||
Set<Account> members = groupMembers.listAccounts(group.getUUID(), project.getNameKey());
|
||||
|
||||
if (members.isEmpty()) {
|
||||
return result;
|
||||
|
||||
@@ -21,15 +21,14 @@ import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.group.InternalGroup;
|
||||
import com.google.gerrit.server.group.InternalGroupDescription;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -37,28 +36,22 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class GroupMembers {
|
||||
public interface Factory {
|
||||
GroupMembers create(CurrentUser currentUser);
|
||||
}
|
||||
|
||||
private final GroupCache groupCache;
|
||||
private final GroupControl.Factory groupControlFactory;
|
||||
private final AccountCache accountCache;
|
||||
private final ProjectControl.GenericFactory projectControl;
|
||||
private final CurrentUser currentUser;
|
||||
private final ProjectCache projectCache;
|
||||
|
||||
@Inject
|
||||
GroupMembers(
|
||||
GroupCache groupCache,
|
||||
GroupControl.Factory groupControlFactory,
|
||||
AccountCache accountCache,
|
||||
ProjectControl.GenericFactory projectControl,
|
||||
@Assisted CurrentUser currentUser) {
|
||||
ProjectCache projectCache) {
|
||||
this.groupCache = groupCache;
|
||||
this.groupControlFactory = groupControlFactory;
|
||||
this.accountCache = accountCache;
|
||||
this.projectControl = projectControl;
|
||||
this.currentUser = currentUser;
|
||||
this.projectCache = projectCache;
|
||||
}
|
||||
|
||||
public Set<Account> listAccounts(AccountGroup.UUID groupUUID, Project.NameKey project)
|
||||
@@ -88,11 +81,13 @@ public class GroupMembers {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
final Iterable<AccountGroup.UUID> ownerGroups =
|
||||
projectControl.controlFor(project, currentUser).getProjectState().getAllOwners();
|
||||
ProjectState projectState = projectCache.checkedGet(project);
|
||||
if (projectState == null) {
|
||||
throw new NoSuchProjectException(project);
|
||||
}
|
||||
|
||||
final HashSet<Account> projectOwners = new HashSet<>();
|
||||
for (AccountGroup.UUID ownerGroup : ownerGroups) {
|
||||
for (AccountGroup.UUID ownerGroup : projectState.getAllOwners()) {
|
||||
if (!seen.contains(ownerGroup)) {
|
||||
projectOwners.addAll(listAccounts(ownerGroup, project, seen));
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import com.google.gerrit.server.group.ListGroups;
|
||||
import com.google.gerrit.server.group.QueryGroups;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
import com.google.gerrit.server.project.ProjectResource;
|
||||
import com.google.gerrit.server.project.ProjectsCollection;
|
||||
import com.google.inject.Inject;
|
||||
@@ -54,7 +53,6 @@ class GroupsImpl implements Groups {
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final CreateGroup.Factory createGroup;
|
||||
private final GroupApiImpl.Factory api;
|
||||
private final ProjectControl.GenericFactory projectControlFactory;
|
||||
|
||||
@Inject
|
||||
GroupsImpl(
|
||||
@@ -66,8 +64,7 @@ class GroupsImpl implements Groups {
|
||||
Provider<CurrentUser> user,
|
||||
PermissionBackend permissionBackend,
|
||||
CreateGroup.Factory createGroup,
|
||||
GroupApiImpl.Factory api,
|
||||
ProjectControl.GenericFactory projectControlFactory) {
|
||||
GroupApiImpl.Factory api) {
|
||||
this.accounts = accounts;
|
||||
this.groups = groups;
|
||||
this.projects = projects;
|
||||
@@ -77,7 +74,6 @@ class GroupsImpl implements Groups {
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.createGroup = createGroup;
|
||||
this.api = api;
|
||||
this.projectControlFactory = projectControlFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,7 +121,7 @@ class GroupsImpl implements Groups {
|
||||
for (String project : req.getProjects()) {
|
||||
try {
|
||||
ProjectResource rsrc = projects.parse(tlr, IdString.fromDecoded(project));
|
||||
list.addProject(projectControlFactory.controlFor(rsrc.getNameKey(), rsrc.getUser()));
|
||||
list.addProject(rsrc.getProjectState());
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Error looking up project " + project, e);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class PostReviewers
|
||||
private final PermissionBackend permissionBackend;
|
||||
|
||||
private final GroupsCollection groupsCollection;
|
||||
private final GroupMembers.Factory groupMembersFactory;
|
||||
private final GroupMembers groupMembers;
|
||||
private final AccountLoader.Factory accountLoaderFactory;
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final ChangeData.Factory changeDataFactory;
|
||||
@@ -111,7 +111,7 @@ public class PostReviewers
|
||||
ReviewerResource.Factory reviewerFactory,
|
||||
PermissionBackend permissionBackend,
|
||||
GroupsCollection groupsCollection,
|
||||
GroupMembers.Factory groupMembersFactory,
|
||||
GroupMembers groupMembers,
|
||||
AccountLoader.Factory accountLoaderFactory,
|
||||
Provider<ReviewDb> db,
|
||||
ChangeData.Factory changeDataFactory,
|
||||
@@ -130,7 +130,7 @@ public class PostReviewers
|
||||
this.reviewerFactory = reviewerFactory;
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.groupsCollection = groupsCollection;
|
||||
this.groupMembersFactory = groupMembersFactory;
|
||||
this.groupMembers = groupMembers;
|
||||
this.accountLoaderFactory = accountLoaderFactory;
|
||||
this.dbProvider = db;
|
||||
this.changeDataFactory = changeDataFactory;
|
||||
@@ -287,10 +287,7 @@ public class PostReviewers
|
||||
Set<Account.Id> reviewers = new HashSet<>();
|
||||
Set<Account> members;
|
||||
try {
|
||||
members =
|
||||
groupMembersFactory
|
||||
.create(rsrc.getUser())
|
||||
.listAccounts(group.getGroupUUID(), rsrc.getProject());
|
||||
members = groupMembers.listAccounts(group.getGroupUUID(), rsrc.getProject());
|
||||
} catch (NoSuchGroupException e) {
|
||||
return fail(
|
||||
reviewer,
|
||||
|
||||
@@ -91,7 +91,6 @@ import com.google.gerrit.server.account.EmailExpander;
|
||||
import com.google.gerrit.server.account.GroupCacheImpl;
|
||||
import com.google.gerrit.server.account.GroupControl;
|
||||
import com.google.gerrit.server.account.GroupIncludeCacheImpl;
|
||||
import com.google.gerrit.server.account.GroupMembers;
|
||||
import com.google.gerrit.server.account.VersionedAuthorizedKeys;
|
||||
import com.google.gerrit.server.account.externalids.ExternalIdModule;
|
||||
import com.google.gerrit.server.api.accounts.AccountExternalIdCreator;
|
||||
@@ -250,7 +249,6 @@ public class GerritGlobalModule extends FactoryModule {
|
||||
factory(ChangeData.AssistedFactory.class);
|
||||
factory(ChangeJson.AssistedFactory.class);
|
||||
factory(CreateChangeSender.Factory.class);
|
||||
factory(GroupMembers.Factory.class);
|
||||
factory(EmailMerge.Factory.class);
|
||||
factory(MergedSender.Factory.class);
|
||||
factory(MergeUtil.Factory.class);
|
||||
|
||||
@@ -67,7 +67,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
|
||||
protected final GroupCache groupCache;
|
||||
|
||||
private final List<ProjectControl> projects = new ArrayList<>();
|
||||
private final List<ProjectState> projects = new ArrayList<>();
|
||||
private final Set<AccountGroup.UUID> groupsToInspect = new HashSet<>();
|
||||
private final GroupControl.Factory groupControlFactory;
|
||||
private final GroupControl.GenericFactory genericGroupControlFactory;
|
||||
@@ -95,6 +95,10 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
usage = "projects for which the groups should be listed"
|
||||
)
|
||||
public void addProject(ProjectControl project) {
|
||||
addProject(project.getProjectState());
|
||||
}
|
||||
|
||||
public void addProject(ProjectState project) {
|
||||
projects.add(project);
|
||||
}
|
||||
|
||||
@@ -241,7 +245,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
return user;
|
||||
}
|
||||
|
||||
public List<ProjectControl> getProjects() {
|
||||
public List<ProjectState> getProjects() {
|
||||
return projects;
|
||||
}
|
||||
|
||||
@@ -298,7 +302,6 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
if (!projects.isEmpty()) {
|
||||
return projects
|
||||
.stream()
|
||||
.map(ProjectControl::getProjectState)
|
||||
.map(ProjectState::getAllGroups)
|
||||
.flatMap(Collection::stream)
|
||||
.map(GroupReference::getUUID)
|
||||
@@ -318,9 +321,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
List<GroupReference> groupRefs =
|
||||
Lists.newArrayList(
|
||||
Iterables.limit(
|
||||
groupBackend.suggest(
|
||||
suggest,
|
||||
projects.stream().findFirst().map(pc -> pc.getProjectState()).orElse(null)),
|
||||
groupBackend.suggest(suggest, projects.stream().findFirst().orElse(null)),
|
||||
limit <= 0 ? 10 : Math.min(limit, 10)));
|
||||
|
||||
List<GroupInfo> groupInfos = Lists.newArrayListWithCapacity(groupRefs.size());
|
||||
|
||||
Reference in New Issue
Block a user