DeleteActive: Return 409 Conflict when account is already inactive
Instead of returning 404 Not Found, return 409 Conflict. Change-Id: I0f27ce3c6ec86549e67b5359401279029b2f9887
This commit is contained in:
@@ -396,7 +396,7 @@ Sets the account state to inactive.
|
||||
HTTP/1.1 204 No Content
|
||||
----
|
||||
|
||||
If the account was already inactive the response is "`404 Not Found`".
|
||||
If the account was already inactive the response is "`409 Conflict`".
|
||||
|
||||
[[get-http-password]]
|
||||
=== Get HTTP Password
|
||||
|
||||
@@ -29,6 +29,7 @@ import static com.google.gerrit.server.StarredChangesUtil.IGNORE_LABEL;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
@@ -214,6 +215,20 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
gApi.accounts().self().setActive(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deactivateNotActive() throws Exception {
|
||||
assertThat(gApi.accounts().id("user").getActive()).isTrue();
|
||||
gApi.accounts().id("user").setActive(false);
|
||||
assertThat(gApi.accounts().id("user").getActive()).isFalse();
|
||||
try {
|
||||
gApi.accounts().id("user").setActive(false);
|
||||
fail("Expected exception");
|
||||
} catch (ResourceConflictException e) {
|
||||
assertThat(e.getMessage()).isEqualTo("account not active");
|
||||
}
|
||||
gApi.accounts().id("user").setActive(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void starUnstarChange() throws Exception {
|
||||
PushOneCommit.Result r = createChange();
|
||||
|
||||
@@ -59,7 +59,7 @@ public class DeleteActive implements RestModifyView<AccountResource, Input> {
|
||||
throw new ResourceNotFoundException("account not found");
|
||||
}
|
||||
if (!a.isActive()) {
|
||||
throw new ResourceNotFoundException();
|
||||
throw new ResourceConflictException("account not active");
|
||||
}
|
||||
if (self.get() == rsrc.getUser()) {
|
||||
throw new ResourceConflictException("cannot deactivate own account");
|
||||
|
||||
Reference in New Issue
Block a user