Search in sources :

Example 26 with AddReviewerInput

use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.

the class ReviewProjectAccess method addProjectOwnersAsReviewers.

private void addProjectOwnersAsReviewers(ChangeResource rsrc) {
    final String projectOwners = groupBackend.get(SystemGroupBackend.PROJECT_OWNERS).getName();
    try {
        AddReviewerInput input = new AddReviewerInput();
        input.reviewer = projectOwners;
        reviewersProvider.get().apply(rsrc, input);
    } catch (Exception e) {
        // one of the owner groups is not visible to the user and this it why it
        // can't be added as reviewer
        Throwables.throwIfUnchecked(e);
    }
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) OrmException(com.google.gwtorm.server.OrmException) UpdateException(com.google.gerrit.server.update.UpdateException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) IOException(java.io.IOException) PermissionDeniedException(com.google.gerrit.common.errors.PermissionDeniedException) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput)

Example 27 with AddReviewerInput

use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.

the class AccountIT method ignoreChange.

@Test
public void ignoreChange() throws Exception {
    TestAccount user2 = accounts.user2();
    accountIndexedCounter.clear();
    PushOneCommit.Result r = createChange();
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    in = new AddReviewerInput();
    in.reviewer = user2.email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    setApiUser(user);
    gApi.accounts().self().setStars(r.getChangeId(), new StarsInput(ImmutableSet.of(IGNORE_LABEL)));
    sender.clear();
    setApiUser(admin);
    gApi.changes().id(r.getChangeId()).abandon();
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    assertThat(messages.get(0).rcpt()).containsExactly(user2.emailAddress);
    accountIndexedCounter.assertNoReindex();
}
Also used : Message(com.google.gerrit.testutil.FakeEmailSender.Message) StarsInput(com.google.gerrit.extensions.api.changes.StarsInput) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 28 with AddReviewerInput

use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.

the class AccountIT method addReviewerToIgnoredChange.

@Test
public void addReviewerToIgnoredChange() throws Exception {
    PushOneCommit.Result r = createChange();
    setApiUser(user);
    gApi.accounts().self().setStars(r.getChangeId(), new StarsInput(ImmutableSet.of(IGNORE_LABEL)));
    sender.clear();
    setApiUser(admin);
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message message = messages.get(0);
    assertThat(message.rcpt()).containsExactly(user.emailAddress);
    assertMailReplyTo(message, admin.email);
    accountIndexedCounter.assertNoReindex();
}
Also used : Message(com.google.gerrit.testutil.FakeEmailSender.Message) StarsInput(com.google.gerrit.extensions.api.changes.StarsInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 29 with AddReviewerInput

use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.

the class ChangeIT method nonVotingReviewerStaysAfterSubmit.

@Test
public void nonVotingReviewerStaysAfterSubmit() throws Exception {
    LabelType verified = category("Verified", value(1, "Passes"), value(0, "No score"), value(-1, "Failed"));
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    cfg.getLabelSections().put(verified.getName(), verified);
    String heads = "refs/heads/*";
    AccountGroup.UUID owners = systemGroupBackend.getGroup(CHANGE_OWNER).getUUID();
    AccountGroup.UUID registered = systemGroupBackend.getGroup(REGISTERED_USERS).getUUID();
    Util.allow(cfg, Permission.forLabel(verified.getName()), -1, 1, owners, heads);
    Util.allow(cfg, Permission.forLabel("Code-Review"), -2, +2, registered, heads);
    saveProjectConfig(project, cfg);
    // Set Code-Review+2 and Verified+1 as admin (change owner)
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    String commit = r.getCommit().name();
    ReviewInput input = ReviewInput.approve();
    input.label(verified.getName(), 1);
    gApi.changes().id(changeId).revision(commit).review(input);
    // Reviewers should only be "admin"
    ChangeInfo c = gApi.changes().id(changeId).get();
    assertThat(getReviewers(c.reviewers.get(REVIEWER))).containsExactlyElementsIn(ImmutableSet.of(admin.getId()));
    assertThat(c.reviewers.get(CC)).isNull();
    // Add the user as reviewer
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(changeId).addReviewer(in);
    c = gApi.changes().id(changeId).get();
    assertThat(getReviewers(c.reviewers.get(REVIEWER))).containsExactlyElementsIn(ImmutableSet.of(admin.getId(), user.getId()));
    // Approve the change as user, then remove the approval
    // (only to confirm that the user does have Code-Review+2 permission)
    setApiUser(user);
    gApi.changes().id(changeId).revision(commit).review(ReviewInput.approve());
    gApi.changes().id(changeId).revision(commit).review(ReviewInput.noScore());
    // Submit the change
    setApiUser(admin);
    gApi.changes().id(changeId).revision(commit).submit();
    // User should still be on the change
    c = gApi.changes().id(changeId).get();
    assertThat(getReviewers(c.reviewers.get(REVIEWER))).containsExactlyElementsIn(ImmutableSet.of(admin.getId(), user.getId()));
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) LabelType(com.google.gerrit.common.data.LabelType) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 30 with AddReviewerInput

use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.

the class ChangeIT method addReviewerThatCannotSeeChange.

@Test
public void addReviewerThatCannotSeeChange() throws Exception {
    // create hidden project that is only visible to administrators
    Project.NameKey p = createProject("p");
    ProjectConfig cfg = projectCache.checkedGet(p).getConfig();
    Util.allow(cfg, Permission.READ, groupCache.get(new AccountGroup.NameKey("Administrators")).getGroupUUID(), "refs/*");
    Util.block(cfg, Permission.READ, REGISTERED_USERS, "refs/*");
    saveProjectConfig(p, cfg);
    // create change
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), repo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    // check the user cannot see the change
    setApiUser(user);
    try {
        gApi.changes().id(result.getChangeId()).get();
        fail("Expected ResourceNotFoundException");
    } catch (ResourceNotFoundException e) {
    // Expected.
    }
    // try to add user as reviewer
    setApiUser(admin);
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    AddReviewerResult r = gApi.changes().id(result.getChangeId()).addReviewer(in);
    assertThat(r.input).isEqualTo(user.email);
    assertThat(r.error).contains("does not have permission to see this change");
    assertThat(r.reviewers).isNull();
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AddReviewerResult(com.google.gerrit.extensions.api.changes.AddReviewerResult) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)45 Test (org.junit.Test)38 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)34 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)30 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)15 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)13 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)9 Message (com.google.gerrit.testutil.FakeEmailSender.Message)8 AddReviewerResult (com.google.gerrit.extensions.api.changes.AddReviewerResult)7 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)5 Change (com.google.gerrit.reviewdb.client.Change)5 TestAccount (com.google.gerrit.acceptance.TestAccount)4 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)4 Account (com.google.gerrit.reviewdb.client.Account)4 Project (com.google.gerrit.reviewdb.client.Project)4 Repo (com.google.gerrit.testutil.InMemoryRepositoryManager.Repo)4 OrmException (com.google.gwtorm.server.OrmException)4 ConfigInput (com.google.gerrit.extensions.api.projects.ConfigInput)3 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)3 UpdateException (com.google.gerrit.server.update.UpdateException)3