Merge branch 'stable-2.11' into stable-2.12
* stable-2.11: SetParent: Explicitly set to All-Projects when not specified CreateProject: Explicitly set parent to All-Projects when not specified Change-Id: If833c4489945ed3f25e8aa3f5a1f812ab2fa12f7
This commit is contained in:
@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.config.AllProjectsNameProvider;
|
||||
import com.google.gerrit.server.project.SetParent;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
@@ -50,6 +51,19 @@ public class SetParentIT extends AbstractDaemonTest {
|
||||
newGson().fromJson(r.getReader(), String.class);
|
||||
assertThat(newParent).isEqualTo(parent);
|
||||
r.consume();
|
||||
|
||||
// When the parent name is not explicitly set, it should be
|
||||
// set to "All-Projects".
|
||||
r = adminSession.put("/projects/" + project.get() + "/parent",
|
||||
newParentInput(null));
|
||||
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
|
||||
r.consume();
|
||||
|
||||
r = adminSession.get("/projects/" + project.get() + "/parent");
|
||||
assertThat(r.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
|
||||
newParent = newGson().fromJson(r.getReader(), String.class);
|
||||
assertThat(newParent).isEqualTo(AllProjectsNameProvider.DEFAULT);
|
||||
r.consume();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.account.GroupBackend;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.config.ProjectOwnerGroupsProvider;
|
||||
import com.google.gerrit.server.config.RepositoryConfig;
|
||||
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
||||
@@ -102,6 +103,7 @@ public class CreateProject implements RestModifyView<TopLevelResource, ProjectIn
|
||||
private final PersonIdent serverIdent;
|
||||
private final Provider<CurrentUser> currentUser;
|
||||
private final Provider<PutConfig> putConfig;
|
||||
private final AllProjectsName allProjects;
|
||||
private final String name;
|
||||
|
||||
@Inject
|
||||
@@ -120,6 +122,7 @@ public class CreateProject implements RestModifyView<TopLevelResource, ProjectIn
|
||||
@GerritPersonIdent PersonIdent serverIdent,
|
||||
Provider<CurrentUser> currentUser,
|
||||
Provider<PutConfig> putConfig,
|
||||
AllProjectsName allProjects,
|
||||
@Assisted String name) {
|
||||
this.projectsCollection = projectsCollection;
|
||||
this.groupsCollection = groupsCollection;
|
||||
@@ -137,6 +140,7 @@ public class CreateProject implements RestModifyView<TopLevelResource, ProjectIn
|
||||
this.serverIdent = serverIdent;
|
||||
this.currentUser = currentUser;
|
||||
this.putConfig = putConfig;
|
||||
this.allProjects = allProjects;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -155,9 +159,9 @@ public class CreateProject implements RestModifyView<TopLevelResource, ProjectIn
|
||||
CreateProjectArgs args = new CreateProjectArgs();
|
||||
args.setProjectName(ProjectUtil.stripGitSuffix(name));
|
||||
|
||||
if (!Strings.isNullOrEmpty(input.parent)) {
|
||||
args.newParent = projectsCollection.get().parse(input.parent).getControl();
|
||||
}
|
||||
String parentName = MoreObjects.firstNonNull(
|
||||
Strings.emptyToNull(input.parent), allProjects.get());
|
||||
args.newParent = projectsCollection.get().parse(parentName).getControl();
|
||||
args.createEmptyCommit = input.createEmptyCommit;
|
||||
args.permissionsOnly = input.permissionsOnly;
|
||||
args.projectDescription = Strings.emptyToNull(input.description);
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Strings;
|
||||
@@ -70,20 +72,20 @@ public class SetParent implements RestModifyView<ProjectResource, Input> {
|
||||
throws AuthException, ResourceConflictException,
|
||||
ResourceNotFoundException, UnprocessableEntityException, IOException {
|
||||
ProjectControl ctl = rsrc.getControl();
|
||||
validateParentUpdate(ctl, input.parent, checkIfAdmin);
|
||||
String parentName = MoreObjects.firstNonNull(
|
||||
Strings.emptyToNull(input.parent), allProjects.get());
|
||||
validateParentUpdate(ctl, parentName, checkIfAdmin);
|
||||
try {
|
||||
MetaDataUpdate md = updateFactory.create(rsrc.getNameKey());
|
||||
try {
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
Project project = config.getProject();
|
||||
project.setParentName(Strings.emptyToNull(input.parent));
|
||||
project.setParentName(parentName);
|
||||
|
||||
String msg = Strings.emptyToNull(input.commitMessage);
|
||||
if (msg == null) {
|
||||
msg = String.format(
|
||||
"Changed parent to %s.\n",
|
||||
MoreObjects.firstNonNull(project.getParentName(),
|
||||
allProjects.get()));
|
||||
"Changed parent to %s.\n", parentName);
|
||||
} else if (!msg.endsWith("\n")) {
|
||||
msg += "\n";
|
||||
}
|
||||
@@ -92,8 +94,9 @@ public class SetParent implements RestModifyView<ProjectResource, Input> {
|
||||
config.commit(md);
|
||||
cache.evict(ctl.getProject());
|
||||
|
||||
Project.NameKey parentName = project.getParent(allProjects);
|
||||
return parentName != null ? parentName.get() : "";
|
||||
Project.NameKey parent = project.getParent(allProjects);
|
||||
checkNotNull(parent);
|
||||
return parent.get();
|
||||
} finally {
|
||||
md.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user