提交 7ae71bf1 编写于 作者: K Kohsuke Kawaguchi

added a mechanism to filter out descriptors

上级 70fde5f7
......@@ -30,6 +30,7 @@ import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.DescriptorVisibilityFilter;
import hudson.model.Hudson;
import hudson.model.Item;
import hudson.model.ItemGroup;
......@@ -1274,6 +1275,10 @@ public class Functions {
return o.toString();
}
public List filterDescriptors(Object context, Iterable descriptors) {
return DescriptorVisibilityFilter.apply(context,descriptors);
}
private static final Pattern SCHEME = Pattern.compile("[a-z]+://.+");
/**
......
package hudson.model;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.scm.SCMDescriptor;
import java.util.ArrayList;
import java.util.List;
/**
* Hides {@link Descriptor}s from users.
*
* @author Kohsuke Kawaguchi
* @since 1.393
*/
public abstract class DescriptorVisibilityFilter implements ExtensionPoint {
/**
* Decides if the given descriptor should be visible to the user.
*
* @param context
* The object that indicates where the visibility of a descriptor is evaluated.
* For example, if Hudson is deciding whether a {@link FreeStyleProject} should gets a
* {@link SCMDescriptor}, the context object will be the {@link FreeStyleProject}.
* The caller can pass in null if there's no context.
* @param descriptor
* Descriptor whose visibility is evaluated. Never null.
*
* @return
* true to allow the descriptor to be visible. false to hide it.
* If any of the installed {@link DescriptorVisibilityFilter} returns false,
* the descriptor is not shown.
*/
public abstract boolean filter(Object context, Descriptor descriptor);
public static ExtensionList<DescriptorVisibilityFilter> all() {
return Hudson.getInstance().getExtensionList(DescriptorVisibilityFilter.class);
}
public static <T extends Descriptor> List<T> apply(Object context, Iterable<T> source) {
ExtensionList<DescriptorVisibilityFilter> filters = all();
List<T> r = new ArrayList<T>();
OUTER:
for (T d : source) {
for (DescriptorVisibilityFilter f : filters) {
if (!f.filter(context,d))
continue OUTER; // veto-ed. not shown
}
r.add(d);
}
return r;
}
}
......@@ -33,6 +33,8 @@ THE SOFTWARE.
@checkUrl : form field validation url
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:s="/lib/form">
<j:set var="descriptors" value="${h.filterDescriptors(it,attrs.descriptors)}" />
<s:form method="post" action="createItem">
<s:entry title="${attrs.nameTitle}">
<s:textbox id="name" name="name" checkUrl="'${rootURL}/${attrs.checkUrl}?value='+encodeURIComponent(this.value)"
......@@ -40,7 +42,7 @@ THE SOFTWARE.
<script>$('name').focus();</script>
</s:entry>
<j:forEach var="descriptor" items="${attrs.descriptors}">
<j:forEach var="descriptor" items="${descriptors}">
<s:block>
<input type="radio" name="mode" value="${descriptor.class.name}" onchange="updateOk(this.form)" onclick="updateOk(this.form)" />
<st:nbsp/>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册