GetDashboard: Return 'bad request' on misuse of 'inherited' flag
The 'inherited' flag may only be used for the default dashboard. Instead of returning 'not found: inherited', when the 'inherited' flag is used on a non-default dashboard, return a 'bad request' error. Change-Id: I46bc70d416c908336c28706a6c15cbd16c253f40
This commit is contained in:
@@ -22,6 +22,7 @@ import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.server.project.DashboardsCollection;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
@@ -57,8 +58,8 @@ public class DashboardIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void cannotGetDashboardWithInheritedForNonDefault() throws Exception {
|
||||
DashboardInfo info = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test");
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
exception.expectMessage("inherited");
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("inherited flag can only be used with default");
|
||||
gApi.projects().name(project.get()).dashboard(info.id).get(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,9 @@ package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.common.SetDashboardInput;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -40,9 +37,7 @@ class DeleteDashboard implements RestModifyView<DashboardResource, SetDashboardI
|
||||
|
||||
@Override
|
||||
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
ResourceNotFoundException, MethodNotAllowedException, IOException,
|
||||
PermissionBackendException {
|
||||
throws RestApiException, IOException, PermissionBackendException {
|
||||
if (resource.isProjectDefault()) {
|
||||
SetDashboardInput in = new SetDashboardInput();
|
||||
in.commitMessage = input != null ? input.commitMessage : null;
|
||||
|
||||
@@ -21,9 +21,11 @@ import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
@@ -51,11 +53,9 @@ public class GetDashboard implements RestReadView<DashboardResource> {
|
||||
|
||||
@Override
|
||||
public DashboardInfo apply(DashboardResource resource)
|
||||
throws ResourceNotFoundException, ResourceConflictException, IOException,
|
||||
PermissionBackendException {
|
||||
throws RestApiException, IOException, PermissionBackendException {
|
||||
if (inherited && !resource.isProjectDefault()) {
|
||||
// inherited flag can only be used with default.
|
||||
throw new ResourceNotFoundException("inherited");
|
||||
throw new BadRequestException("inherited flag can only be used with default");
|
||||
}
|
||||
|
||||
String project = resource.getControl().getProject().getName();
|
||||
|
||||
@@ -16,12 +16,9 @@ package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.common.SetDashboardInput;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -40,9 +37,7 @@ class SetDashboard implements RestModifyView<DashboardResource, SetDashboardInpu
|
||||
|
||||
@Override
|
||||
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
MethodNotAllowedException, ResourceNotFoundException, IOException,
|
||||
PermissionBackendException {
|
||||
throws RestApiException, IOException, PermissionBackendException {
|
||||
if (resource.isProjectDefault()) {
|
||||
return defaultSetter.get().apply(resource, input);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
@@ -59,8 +60,7 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, SetDashbo
|
||||
|
||||
@Override
|
||||
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
ResourceNotFoundException, IOException, PermissionBackendException {
|
||||
throws RestApiException, IOException, PermissionBackendException {
|
||||
if (input == null) {
|
||||
input = new SetDashboardInput(); // Delete would set input to null.
|
||||
}
|
||||
@@ -132,8 +132,7 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, SetDashbo
|
||||
|
||||
@Override
|
||||
public Response<DashboardInfo> apply(ProjectResource resource, SetDashboardInput input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
ResourceNotFoundException, IOException, PermissionBackendException {
|
||||
throws RestApiException, IOException, PermissionBackendException {
|
||||
SetDefaultDashboard set = setDefault.get();
|
||||
set.inherited = inherited;
|
||||
return set.apply(DashboardResource.projectDefault(resource.getControl()), input);
|
||||
|
||||
Reference in New Issue
Block a user