Search in sources :

Example 6 with Permission

use of com.google.gerrit.common.data.Permission in project gerrit by GerritCodeReview.

the class ProjectControl method allRefPatterns.

private Set<String> allRefPatterns(String permissionName) {
    Set<String> all = new HashSet<>();
    for (SectionMatcher matcher : access()) {
        AccessSection section = matcher.section;
        Permission permission = section.getPermission(permissionName);
        if (permission != null) {
            all.add(section.getName());
        }
    }
    return all;
}
Also used : Permission(com.google.gerrit.common.data.Permission) ProjectPermission(com.google.gerrit.server.permissions.ProjectPermission) AccessSection(com.google.gerrit.common.data.AccessSection) HashSet(java.util.HashSet)

Example 7 with Permission

use of com.google.gerrit.common.data.Permission in project gerrit by GerritCodeReview.

the class ProjectControl method canPerformOnAnyRef.

private boolean canPerformOnAnyRef(String permissionName) {
    for (SectionMatcher matcher : access()) {
        AccessSection section = matcher.section;
        Permission permission = section.getPermission(permissionName);
        if (permission == null) {
            continue;
        }
        for (PermissionRule rule : permission.getRules()) {
            if (rule.isBlock() || rule.isDeny() || !match(rule)) {
                continue;
            }
            //
            if (controlForRef(section.getName()).canPerform(permissionName)) {
                return true;
            }
            break;
        }
    }
    return false;
}
Also used : PermissionRule(com.google.gerrit.common.data.PermissionRule) Permission(com.google.gerrit.common.data.Permission) ProjectPermission(com.google.gerrit.server.permissions.ProjectPermission) AccessSection(com.google.gerrit.common.data.AccessSection)

Example 8 with Permission

use of com.google.gerrit.common.data.Permission in project gerrit by GerritCodeReview.

the class GetCommitIT method unblockRead.

private void unblockRead() throws Exception {
    ProjectConfig pc = projectCache.checkedGet(project).getConfig();
    pc.getAccessSection("refs/*").remove(new Permission(Permission.READ));
    saveProjectConfig(project, pc);
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Permission(com.google.gerrit.common.data.Permission)

Example 9 with Permission

use of com.google.gerrit.common.data.Permission in project gerrit by GerritCodeReview.

the class ProjectAccessHandler method replace.

private void replace(ProjectConfig config, Set<String> toDelete, AccessSection section) throws NoSuchGroupException {
    for (Permission permission : section.getPermissions()) {
        for (PermissionRule rule : permission.getRules()) {
            lookupGroup(rule);
        }
    }
    config.replace(section);
    toDelete.remove(section.getName());
}
Also used : PermissionRule(com.google.gerrit.common.data.PermissionRule) Permission(com.google.gerrit.common.data.Permission)

Example 10 with Permission

use of com.google.gerrit.common.data.Permission in project gerrit by GerritCodeReview.

the class ProjectConfigTest method readConfig.

@Test
public void readConfig() throws Exception {
    RevCommit rev = util.commit(//
    util.tree(//
    util.file("groups", util.blob(group(developers))), util.file("project.config", util.blob(//
    "" + //
    "[access \"refs/heads/*\"]\n" + //
    "  exclusiveGroupPermissions = read submit create\n" + //
    "  submit = group Developers\n" + //
    "  push = group Developers\n" + //
    "  read = group Developers\n" + //
    "[accounts]\n" + //
    "  sameGroupVisibility = deny group Developers\n" + //
    "  sameGroupVisibility = block group Staff\n" + //
    "[contributor-agreement \"Individual\"]\n" + //
    "  description = A simple description\n" + //
    "  accepted = group Developers\n" + //
    "  accepted = group Staff\n" + //
    "  autoVerify = group Developers\n" + //
    "  agreementUrl = http://www.example.com/agree\n"))));
    ProjectConfig cfg = read(rev);
    assertThat(cfg.getAccountsSection().getSameGroupVisibility()).hasSize(2);
    ContributorAgreement ca = cfg.getContributorAgreement("Individual");
    assertThat(ca.getName()).isEqualTo("Individual");
    assertThat(ca.getDescription()).isEqualTo("A simple description");
    assertThat(ca.getAgreementUrl()).isEqualTo("http://www.example.com/agree");
    assertThat(ca.getAccepted()).hasSize(2);
    assertThat(ca.getAccepted().get(0).getGroup()).isEqualTo(developers);
    assertThat(ca.getAccepted().get(1).getGroup().getName()).isEqualTo("Staff");
    assertThat(ca.getAutoVerify().getName()).isEqualTo("Developers");
    AccessSection section = cfg.getAccessSection("refs/heads/*");
    assertThat(section).isNotNull();
    assertThat(cfg.getAccessSection("refs/*")).isNull();
    Permission create = section.getPermission(Permission.CREATE);
    Permission submit = section.getPermission(Permission.SUBMIT);
    Permission read = section.getPermission(Permission.READ);
    Permission push = section.getPermission(Permission.PUSH);
    assertThat(create.getExclusiveGroup()).isTrue();
    assertThat(submit.getExclusiveGroup()).isTrue();
    assertThat(read.getExclusiveGroup()).isTrue();
    assertThat(push.getExclusiveGroup()).isFalse();
}
Also used : ContributorAgreement(com.google.gerrit.common.data.ContributorAgreement) Permission(com.google.gerrit.common.data.Permission) AccessSection(com.google.gerrit.common.data.AccessSection) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

Permission (com.google.gerrit.common.data.Permission)29 AccessSection (com.google.gerrit.common.data.AccessSection)19 PermissionRule (com.google.gerrit.common.data.PermissionRule)18 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)10 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)9 GroupReference (com.google.gerrit.common.data.GroupReference)6 Permission.isPermission (com.google.gerrit.common.data.Permission.isPermission)4 ProjectPermission (com.google.gerrit.server.permissions.ProjectPermission)4 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)4 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)3 Project (com.google.gerrit.reviewdb.client.Project)3 OrmException (com.google.gwtorm.server.OrmException)3 HashSet (java.util.HashSet)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 Test (org.junit.Test)3 ContributorAgreement (com.google.gerrit.common.data.ContributorAgreement)2 GroupDescription (com.google.gerrit.common.data.GroupDescription)2 LabelType (com.google.gerrit.common.data.LabelType)2 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)2 AccessSectionInfo (com.google.gerrit.extensions.api.access.AccessSectionInfo)2