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);
}
}
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();
}
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();
}
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()));
}
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();
}
Aggregations