Access LabelTypes through ProjectState rather than globally

We want to allow projects to define their own labels, so we can't
assume the label list is global. In typical cases, we can access it
through a ProjectControl, ChangeControl, or related factory. This does
result in a few more places where we propagate
NoSuchProject/ChangeExceptions where there were none before. This is
intended: operations that query/modify labels on, say, a bare
Change.Id now do need to verify that the project/change exists.

For now, leave code in LabelTypesProvider, but try not to inject
LabelTypes where at all possible.

Change-Id: I4936ccafdb41848aaac3e335adf4648369d6abbc
This commit is contained in:
Dave Borowitz
2013-02-14 17:11:25 -08:00
parent 742a046fd0
commit 6cae753a4c
32 changed files with 212 additions and 156 deletions

View File

@@ -20,6 +20,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.gerrit.common.data.AccessSection;
import com.google.gerrit.common.data.GroupReference;
import com.google.gerrit.common.data.LabelTypes;
import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.reviewdb.client.AccountGroup;
@@ -65,6 +66,7 @@ public class ProjectState {
private final PrologEnvironment.Factory envFactory;
private final GitRepositoryManager gitMgr;
private final RulesCache rulesCache;
private final LabelTypes labelTypes;
private final ProjectConfig config;
private final Set<AccountGroup.UUID> localOwners;
@@ -89,6 +91,7 @@ public class ProjectState {
final PrologEnvironment.Factory envFactory,
final GitRepositoryManager gitMgr,
final RulesCache rulesCache,
final LabelTypes labelTypes,
@Assisted final ProjectConfig config) {
this.projectCache = projectCache;
this.isAllProjects = config.getProject().getNameKey().equals(allProjectsName);
@@ -101,6 +104,7 @@ public class ProjectState {
this.capabilities = isAllProjects
? new CapabilityCollection(config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES))
: null;
this.labelTypes = labelTypes;
if (isAllProjects && !Permission.canBeOnAllProjects(AccessSection.ALL, Permission.OWNER)) {
localOwners = Collections.emptySet();
@@ -337,6 +341,10 @@ public class ProjectState {
});
}
public LabelTypes getLabelTypes() {
return labelTypes;
}
private boolean getInheritableBoolean(Function<Project, InheritableBoolean> func) {
for (ProjectState s : tree()) {
switch (func.apply(s.getProject())) {