Search in sources :

Example 21 with Permission

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

the class AbstractQueryChangesTest method grant.

protected void grant(Project.NameKey project, String ref, String permission, boolean force, AccountGroup.UUID groupUUID) throws RepositoryNotFoundException, IOException, ConfigInvalidException {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
        md.setMessage(String.format("Grant %s on %s", permission, ref));
        ProjectConfig config = projectConfigFactory.read(md);
        config.upsertAccessSection(ref, s -> {
            Permission.Builder p = s.upsertPermission(permission);
            PermissionRule.Builder rule = PermissionRule.builder(GroupReference.create(groupUUID, groupUUID.get())).setForce(force);
            p.add(rule);
        });
        config.commit(md);
        projectCache.evictAndReindex(config.getProject());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) PermissionRule(com.google.gerrit.entities.PermissionRule) Permission(com.google.gerrit.entities.Permission) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Aggregations

Permission (com.google.gerrit.entities.Permission)21 AccessSection (com.google.gerrit.entities.AccessSection)16 PermissionRule (com.google.gerrit.entities.PermissionRule)9 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)4 List (java.util.List)4 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)4 ImmutableList (com.google.common.collect.ImmutableList)3 Sets (com.google.common.collect.Sets)3 FluentLogger (com.google.common.flogger.FluentLogger)3 AccountGroup (com.google.gerrit.entities.AccountGroup)3 GroupReference (com.google.gerrit.entities.GroupReference)3 CoreOrPluginProjectPermission (com.google.gerrit.extensions.api.access.CoreOrPluginProjectPermission)3 PluginProjectPermission (com.google.gerrit.extensions.api.access.PluginProjectPermission)3 Repository (org.eclipse.jgit.lib.Repository)3 Test (org.junit.Test)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2