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