Merge "Fall back to addByEmail for inactive CCs"

This commit is contained in:
ekempin
2017-04-28 07:19:58 +00:00
committed by Gerrit Code Review
2 changed files with 30 additions and 0 deletions

View File

@@ -65,9 +65,11 @@ import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling;
import com.google.gerrit.extensions.api.changes.RevisionApi;
import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.api.projects.ConfigInput;
import com.google.gerrit.extensions.client.ChangeKind;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.Comment.Range;
import com.google.gerrit.extensions.client.InheritableBoolean;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.client.ReviewerState;
import com.google.gerrit.extensions.client.Side;
@@ -1094,6 +1096,31 @@ public class ChangeIT extends AbstractDaemonTest {
assertThat(r.reviewers).isNull();
}
@Test
public void addReviewerThatIsInactiveEmailFallback() throws Exception {
assume().that(notesMigration.enabled()).isTrue();
ConfigInput conf = new ConfigInput();
conf.enableReviewerByEmail = InheritableBoolean.TRUE;
gApi.projects().name(project.get()).config(conf);
PushOneCommit.Result result = createChange();
String username = "user@domain.com";
gApi.accounts().create(username).setActive(false);
AddReviewerInput in = new AddReviewerInput();
in.reviewer = username;
in.state = ReviewerState.CC;
AddReviewerResult r = gApi.changes().id(result.getChangeId()).addReviewer(in);
assertThat(r.input).isEqualTo(username);
assertThat(r.error).isNull();
// When adding by email, the reviewers field is also empty because we can't
// render a ReviewerInfo object for a non-account.
assertThat(r.reviewers).isNull();
}
@Test
public void addReviewer() throws Exception {
TestTimeUtil.resetWithClockStep(1, SECONDS);

View File

@@ -240,6 +240,9 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
reviewer, rsrc, ImmutableSet.of(member.getId()), null, state, notify, accountsToNotify);
}
if (!member.isActive()) {
if (allowByEmail && state == CC) {
return null;
}
return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerInactive, reviewer));
}
return fail(