Fix reading /default for inherited dashboards

When loading the default dashboard for a project the default REST
approach is to load only the default defined locally in this project.
If no such default is defined, the caller may supply an optional
?inherited query parameter to search up the inheritance tree.

Change-Id: I5ed3d63f734fa9734c7ccd05c940fbdcf9dcab1d
This commit is contained in:
Shawn O. Pearce
2012-11-17 21:29:39 -08:00
parent a7d9c9b7ac
commit 8e6ccbcb68
5 changed files with 91 additions and 21 deletions

View File

@@ -32,6 +32,7 @@ import com.google.inject.Provider;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.kohsuke.args4j.Option;
class SetDefaultDashboard implements RestModifyView<DashboardResource, Input> {
private final ProjectCache cache;
@@ -39,6 +40,9 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, Input> {
private final DashboardsCollection dashboards;
private final Provider<GetDashboard> get;
@Option(name = "--inherited", usage = "set dashboard inherited by children")
private boolean inherited;
@Inject
SetDefaultDashboard(ProjectCache cache,
MetaDataUpdate.Server updateFactory,
@@ -84,7 +88,11 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, Input> {
try {
ProjectConfig config = ProjectConfig.read(md);
Project project = config.getProject();
project.setLocalDefaultDashboard(input.id);
if (inherited) {
project.setDefaultDashboard(input.id);
} else {
project.setLocalDefaultDashboard(input.id);
}
String msg = Objects.firstNonNull(
Strings.emptyToNull(input.commitMessage),
@@ -120,6 +128,9 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, Input> {
RestModifyView<ProjectResource, SetDashboard.Input> {
private final Provider<SetDefaultDashboard> setDefault;
@Option(name = "--inherited", usage = "set dashboard inherited by children")
private boolean inherited;
@Inject
CreateDefault(Provider<SetDefaultDashboard> setDefault) {
this.setDefault = setDefault;
@@ -134,9 +145,11 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, Input> {
public Object apply(ProjectResource resource, Input input)
throws AuthException, BadRequestException, ResourceConflictException,
Exception {
ProjectControl ctl = resource.getControl();
return setDefault.get().apply(
new DashboardResource(ctl, null, null, null, null, true), input);
SetDefaultDashboard set = setDefault.get();
set.inherited = inherited;
return set.apply(
DashboardResource.projectDefault(resource.getControl()),
input);
}
}
}