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:
Adrian Görler
2014-08-29 09:17:04 +02:00
parent a85e64d411
commit f06e9e20d9
2 changed files with 16 additions and 12 deletions

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.project;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
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.server.CurrentUser;
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.SitePaths;
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
* be an owner of this project, or one of its parent projects..
* @return all {@link AccountGroup}'s that are allowed to administrate the
* 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) {
return Iterables.any(tree(), new Predicate<ProjectState>() {
@Override
public boolean apply(ProjectState in) {
return groups.containsAnyOf(in.localOwners);
}
});
public Set<AccountGroup.UUID> getAllOwners() {
Set<AccountGroup.UUID> result = new HashSet<>();
for (ProjectState p : tree()) {
result.addAll(p.localOwners);
}
return result;
}
public ProjectControl controlFor(final CurrentUser user) {