Search in sources :

Example 1 with PermissionInfo

use of com.google.gerrit.extensions.api.access.PermissionInfo in project gerrit by GerritCodeReview.

the class AccessIT method createDefaultAccessSectionInfo.

private AccessSectionInfo createDefaultAccessSectionInfo() {
    AccessSectionInfo accessSection = newAccessSectionInfo();
    PermissionInfo push = newPermissionInfo();
    PermissionRuleInfo pri = new PermissionRuleInfo(PermissionRuleInfo.Action.ALLOW, false);
    push.rules.put(SystemGroupBackend.REGISTERED_USERS.get(), pri);
    accessSection.permissions.put(Permission.PUSH, push);
    PermissionInfo codeReview = newPermissionInfo();
    codeReview.label = LABEL_CODE_REVIEW;
    pri = new PermissionRuleInfo(PermissionRuleInfo.Action.DENY, false);
    codeReview.rules.put(SystemGroupBackend.REGISTERED_USERS.get(), pri);
    pri = new PermissionRuleInfo(PermissionRuleInfo.Action.ALLOW, false);
    pri.max = 1;
    pri.min = -1;
    codeReview.rules.put(SystemGroupBackend.PROJECT_OWNERS.get(), pri);
    accessSection.permissions.put(Permission.LABEL + LABEL_CODE_REVIEW, codeReview);
    return accessSection;
}
Also used : PermissionInfo(com.google.gerrit.extensions.api.access.PermissionInfo) PermissionRuleInfo(com.google.gerrit.extensions.api.access.PermissionRuleInfo) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo)

Example 2 with PermissionInfo

use of com.google.gerrit.extensions.api.access.PermissionInfo in project gerrit by GerritCodeReview.

the class AccessIT method createAccessSectionInfoDenyAll.

private AccessSectionInfo createAccessSectionInfoDenyAll() {
    AccessSectionInfo accessSection = newAccessSectionInfo();
    PermissionInfo read = newPermissionInfo();
    PermissionRuleInfo pri = new PermissionRuleInfo(PermissionRuleInfo.Action.DENY, false);
    read.rules.put(SystemGroupBackend.ANONYMOUS_USERS.get(), pri);
    accessSection.permissions.put(Permission.READ, read);
    return accessSection;
}
Also used : PermissionInfo(com.google.gerrit.extensions.api.access.PermissionInfo) PermissionRuleInfo(com.google.gerrit.extensions.api.access.PermissionRuleInfo) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo)

Example 3 with PermissionInfo

use of com.google.gerrit.extensions.api.access.PermissionInfo in project gerrit by GerritCodeReview.

the class AccessIT method removePermissionRule.

@Test
public void removePermissionRule() throws Exception {
    // Add initial permission set
    ProjectAccessInput accessInput = newProjectAccessInput();
    AccessSectionInfo accessSectionInfo = createDefaultAccessSectionInfo();
    accessInput.add.put(REFS_HEADS, accessSectionInfo);
    pApi.access(accessInput);
    // Remove specific permission rule
    AccessSectionInfo accessSectionToRemove = newAccessSectionInfo();
    PermissionInfo codeReview = newPermissionInfo();
    codeReview.label = LABEL_CODE_REVIEW;
    PermissionRuleInfo pri = new PermissionRuleInfo(PermissionRuleInfo.Action.DENY, false);
    codeReview.rules.put(SystemGroupBackend.REGISTERED_USERS.get(), pri);
    accessSectionToRemove.permissions.put(Permission.LABEL + LABEL_CODE_REVIEW, codeReview);
    ProjectAccessInput removal = newProjectAccessInput();
    removal.remove.put(REFS_HEADS, accessSectionToRemove);
    pApi.access(removal);
    // Remove locally
    accessInput.add.get(REFS_HEADS).permissions.get(Permission.LABEL + LABEL_CODE_REVIEW).rules.remove(SystemGroupBackend.REGISTERED_USERS.get());
    // Check
    assertThat(pApi.access().local).isEqualTo(accessInput.add);
}
Also used : PermissionInfo(com.google.gerrit.extensions.api.access.PermissionInfo) PermissionRuleInfo(com.google.gerrit.extensions.api.access.PermissionRuleInfo) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo) ProjectAccessInput(com.google.gerrit.extensions.api.access.ProjectAccessInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with PermissionInfo

use of com.google.gerrit.extensions.api.access.PermissionInfo in project gerrit by GerritCodeReview.

the class AccessIT method newPermissionInfo.

private PermissionInfo newPermissionInfo() {
    PermissionInfo p = new PermissionInfo(null, null);
    p.rules = new HashMap<>();
    return p;
}
Also used : PermissionInfo(com.google.gerrit.extensions.api.access.PermissionInfo)

Example 5 with PermissionInfo

use of com.google.gerrit.extensions.api.access.PermissionInfo in project gerrit by GerritCodeReview.

the class GetAccess method createAccessSection.

private AccessSectionInfo createAccessSection(AccessSection section) {
    AccessSectionInfo accessSectionInfo = new AccessSectionInfo();
    accessSectionInfo.permissions = new HashMap<>();
    for (Permission p : section.getPermissions()) {
        PermissionInfo pInfo = new PermissionInfo(p.getLabel(), p.getExclusiveGroup() ? true : null);
        pInfo.rules = new HashMap<>();
        for (PermissionRule r : p.getRules()) {
            PermissionRuleInfo info = new PermissionRuleInfo(ACTION_TYPE.get(r.getAction()), r.getForce());
            if (r.hasRange()) {
                info.max = r.getMax();
                info.min = r.getMin();
            }
            AccountGroup.UUID group = r.getGroup().getUUID();
            if (group != null) {
                pInfo.rules.put(group.get(), info);
            }
        }
        accessSectionInfo.permissions.put(p.getName(), pInfo);
    }
    return accessSectionInfo;
}
Also used : PermissionInfo(com.google.gerrit.extensions.api.access.PermissionInfo) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) PermissionRule(com.google.gerrit.common.data.PermissionRule) Permission(com.google.gerrit.common.data.Permission) PermissionRuleInfo(com.google.gerrit.extensions.api.access.PermissionRuleInfo) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo)

Aggregations

PermissionInfo (com.google.gerrit.extensions.api.access.PermissionInfo)10 AccessSectionInfo (com.google.gerrit.extensions.api.access.AccessSectionInfo)9 PermissionRuleInfo (com.google.gerrit.extensions.api.access.PermissionRuleInfo)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 ProjectAccessInput (com.google.gerrit.extensions.api.access.ProjectAccessInput)4 Test (org.junit.Test)4 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)3 Permission (com.google.gerrit.common.data.Permission)2 PermissionRule (com.google.gerrit.common.data.PermissionRule)2 AccessSection (com.google.gerrit.common.data.AccessSection)1 GroupDescription (com.google.gerrit.common.data.GroupDescription)1 ProjectAccessInfo (com.google.gerrit.extensions.api.access.ProjectAccessInfo)1 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)1 GlobalPermission (com.google.gerrit.server.permissions.GlobalPermission)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1