Return 400 Bad Request on ignore of own change
Users cannot ignore own changes. When a user tries to ignore an own change the request succeeded with 200 OK, but then the change was still not ignored. This behavior was confusing and it's better to return a proper response code that indicates that ignoring the change was not possible. Change-Id: Ief8f6e429f119bb9504bdfa9ee41944e01a9ecf8 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -3464,8 +3464,10 @@ public class ChangeIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void cannotIgnoreOwnChange() throws Exception {
|
||||
String changeId = createChange().getChangeId();
|
||||
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("cannot ignore own change");
|
||||
gApi.changes().id(changeId).ignore(true);
|
||||
assertThat(gApi.changes().id(changeId).ignored()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
@@ -52,8 +53,11 @@ public class Ignore
|
||||
@Override
|
||||
public Response<String> apply(ChangeResource rsrc, Input input) throws RestApiException {
|
||||
try {
|
||||
// Don't try to ignore own changes or already ignored changes
|
||||
if (canIgnore(rsrc)) {
|
||||
if (rsrc.isUserOwner()) {
|
||||
throw new BadRequestException("cannot ignore own change");
|
||||
}
|
||||
|
||||
if (!isIgnored(rsrc)) {
|
||||
stars.ignore(rsrc);
|
||||
}
|
||||
return Response.ok("");
|
||||
|
||||
Reference in New Issue
Block a user