Search in sources :

Example 1 with PermissionRange

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);
}
Also used : PermissionRange(com.google.gerrit.common.data.PermissionRange) PermissionRule(com.google.gerrit.common.data.PermissionRule)

Example 2 with PermissionRange

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));
        }
    }
}
Also used : PermissionRange(com.google.gerrit.common.data.PermissionRange) AuthException(com.google.gerrit.extensions.restapi.AuthException) Map(java.util.Map)

Example 3 with PermissionRange

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);
}
Also used : PermissionRange(com.google.gerrit.common.data.PermissionRange) Test(org.junit.Test)

Example 4 with PermissionRange

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);
}
Also used : PermissionRange(com.google.gerrit.common.data.PermissionRange) Test(org.junit.Test)

Example 5 with PermissionRange

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);
}
Also used : PermissionRange(com.google.gerrit.common.data.PermissionRange) Test(org.junit.Test)

Aggregations

PermissionRange (com.google.gerrit.common.data.PermissionRange)14 Test (org.junit.Test)8 PermissionRule (com.google.gerrit.common.data.PermissionRule)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LabelType (com.google.gerrit.common.data.LabelType)1 LabelTypes (com.google.gerrit.common.data.LabelTypes)1 SubmitRecord (com.google.gerrit.common.data.SubmitRecord)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)1 LabelPermission (com.google.gerrit.server.permissions.LabelPermission)1 SubmitRuleEvaluator (com.google.gerrit.server.project.SubmitRuleEvaluator)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1