Allow setting label types in project.config
Project owners can add a label.Label-Name section with keys corresponding to the existing columns in the ApprovalCategory table: [label "My-Label"] id = MLBL abbreviation = L function = MaxNoBlock copyMinScore = true value = -1 Negative label value value = 0 Neutral label value value = +1 Positive label value. Providing a label in a child project overrides all configuration and values for that label in parent projects or in the global DB. Labels with no values are treated as nonexistent. Thus child projects can disable labels defined in parent projects by adding an empty section for that label in the child project.config. Labels are ordered in the order they appear walking from parent to child projects, with labels in the database ordered first. Overriding a label's configuration does not change its ordering. Adding a label does not imply adding any permissions, so initially new labels will not be votable. Once a label is added, it will show up in permission dropdowns in the project access editor, so owners can add permissions through the web UI. This applies equally to labels produced dynamically from Prolog rules: to make such labels votable, a project owner needs to define label values and permissions for those labels. Since the owner will be editing rules.pl in refs/meta/config anyway, it should be convenient enough to also modify project.config in the same commit. Change-Id: I94d041236d53b1fdcd45a19806df1fb605588ff2
This commit is contained in:
@@ -18,8 +18,10 @@ import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
@@ -51,6 +53,7 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/** Cached information on a project. */
|
||||
@@ -66,7 +69,7 @@ public class ProjectState {
|
||||
private final PrologEnvironment.Factory envFactory;
|
||||
private final GitRepositoryManager gitMgr;
|
||||
private final RulesCache rulesCache;
|
||||
private final LabelTypes labelTypes;
|
||||
private final LabelTypes dbLabelTypes;
|
||||
|
||||
private final ProjectConfig config;
|
||||
private final Set<AccountGroup.UUID> localOwners;
|
||||
@@ -104,7 +107,7 @@ public class ProjectState {
|
||||
this.capabilities = isAllProjects
|
||||
? new CapabilityCollection(config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES))
|
||||
: null;
|
||||
this.labelTypes = labelTypes;
|
||||
this.dbLabelTypes = labelTypes;
|
||||
|
||||
if (isAllProjects && !Permission.canBeOnAllProjects(AccessSection.ALL, Permission.OWNER)) {
|
||||
localOwners = Collections.emptySet();
|
||||
@@ -342,7 +345,24 @@ public class ProjectState {
|
||||
}
|
||||
|
||||
public LabelTypes getLabelTypes() {
|
||||
return labelTypes;
|
||||
Map<String, LabelType> types = Maps.newLinkedHashMap();
|
||||
for (LabelType type : dbLabelTypes.getLabelTypes()) {
|
||||
types.put(type.getName(), type);
|
||||
}
|
||||
List<ProjectState> projects = Lists.newArrayList(tree());
|
||||
Collections.reverse(projects);
|
||||
for (ProjectState s : projects) {
|
||||
for (LabelType type : s.getConfig().getLabelSections()) {
|
||||
types.put(type.getName(), type);
|
||||
}
|
||||
}
|
||||
List<LabelType> all = Lists.newArrayListWithCapacity(types.size());
|
||||
for (LabelType type : types.values()) {
|
||||
if (!type.getValues().isEmpty()) {
|
||||
all.add(type);
|
||||
}
|
||||
}
|
||||
return new LabelTypes(Collections.unmodifiableList(all));
|
||||
}
|
||||
|
||||
private boolean getInheritableBoolean(Function<Project, InheritableBoolean> func) {
|
||||
|
Reference in New Issue
Block a user