PostReview: Don't try to publish other users' drafts

We were calling the wrong PatchLineCommentsUtil method by accident,
getting all drafts on a change rather than just the current user's
drafts. Fortunately, there is a sanity check in ChangeDraftUpdate that
was triggering and turning these into 500s rather than actually
publishing other users' drafts.

Fix this bug, and add some more draft changes to the test case that
are explicitly excluded.

Change-Id: Ifae5b0a61328b33170664a81a39f02fa7cfd4e4e
This commit is contained in:
Dave Borowitz 2015-05-05 10:13:09 -07:00
parent 74b919a6c9
commit 0f243ef2a7
2 changed files with 13 additions and 2 deletions

View File

@ -289,6 +289,17 @@ public class CommentsIT extends AbstractDaemonTest {
addDraft(r2.getChangeId(), r2.getCommit().getName(),
newDraft(FILE_NAME, Side.REVISION, 2, "typo: content"));
PushOneCommit.Result other = createChange();
// Drafts on other changes aren't returned.
addDraft(other.getChangeId(), other.getCommit().getName(),
newDraft(FILE_NAME, Side.REVISION, 1, "unrelated comment"));
setApiUser(admin);
// Drafts by other users aren't returned.
addDraft(r2.getChangeId(), r2.getCommit().getName(),
newDraft(FILE_NAME, Side.REVISION, 2, "oops"));
setApiUser(user);
ReviewInput reviewInput = new ReviewInput();
reviewInput.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
reviewInput.message = "comments";

View File

@ -414,8 +414,8 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
private Map<String, PatchLineComment> changeDrafts(RevisionResource rsrc)
throws OrmException {
Map<String, PatchLineComment> drafts = Maps.newHashMap();
for (PatchLineComment c
: plcUtil.draftByChange(db.get(), rsrc.getNotes())) {
for (PatchLineComment c : plcUtil.draftByChangeAuthor(
db.get(), rsrc.getNotes(), rsrc.getAccountId())) {
drafts.put(c.getKey().get(), c);
}
return drafts;