提交 e16d23bf 编写于 作者: K Kohsuke Kawaguchi

Hudson does a very tricky redirection for Views. Shouldn't apply to the rest of ItemGroups

上级 8d150d57
...@@ -154,6 +154,7 @@ import org.jvnet.hudson.reactor.ReactorListener; ...@@ -154,6 +154,7 @@ import org.jvnet.hudson.reactor.ReactorListener;
import org.jvnet.hudson.reactor.TaskGraphBuilder.Handle; import org.jvnet.hudson.reactor.TaskGraphBuilder.Handle;
import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option; import org.kohsuke.args4j.Option;
import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.HttpRedirect; import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses; import org.kohsuke.stapler.HttpResponses;
...@@ -550,6 +551,24 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl ...@@ -550,6 +551,24 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
protected File getRootDirFor(String name) { protected File getRootDirFor(String name) {
return Hudson.this.getRootDirFor(name); return Hudson.this.getRootDirFor(name);
} }
/**
*send the browser to the config page
* use View to trim view/{default-view} from URL if possible
*/
@Override
protected String redirectAfterCreateItem(StaplerRequest req, TopLevelItem result) throws IOException {
String redirect = result.getUrl()+"configure";
List<Ancestor> ancestors = req.getAncestors();
for (int i = ancestors.size() - 1; i >= 0; i--) {
Object o = ancestors.get(i).getObject();
if (o instanceof View) {
redirect = req.getContextPath() + '/' + ((View)o).getUrl() + redirect;
break;
}
}
return redirect;
}
}; };
@CLIResolver @CLIResolver
......
...@@ -117,6 +117,7 @@ public abstract class ItemGroupMixIn { ...@@ -117,6 +117,7 @@ public abstract class ItemGroupMixIn {
/** /**
* Creates a {@link TopLevelItem} from the submission of the '/lib/hudson/newFromList/formList' * Creates a {@link TopLevelItem} from the submission of the '/lib/hudson/newFromList/formList'
* or throws an exception if it fails.
*/ */
public synchronized TopLevelItem createTopLevelItem( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { public synchronized TopLevelItem createTopLevelItem( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
acl.checkPermission(Job.CREATE); acl.checkPermission(Job.CREATE);
...@@ -150,9 +151,8 @@ public abstract class ItemGroupMixIn { ...@@ -150,9 +151,8 @@ public abstract class ItemGroupMixIn {
else else
throw new Failure("No such job: "+from); throw new Failure("No such job: "+from);
} }
if (!(src instanceof TopLevelItem)) { if (!(src instanceof TopLevelItem))
throw new Failure(from+" cannot be copied"); throw new Failure(from+" cannot be copied");
}
result = copy((TopLevelItem) src,name); result = copy((TopLevelItem) src,name);
} else { } else {
...@@ -169,21 +169,17 @@ public abstract class ItemGroupMixIn { ...@@ -169,21 +169,17 @@ public abstract class ItemGroupMixIn {
} }
} }
// send the browser to the config page rsp.sendRedirect2(redirectAfterCreateItem(req, result)+"configure");
// use View to trim view/{default-view} from URL if possible
String redirect = result.getUrl()+"configure";
List<Ancestor> ancestors = req.getAncestors();
for (int i = ancestors.size() - 1; i >= 0; i--) {
Object o = ancestors.get(i).getObject();
if (o instanceof View) {
redirect = req.getContextPath() + '/' + ((View)o).getUrl() + redirect;
break;
}
}
rsp.sendRedirect2(redirect);
return result; return result;
} }
/**
* Computes the redirection target URL for the newly created {@link TopLevelItem}.
*/
protected String redirectAfterCreateItem(StaplerRequest req, TopLevelItem result) throws IOException {
return req.getContextPath()+'/'+result.getUrl()+"configure";
}
/** /**
* Copies an existing {@link TopLevelItem} to a new name. * Copies an existing {@link TopLevelItem} to a new name.
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册