Search in sources :

Example 16 with AccessSection

use of com.google.gerrit.entities.AccessSection in project gerrit by GerritCodeReview.

the class AccountIT method assertLabelPermission.

protected void assertLabelPermission(Project.NameKey project, GroupReference groupReference, String ref, boolean exclusive, String labelName, int min, int max) {
    Optional<AccessSection> accessSection = projectCache.get(project).orElseThrow(illegalState(project)).getConfig().getAccessSection(ref);
    assertThat(accessSection).isPresent();
    String permissionName = Permission.LABEL + labelName;
    Permission permission = accessSection.get().getPermission(permissionName);
    assertPermission(permission, permissionName, exclusive, labelName);
    assertPermissionRule(permission.getRule(groupReference), groupReference, Action.ALLOW, false, min, max);
}
Also used : Permission(com.google.gerrit.entities.Permission) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) AccessSection(com.google.gerrit.entities.AccessSection)

Example 17 with AccessSection

use of com.google.gerrit.entities.AccessSection in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method assertPermissions.

protected void assertPermissions(Project.NameKey project, GroupReference groupReference, String ref, boolean exclusive, String... permissionNames) {
    Optional<AccessSection> accessSection = projectCache.get(project).orElseThrow(illegalState(project)).getConfig().getAccessSection(ref);
    assertThat(accessSection).isPresent();
    for (String permissionName : permissionNames) {
        Permission permission = accessSection.get().getPermission(permissionName);
        assertPermission(permission, permissionName, exclusive, null);
        assertPermissionRule(permission.getRule(groupReference), groupReference, Action.ALLOW, false, 0, 0);
    }
}
Also used : Permission(com.google.gerrit.entities.Permission) IdString(com.google.gerrit.extensions.restapi.IdString) AccessSection(com.google.gerrit.entities.AccessSection)

Example 18 with AccessSection

use of com.google.gerrit.entities.AccessSection in project gerrit by GerritCodeReview.

the class ProjectControl method canPerformOnAnyRef.

private boolean canPerformOnAnyRef(String permissionName) {
    for (SectionMatcher matcher : access()) {
        AccessSection section = matcher.getSection();
        Permission permission = section.getPermission(permissionName);
        if (permission == null) {
            continue;
        }
        Boolean can = canPerform(permissionName, section, permission);
        if (can != null) {
            return can;
        }
    }
    return false;
}
Also used : Permission(com.google.gerrit.entities.Permission) CoreOrPluginProjectPermission(com.google.gerrit.extensions.api.access.CoreOrPluginProjectPermission) PluginProjectPermission(com.google.gerrit.extensions.api.access.PluginProjectPermission) SectionMatcher(com.google.gerrit.server.project.SectionMatcher) AccessSection(com.google.gerrit.entities.AccessSection)

Example 19 with AccessSection

use of com.google.gerrit.entities.AccessSection in project gerrit by GerritCodeReview.

the class ProjectControl method canPerformOnTagRef.

private boolean canPerformOnTagRef(String permissionName) {
    for (SectionMatcher matcher : access()) {
        AccessSection section = matcher.getSection();
        if (section.getName().startsWith(REFS_TAGS) || section.getName().startsWith(REGEX_PREFIX + REFS_TAGS)) {
            Permission permission = section.getPermission(permissionName);
            if (permission == null) {
                continue;
            }
            Boolean can = canPerform(permissionName, section, permission);
            if (can != null) {
                return can;
            }
        }
    }
    return false;
}
Also used : Permission(com.google.gerrit.entities.Permission) CoreOrPluginProjectPermission(com.google.gerrit.extensions.api.access.CoreOrPluginProjectPermission) PluginProjectPermission(com.google.gerrit.extensions.api.access.PluginProjectPermission) SectionMatcher(com.google.gerrit.server.project.SectionMatcher) AccessSection(com.google.gerrit.entities.AccessSection)

Example 20 with AccessSection

use of com.google.gerrit.entities.AccessSection in project gerrit by GerritCodeReview.

the class AccessIT method grantRevertPermissionOnlyWorksOnce.

@Test
public void grantRevertPermissionOnlyWorksOnce() throws Exception {
    grantRevertPermission.execute(newProjectName);
    grantRevertPermission.execute(newProjectName);
    try (Repository repo = repoManager.openRepository(newProjectName)) {
        MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, newProjectName, repo);
        ProjectConfig projectConfig = projectConfigFactory.read(md);
        AccessSection all = projectConfig.getAccessSection(AccessSection.ALL);
        Permission permission = all.getPermission(Permission.REVERT);
        assertThat(permission.getRules()).hasSize(1);
    }
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) GrantRevertPermission(com.google.gerrit.server.schema.GrantRevertPermission) Permission(com.google.gerrit.entities.Permission) AccessSection(com.google.gerrit.entities.AccessSection) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

AccessSection (com.google.gerrit.entities.AccessSection)22 Permission (com.google.gerrit.entities.Permission)16 PermissionRule (com.google.gerrit.entities.PermissionRule)7 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)6 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)4 Project (com.google.gerrit.entities.Project)3 InvalidNameException (com.google.gerrit.exceptions.InvalidNameException)3 CoreOrPluginProjectPermission (com.google.gerrit.extensions.api.access.CoreOrPluginProjectPermission)3 PluginProjectPermission (com.google.gerrit.extensions.api.access.PluginProjectPermission)3 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)3 SectionMatcher (com.google.gerrit.server.project.SectionMatcher)3 ImmutableList (com.google.common.collect.ImmutableList)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 GroupDescription (com.google.gerrit.entities.GroupDescription)2 GroupReference (com.google.gerrit.entities.GroupReference)2 LabelType (com.google.gerrit.entities.LabelType)2