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.common.data.Permission;
|
||||||
import com.google.gerrit.extensions.api.projects.BranchInput;
|
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
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.extensions.restapi.ResourceNotFoundException;
|
||||||
import com.google.gerrit.server.project.DashboardsCollection;
|
import com.google.gerrit.server.project.DashboardsCollection;
|
||||||
import org.eclipse.jgit.junit.TestRepository;
|
import org.eclipse.jgit.junit.TestRepository;
|
||||||
@@ -57,8 +58,8 @@ public class DashboardIT extends AbstractDaemonTest {
|
|||||||
@Test
|
@Test
|
||||||
public void cannotGetDashboardWithInheritedForNonDefault() throws Exception {
|
public void cannotGetDashboardWithInheritedForNonDefault() throws Exception {
|
||||||
DashboardInfo info = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test");
|
DashboardInfo info = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test");
|
||||||
exception.expect(ResourceNotFoundException.class);
|
exception.expect(BadRequestException.class);
|
||||||
exception.expectMessage("inherited");
|
exception.expectMessage("inherited flag can only be used with default");
|
||||||
gApi.projects().name(project.get()).dashboard(info.id).get(true);
|
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.api.projects.DashboardInfo;
|
||||||
import com.google.gerrit.extensions.common.SetDashboardInput;
|
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.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.Response;
|
||||||
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -40,9 +37,7 @@ class DeleteDashboard implements RestModifyView<DashboardResource, SetDashboardI
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input)
|
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input)
|
||||||
throws AuthException, BadRequestException, ResourceConflictException,
|
throws RestApiException, IOException, PermissionBackendException {
|
||||||
ResourceNotFoundException, MethodNotAllowedException, IOException,
|
|
||||||
PermissionBackendException {
|
|
||||||
if (resource.isProjectDefault()) {
|
if (resource.isProjectDefault()) {
|
||||||
SetDashboardInput in = new SetDashboardInput();
|
SetDashboardInput in = new SetDashboardInput();
|
||||||
in.commitMessage = input != null ? input.commitMessage : null;
|
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.base.Strings;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
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.IdString;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
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.RestReadView;
|
||||||
import com.google.gerrit.extensions.restapi.Url;
|
import com.google.gerrit.extensions.restapi.Url;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||||
@@ -51,11 +53,9 @@ public class GetDashboard implements RestReadView<DashboardResource> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DashboardInfo apply(DashboardResource resource)
|
public DashboardInfo apply(DashboardResource resource)
|
||||||
throws ResourceNotFoundException, ResourceConflictException, IOException,
|
throws RestApiException, IOException, PermissionBackendException {
|
||||||
PermissionBackendException {
|
|
||||||
if (inherited && !resource.isProjectDefault()) {
|
if (inherited && !resource.isProjectDefault()) {
|
||||||
// inherited flag can only be used with default.
|
throw new BadRequestException("inherited flag can only be used with default");
|
||||||
throw new ResourceNotFoundException("inherited");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String project = resource.getControl().getProject().getName();
|
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.api.projects.DashboardInfo;
|
||||||
import com.google.gerrit.extensions.common.SetDashboardInput;
|
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.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.Response;
|
||||||
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -40,9 +37,7 @@ class SetDashboard implements RestModifyView<DashboardResource, SetDashboardInpu
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input)
|
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input)
|
||||||
throws AuthException, BadRequestException, ResourceConflictException,
|
throws RestApiException, IOException, PermissionBackendException {
|
||||||
MethodNotAllowedException, ResourceNotFoundException, IOException,
|
|
||||||
PermissionBackendException {
|
|
||||||
if (resource.isProjectDefault()) {
|
if (resource.isProjectDefault()) {
|
||||||
return defaultSetter.get().apply(resource, input);
|
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.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||||
import com.google.gerrit.extensions.restapi.Response;
|
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.extensions.restapi.RestModifyView;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||||
@@ -59,8 +60,7 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, SetDashbo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input)
|
public Response<DashboardInfo> apply(DashboardResource resource, SetDashboardInput input)
|
||||||
throws AuthException, BadRequestException, ResourceConflictException,
|
throws RestApiException, IOException, PermissionBackendException {
|
||||||
ResourceNotFoundException, IOException, PermissionBackendException {
|
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
input = new SetDashboardInput(); // Delete would set input to null.
|
input = new SetDashboardInput(); // Delete would set input to null.
|
||||||
}
|
}
|
||||||
@@ -132,8 +132,7 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, SetDashbo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<DashboardInfo> apply(ProjectResource resource, SetDashboardInput input)
|
public Response<DashboardInfo> apply(ProjectResource resource, SetDashboardInput input)
|
||||||
throws AuthException, BadRequestException, ResourceConflictException,
|
throws RestApiException, IOException, PermissionBackendException {
|
||||||
ResourceNotFoundException, IOException, PermissionBackendException {
|
|
||||||
SetDefaultDashboard set = setDefault.get();
|
SetDefaultDashboard set = setDefault.get();
|
||||||
set.inherited = inherited;
|
set.inherited = inherited;
|
||||||
return set.apply(DashboardResource.projectDefault(resource.getControl()), input);
|
return set.apply(DashboardResource.projectDefault(resource.getControl()), input);
|
||||||
|
|||||||
Reference in New Issue
Block a user