use of com.google.gerrit.common.data.PermissionRange in project gerrit by GerritCodeReview.
the class CapabilityControl method toRange.
private static PermissionRange toRange(String permissionName, List<PermissionRule> ruleList) {
int min = 0;
int max = 0;
if (ruleList.isEmpty()) {
PermissionRange.WithDefaults defaultRange = GlobalCapability.getRange(permissionName);
if (defaultRange != null) {
min = defaultRange.getDefaultMin();
max = defaultRange.getDefaultMax();
}
} else {
for (PermissionRule rule : ruleList) {
min = Math.min(min, rule.getMin());
max = Math.max(max, rule.getMax());
}
}
return new PermissionRange(permissionName, min, max);
}
use of com.google.gerrit.common.data.PermissionRange in project gerrit by GerritCodeReview.
the class ApprovalsUtil method checkApprovals.
private static void checkApprovals(Map<String, Short> approvals, ChangeControl changeCtl) throws AuthException {
for (Map.Entry<String, Short> vote : approvals.entrySet()) {
String name = vote.getKey();
Short value = vote.getValue();
PermissionRange range = changeCtl.getRange(Permission.forLabel(name));
if (range == null || !range.contains(value)) {
throw new AuthException(String.format("applying label \"%s\": %d is restricted", name, value));
}
}
}
use of com.google.gerrit.common.data.PermissionRange in project gerrit by GerritCodeReview.
the class RefControlTest method unblockRange.
@Test
public void unblockRange() {
block(local, LABEL + "Code-Review", -1, +1, ANONYMOUS_USERS, "refs/heads/*");
allow(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
ProjectControl u = user(local, DEVS);
PermissionRange range = u.controlForRef("refs/heads/master").getRange(LABEL + "Code-Review");
assertCanVote(-2, range);
assertCanVote(2, range);
}
use of com.google.gerrit.common.data.PermissionRange in project gerrit by GerritCodeReview.
the class RefControlTest method blockLabelRange_ParentBlocksChild.
@Test
public void blockLabelRange_ParentBlocksChild() {
allow(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
block(parent, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
ProjectControl u = user(local, DEVS);
PermissionRange range = u.controlForRef("refs/heads/master").getRange(LABEL + "Code-Review");
assertCanVote(-1, range);
assertCanVote(1, range);
assertCannotVote(-2, range);
assertCannotVote(2, range);
}
use of com.google.gerrit.common.data.PermissionRange in project gerrit by GerritCodeReview.
the class RefControlTest method unblockRangeOnMoreSpecificRef_Fails.
@Test
public void unblockRangeOnMoreSpecificRef_Fails() {
block(local, LABEL + "Code-Review", -1, +1, ANONYMOUS_USERS, "refs/heads/*");
allow(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/master");
ProjectControl u = user(local, DEVS);
PermissionRange range = u.controlForRef("refs/heads/master").getRange(LABEL + "Code-Review");
assertCannotVote(-2, range);
assertCannotVote(2, range);
}
Aggregations