Prevent posting reviews on change edits
Posting a review triggers a stream event, but this fails with a NullPointerException when the creation date is set for the event since the change edit does not have a creation date. Posting reviews on a change edit and sending a stream event does not make sense since the change edit is not visible to anyone except the author. Change-Id: I8d2de5c0368d2f4211bc756ff9e989350e18df0d Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -2067,6 +2067,9 @@ describes the applied labels.
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
A review cannot be set on a change edit. Trying to post a review for a
|
||||||
|
change edit fails with `409 Conflict`.
|
||||||
|
|
||||||
[[rebase-revision]]
|
[[rebase-revision]]
|
||||||
=== Rebase Revision
|
=== Rebase Revision
|
||||||
--
|
--
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import com.google.gerrit.extensions.api.changes.ReviewInput.NotifyHandling;
|
|||||||
import com.google.gerrit.extensions.common.Comment.Side;
|
import com.google.gerrit.extensions.common.Comment.Side;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||||
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||||
import com.google.gerrit.extensions.restapi.Url;
|
import com.google.gerrit.extensions.restapi.Url;
|
||||||
@@ -130,8 +131,11 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Output apply(RevisionResource revision, ReviewInput input)
|
public Output apply(RevisionResource revision, ReviewInput input)
|
||||||
throws AuthException, BadRequestException, UnprocessableEntityException,
|
throws AuthException, BadRequestException, ResourceConflictException,
|
||||||
OrmException, IOException {
|
UnprocessableEntityException, OrmException, IOException {
|
||||||
|
if (revision.getEdit().isPresent()) {
|
||||||
|
throw new ResourceConflictException("cannot post review on edit");
|
||||||
|
}
|
||||||
if (input.onBehalfOf != null) {
|
if (input.onBehalfOf != null) {
|
||||||
revision = onBehalfOf(revision, input);
|
revision = onBehalfOf(revision, input);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user