Move the responsibility to check for project ownership to ProjectControl
The class ProjectControl is the level of abstraction that deals with a project in the context of a user. Hence the ownership check is more suitable here. Change-Id: I60b0cf9cc6c797dfa4ea8070fff6ffc0ac8526af
This commit is contained in:
@@ -35,6 +35,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
|||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.InternalUser;
|
import com.google.gerrit.server.InternalUser;
|
||||||
|
import com.google.gerrit.server.account.GroupMembership;
|
||||||
import com.google.gerrit.server.change.IncludedInResolver;
|
import com.google.gerrit.server.change.IncludedInResolver;
|
||||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||||
import com.google.gerrit.server.config.GitReceivePackGroups;
|
import com.google.gerrit.server.config.GitReceivePackGroups;
|
||||||
@@ -288,7 +289,8 @@ public class ProjectControl {
|
|||||||
|
|
||||||
private boolean isDeclaredOwner() {
|
private boolean isDeclaredOwner() {
|
||||||
if (declaredOwner == null) {
|
if (declaredOwner == null) {
|
||||||
declaredOwner = state.isOwner(user.getEffectiveGroups());
|
GroupMembership effectiveGroups = user.getEffectiveGroups();
|
||||||
|
declaredOwner = effectiveGroups.containsAnyOf(state.getAllOwners());
|
||||||
}
|
}
|
||||||
return declaredOwner;
|
return declaredOwner;
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,6 @@ package com.google.gerrit.server.project;
|
|||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -37,7 +36,6 @@ import com.google.gerrit.rules.PrologEnvironment;
|
|||||||
import com.google.gerrit.rules.RulesCache;
|
import com.google.gerrit.rules.RulesCache;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.account.CapabilityCollection;
|
import com.google.gerrit.server.account.CapabilityCollection;
|
||||||
import com.google.gerrit.server.account.GroupMembership;
|
|
||||||
import com.google.gerrit.server.config.AllProjectsName;
|
import com.google.gerrit.server.config.AllProjectsName;
|
||||||
import com.google.gerrit.server.config.SitePaths;
|
import com.google.gerrit.server.config.SitePaths;
|
||||||
import com.google.gerrit.server.git.BranchOrderSection;
|
import com.google.gerrit.server.git.BranchOrderSection;
|
||||||
@@ -313,16 +311,20 @@ public class ProjectState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if any of the groups listed in {@code groups} was declared to
|
* @return all {@link AccountGroup}'s that are allowed to administrate the
|
||||||
* be an owner of this project, or one of its parent projects..
|
* complete project. This includes all groups to which the owner
|
||||||
|
* privilege for 'refs/*' is assigned for this project (the local
|
||||||
|
* owners) and all groups to which the owner privilege for 'refs/*' is
|
||||||
|
* assigned for one of the parent projects (the inherited owners).
|
||||||
*/
|
*/
|
||||||
boolean isOwner(final GroupMembership groups) {
|
public Set<AccountGroup.UUID> getAllOwners() {
|
||||||
return Iterables.any(tree(), new Predicate<ProjectState>() {
|
Set<AccountGroup.UUID> result = new HashSet<>();
|
||||||
@Override
|
|
||||||
public boolean apply(ProjectState in) {
|
for (ProjectState p : tree()) {
|
||||||
return groups.containsAnyOf(in.localOwners);
|
result.addAll(p.localOwners);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectControl controlFor(final CurrentUser user) {
|
public ProjectControl controlFor(final CurrentUser user) {
|
||||||
|
Reference in New Issue
Block a user