Make project and ref for each PermissionRule available to RefControl

This information is important to be able to allow ALLOW rules to
override BLOCK rules if they are defined on the same project. This
will be implemented in a follow-up change.

Change-Id: If22c1f0f8e13735e2e1e6e868e82b0d3617ef616
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
This commit is contained in:
Sasa Zivkov
2013-02-04 14:45:41 +01:00
parent d589f463e3
commit 272275343c
4 changed files with 89 additions and 22 deletions

View File

@@ -16,10 +16,13 @@ package com.google.gerrit.server.project;
import static com.google.gerrit.server.project.RefControl.isRE;
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.Permission;
import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -73,7 +76,7 @@ public class PermissionCollection {
}
boolean perUser = false;
List<AccessSection> sections = new ArrayList<AccessSection>();
Map<AccessSection, Project.NameKey> sectionToProject = Maps.newLinkedHashMap();
for (SectionMatcher matcher : matcherList) {
// If the matcher has to expand parameters and its prefix matches the
// reference there is a very good chance the reference is actually user
@@ -93,9 +96,10 @@ public class PermissionCollection {
}
if (matcher.match(ref, username)) {
sections.add(matcher.section);
sectionToProject.put(matcher.section, matcher.project);
}
}
List<AccessSection> sections = Lists.newArrayList(sectionToProject.keySet());
sorter.sort(ref, sections);
Set<SeenRule> seen = new HashSet<SeenRule>();
@@ -104,7 +108,9 @@ public class PermissionCollection {
HashMap<String, List<PermissionRule>> permissions =
new HashMap<String, List<PermissionRule>>();
Map<PermissionRule, ProjectRef> ruleProps = Maps.newIdentityHashMap();
for (AccessSection section : sections) {
Project.NameKey project = sectionToProject.get(section);
for (Permission permission : section.getPermissions()) {
boolean exclusivePermissionExists =
exclusiveGroupPermissions.contains(permission.getName());
@@ -124,6 +130,7 @@ public class PermissionCollection {
permissions.put(permission.getName(), r);
}
r.add(rule);
ruleProps.put(rule, new ProjectRef(project, section.getName()));
}
}
@@ -133,16 +140,20 @@ public class PermissionCollection {
}
}
return new PermissionCollection(permissions, perUser ? username : null);
return new PermissionCollection(permissions, ruleProps,
perUser ? username : null);
}
}
private final Map<String, List<PermissionRule>> rules;
private final Map<PermissionRule, ProjectRef> ruleProps;
private final String username;
private PermissionCollection(Map<String, List<PermissionRule>> rules,
Map<PermissionRule, ProjectRef> ruleProps,
String username) {
this.rules = rules;
this.ruleProps = ruleProps;
this.username = username;
}
@@ -167,6 +178,10 @@ public class PermissionCollection {
return r != null ? r : Collections.<PermissionRule> emptyList();
}
ProjectRef getRuleProps(PermissionRule rule) {
return ruleProps.get(rule);
}
/**
* Obtain all declared permission rules that match the reference.
*