Search in sources :

Example 36 with ProjectConfig

use of com.google.gerrit.server.git.ProjectConfig in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method removePermission.

protected void removePermission(Project.NameKey project, String ref, String permission) throws IOException, ConfigInvalidException {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
        md.setMessage(String.format("Remove %s on %s", permission, ref));
        ProjectConfig config = ProjectConfig.read(md);
        AccessSection s = config.getAccessSection(ref, true);
        Permission p = s.getPermission(permission, true);
        p.getRules().clear();
        config.commit(md);
        projectCache.evict(config.getProject());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Permission(com.google.gerrit.common.data.Permission) AccessSection(com.google.gerrit.common.data.AccessSection) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 37 with ProjectConfig

use of com.google.gerrit.server.git.ProjectConfig in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method setUseContributorAgreements.

protected void setUseContributorAgreements(InheritableBoolean value) throws Exception {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
        ProjectConfig config = ProjectConfig.read(md);
        config.getProject().setUseContributorAgreements(value);
        config.commit(md);
        projectCache.evict(config.getProject());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 38 with ProjectConfig

use of com.google.gerrit.server.git.ProjectConfig in project gerrit by GerritCodeReview.

the class ChangeIT method checkLabelsForOpenChange.

@Test
public void checkLabelsForOpenChange() throws Exception {
    PushOneCommit.Result r = createChange();
    ChangeInfo change = gApi.changes().id(r.getChangeId()).get();
    assertThat(change.status).isEqualTo(ChangeStatus.NEW);
    assertThat(change.labels.keySet()).containsExactly("Code-Review");
    assertThat(change.permittedLabels.keySet()).containsExactly("Code-Review");
    // add new label and assert that it's returned for existing changes
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    LabelType verified = Util.verified();
    cfg.getLabelSections().put(verified.getName(), verified);
    AccountGroup.UUID registeredUsers = systemGroupBackend.getGroup(REGISTERED_USERS).getUUID();
    String heads = RefNames.REFS_HEADS + "*";
    Util.allow(cfg, Permission.forLabel(verified.getName()), -1, 1, registeredUsers, heads);
    saveProjectConfig(project, cfg);
    change = gApi.changes().id(r.getChangeId()).get();
    assertThat(change.labels.keySet()).containsExactly("Code-Review", "Verified");
    assertThat(change.permittedLabels.keySet()).containsExactly("Code-Review", "Verified");
    assertPermitted(change, "Code-Review", -2, -1, 0, 1, 2);
    assertPermitted(change, "Verified", -1, 0, 1);
    // add an approval on the new label
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(new ReviewInput().label(verified.getName(), verified.getMax().getValue()));
    // remove label and assert that it's no longer returned for existing
    // changes, even if there is an approval for it
    cfg.getLabelSections().remove(verified.getName());
    Util.remove(cfg, Permission.forLabel(verified.getName()), registeredUsers, heads);
    saveProjectConfig(project, cfg);
    change = gApi.changes().id(r.getChangeId()).get();
    assertThat(change.labels.keySet()).containsExactly("Code-Review");
    assertThat(change.permittedLabels.keySet()).containsExactly("Code-Review");
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) LabelType(com.google.gerrit.common.data.LabelType) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 39 with ProjectConfig

use of com.google.gerrit.server.git.ProjectConfig in project gerrit by GerritCodeReview.

the class AbstractPushForReview method setUp.

@Before
public void setUp() throws Exception {
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    patchSetLock = Util.patchSetLock();
    cfg.getLabelSections().put(patchSetLock.getName(), patchSetLock);
    AccountGroup.UUID anonymousUsers = systemGroupBackend.getGroup(ANONYMOUS_USERS).getUUID();
    Util.allow(cfg, Permission.forLabel(patchSetLock.getName()), 0, 1, anonymousUsers, "refs/heads/*");
    saveProjectConfig(cfg);
    grant(project, "refs/heads/*", Permission.LABEL + "Patch-Set-Lock");
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) Before(org.junit.Before)

Example 40 with ProjectConfig

use of com.google.gerrit.server.git.ProjectConfig in project gerrit by GerritCodeReview.

the class AbstractPushForReview method enableCreateNewChangeForAllNotInTarget.

private void enableCreateNewChangeForAllNotInTarget() throws Exception {
    ProjectConfig config = projectCache.checkedGet(project).getConfig();
    config.getProject().setCreateNewChangeForAllNotInTarget(InheritableBoolean.TRUE);
    saveProjectConfig(project, config);
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig)

Aggregations

ProjectConfig (com.google.gerrit.server.git.ProjectConfig)64 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)23 AccessSection (com.google.gerrit.common.data.AccessSection)15 Project (com.google.gerrit.reviewdb.client.Project)14 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)14 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)12 Permission (com.google.gerrit.common.data.Permission)10 PermissionRule (com.google.gerrit.common.data.PermissionRule)10 IOException (java.io.IOException)10 Repository (org.eclipse.jgit.lib.Repository)9 LabelType (com.google.gerrit.common.data.LabelType)8 Test (org.junit.Test)8 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)7 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)7 Before (org.junit.Before)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 GroupReference (com.google.gerrit.common.data.GroupReference)6 OrmException (com.google.gwtorm.server.OrmException)6 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)5 AuthException (com.google.gerrit.extensions.restapi.AuthException)4