Allow updating the parent project from the WebUI
This change adds support for updating the parent project of a child project from the WebUI. This functionality is offered in the ProjectAccessScreen. When the access rights are changed the user is also able to change the parent project (if the user has the needed privileges, means if he is administrator). When the user saves the new settings only one RPC to the server is done that updates both the access rights and the parent project property. Technically both updates are modifications of the 'project.config' file in the 'refs/meta/config' branch. There will be only one commit for this file that does both updates. In the UI only valid parent projects are suggested as new parent project (all projects that would cause a cycle in the line of parent projects are not suggested). Bug: issue 1298 Change-Id: Ic63bdb039ea5057a0551138f8fef9ede280b2be3 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -38,7 +38,7 @@ import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class SetParent implements RestModifyView<ProjectResource, Input> {
|
||||
public class SetParent implements RestModifyView<ProjectResource, Input> {
|
||||
static class Input {
|
||||
@DefaultInput
|
||||
String parent;
|
||||
@@ -63,41 +63,14 @@ class SetParent implements RestModifyView<ProjectResource, Input> {
|
||||
BadRequestException, ResourceConflictException,
|
||||
ResourceNotFoundException, UnprocessableEntityException, IOException {
|
||||
ProjectControl ctl = rsrc.getControl();
|
||||
validateParentUpdate(ctl, input.parent);
|
||||
IdentifiedUser user = (IdentifiedUser) ctl.getCurrentUser();
|
||||
if (!user.getCapabilities().canAdministrateServer()) {
|
||||
throw new AuthException("not administrator");
|
||||
}
|
||||
|
||||
if (rsrc.getNameKey().equals(allProjects)) {
|
||||
throw new ResourceConflictException("cannot set parent of "
|
||||
+ allProjects.get());
|
||||
}
|
||||
|
||||
input.parent = Strings.emptyToNull(input.parent);
|
||||
if (input.parent != null) {
|
||||
ProjectState parent = cache.get(new Project.NameKey(input.parent));
|
||||
if (parent == null) {
|
||||
throw new UnprocessableEntityException("parent project " + input.parent
|
||||
+ " not found");
|
||||
}
|
||||
|
||||
if (Iterables.tryFind(parent.tree(), new Predicate<ProjectState>() {
|
||||
@Override
|
||||
public boolean apply(ProjectState input) {
|
||||
return input.getProject().getNameKey().equals(rsrc.getNameKey());
|
||||
}
|
||||
}).isPresent()) {
|
||||
throw new ResourceConflictException("cycle exists between "
|
||||
+ rsrc.getName() + " and " + parent.getProject().getName());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
MetaDataUpdate md = updateFactory.create(rsrc.getNameKey());
|
||||
try {
|
||||
ProjectConfig config = ProjectConfig.read(md);
|
||||
Project project = config.getProject();
|
||||
project.setParentName(input.parent);
|
||||
project.setParentName(Strings.emptyToNull(input.parent));
|
||||
|
||||
String msg = Strings.emptyToNull(input.commitMessage);
|
||||
if (msg == null) {
|
||||
@@ -124,4 +97,39 @@ class SetParent implements RestModifyView<ProjectResource, Input> {
|
||||
"invalid project.config: %s", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public void validateParentUpdate(final ProjectControl ctl, String newParent)
|
||||
throws AuthException, ResourceConflictException,
|
||||
UnprocessableEntityException {
|
||||
IdentifiedUser user = (IdentifiedUser) ctl.getCurrentUser();
|
||||
if (!user.getCapabilities().canAdministrateServer()) {
|
||||
throw new AuthException("not administrator");
|
||||
}
|
||||
|
||||
if (ctl.getProject().getNameKey().equals(allProjects)) {
|
||||
throw new ResourceConflictException("cannot set parent of "
|
||||
+ allProjects.get());
|
||||
}
|
||||
|
||||
newParent = Strings.emptyToNull(newParent);
|
||||
if (newParent != null) {
|
||||
ProjectState parent = cache.get(new Project.NameKey(newParent));
|
||||
if (parent == null) {
|
||||
throw new UnprocessableEntityException("parent project " + newParent
|
||||
+ " not found");
|
||||
}
|
||||
|
||||
if (Iterables.tryFind(parent.tree(), new Predicate<ProjectState>() {
|
||||
@Override
|
||||
public boolean apply(ProjectState input) {
|
||||
return input.getProject().getNameKey()
|
||||
.equals(ctl.getProject().getNameKey());
|
||||
}
|
||||
}).isPresent()) {
|
||||
throw new ResourceConflictException("cycle exists between "
|
||||
+ ctl.getProject().getName() + " and "
|
||||
+ parent.getProject().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user