Merge branch 'stable-2.12' into stable-2.13
* stable-2.12: Do not check visibility of parent when creating project Add test for create project with create-project capability Change-Id: I174133557e057bc64077bba7d6a68eb0de8e5f73
This commit is contained in:
@@ -24,6 +24,7 @@ import com.google.common.net.HttpHeaders;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.UseLocalDisk;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.api.projects.ProjectInput;
|
||||
import com.google.gerrit.extensions.client.InheritableBoolean;
|
||||
import com.google.gerrit.extensions.client.SubmitType;
|
||||
@@ -243,6 +244,22 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
"refs/heads/release");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateProjectWithCapability() throws Exception {
|
||||
allowGlobalCapabilities(SystemGroupBackend.REGISTERED_USERS,
|
||||
GlobalCapability.CREATE_PROJECT);
|
||||
try {
|
||||
setApiUser(user);
|
||||
ProjectInput in = new ProjectInput();
|
||||
in.name = name("newProject");
|
||||
ProjectInfo p = gApi.projects().create(in).get();
|
||||
assertThat(p.name).isEqualTo(in.name);
|
||||
} finally {
|
||||
removeGlobalCapabilities(SystemGroupBackend.REGISTERED_USERS,
|
||||
GlobalCapability.CREATE_PROJECT);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateProjectWithoutCapability_Forbidden() throws Exception {
|
||||
setApiUser(user);
|
||||
@@ -259,6 +276,26 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
assertCreateFails(in, ResourceConflictException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateProjectWithCreateProjectCapabilityAndParentNotVisible()
|
||||
throws Exception {
|
||||
Project parent = projectCache.get(allProjects).getProject();
|
||||
parent.setState(com.google.gerrit.extensions.client.ProjectState.HIDDEN);
|
||||
allowGlobalCapabilities(SystemGroupBackend.REGISTERED_USERS,
|
||||
GlobalCapability.CREATE_PROJECT);
|
||||
try {
|
||||
setApiUser(user);
|
||||
ProjectInput in = new ProjectInput();
|
||||
in.name = name("newProject");
|
||||
ProjectInfo p = gApi.projects().create(in).get();
|
||||
assertThat(p.name).isEqualTo(in.name);
|
||||
} finally {
|
||||
parent.setState(com.google.gerrit.extensions.client.ProjectState.ACTIVE);
|
||||
removeGlobalCapabilities(SystemGroupBackend.REGISTERED_USERS,
|
||||
GlobalCapability.CREATE_PROJECT);
|
||||
}
|
||||
}
|
||||
|
||||
private AccountGroup.UUID groupUuid(String groupName) {
|
||||
return groupCache.get(new AccountGroup.NameKey(groupName)).getGroupUUID();
|
||||
}
|
||||
|
@@ -163,7 +163,8 @@ public class CreateProject implements RestModifyView<TopLevelResource, ProjectIn
|
||||
|
||||
String parentName = MoreObjects.firstNonNull(
|
||||
Strings.emptyToNull(input.parent), allProjects.get());
|
||||
args.newParent = projectsCollection.get().parse(parentName).getControl();
|
||||
args.newParent =
|
||||
projectsCollection.get().parse(parentName, false).getControl();
|
||||
args.createEmptyCommit = input.createEmptyCommit;
|
||||
args.permissionsOnly = input.permissionsOnly;
|
||||
args.projectDescription = Strings.emptyToNull(input.description);
|
||||
|
@@ -63,7 +63,7 @@ public class ProjectsCollection implements
|
||||
@Override
|
||||
public ProjectResource parse(TopLevelResource parent, IdString id)
|
||||
throws ResourceNotFoundException, IOException {
|
||||
ProjectResource rsrc = _parse(id.get());
|
||||
ProjectResource rsrc = _parse(id.get(), true);
|
||||
if (rsrc == null) {
|
||||
throw new ResourceNotFoundException(id);
|
||||
}
|
||||
@@ -81,7 +81,24 @@ public class ProjectsCollection implements
|
||||
*/
|
||||
public ProjectResource parse(String id)
|
||||
throws UnprocessableEntityException, IOException {
|
||||
ProjectResource rsrc = _parse(id);
|
||||
return parse(id, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a project ID from a request body and returns the project.
|
||||
*
|
||||
* @param id ID of the project, can be a project name
|
||||
* @param checkVisibility Whether to check or not that project is visible to
|
||||
* the calling user
|
||||
* @return the project
|
||||
* @throws UnprocessableEntityException thrown if the project ID cannot be
|
||||
* resolved or if the project is not visible to the calling user and
|
||||
* checkVisibility is true.
|
||||
* @throws IOException thrown when there is an error.
|
||||
*/
|
||||
public ProjectResource parse(String id, boolean checkVisibility)
|
||||
throws UnprocessableEntityException, IOException {
|
||||
ProjectResource rsrc = _parse(id, checkVisibility);
|
||||
if (rsrc == null) {
|
||||
throw new UnprocessableEntityException(String.format(
|
||||
"Project Not Found: %s", id));
|
||||
@@ -89,7 +106,8 @@ public class ProjectsCollection implements
|
||||
return rsrc;
|
||||
}
|
||||
|
||||
private ProjectResource _parse(String id) throws IOException {
|
||||
private ProjectResource _parse(String id, boolean checkVisibility)
|
||||
throws IOException {
|
||||
if (id.endsWith(Constants.DOT_GIT_EXT)) {
|
||||
id = id.substring(0, id.length() - Constants.DOT_GIT_EXT.length());
|
||||
}
|
||||
@@ -101,7 +119,7 @@ public class ProjectsCollection implements
|
||||
} catch (NoSuchProjectException e) {
|
||||
return null;
|
||||
}
|
||||
if (!ctl.isVisible() && !ctl.isOwner()) {
|
||||
if (checkVisibility && !ctl.isVisible() && !ctl.isOwner()) {
|
||||
return null;
|
||||
}
|
||||
return new ProjectResource(ctl);
|
||||
|
Reference in New Issue
Block a user