提交 363cc0e3 编写于 作者: N Nicolas De Loof

Merge branch 'Vlatombe/user-transient-actions'

......@@ -99,6 +99,8 @@ Upcoming changes</a>
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-14327">issue 14327</a>)
<li class=rfe>
Option to set java executable path for managed windows slaves
<li class=rfe>
Added new extension point for transient user actions, and displays user properties if they are also Actions.
</ul>
</div><!--=TRUNK-END=-->
......
/*
* The MIT License
*
* Copyright (c) 2012, Vincent Latombe.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.model;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import jenkins.model.Jenkins;
import java.util.Collection;
import java.util.Collections;
/**
* Extension point for inserting transient {@link Action}s into {@link User}s.
*
* To register your implementation, put {@link Extension} on your subtype.
*
* @author Vincent Latombe
* @since 1.477
* @see Action
*/
public abstract class TransientUserActionFactory implements ExtensionPoint {
/**
* Creates actions for the given user.
*
* @param target for which the action objects are requested. Never null.
* @return Can be empty but must not be null.
*/
public Collection<? extends Action> createFor(User target) {
return Collections.emptyList();
}
/**
* Returns all the registered {@link TransientUserActionFactory}s.
*/
public static ExtensionList<TransientUserActionFactory> all() {
return Jenkins.getInstance().getExtensionList(TransientUserActionFactory.class);
}
}
\ No newline at end of file
/*
* The MIT License
*
* Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt, Tom Huybrechts
* Copyright (c) 2004-2012, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt,
* Tom Huybrechts, Vincent Latombe
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......@@ -593,13 +594,43 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
}
public Object getDynamic(String token) {
for (UserProperty property: getProperties().values()) {
if (property instanceof Action) {
Action a= (Action) property;
if(a.getUrlName().equals(token) || a.getUrlName().equals('/'+token))
return a;
for(Action action: getTransientActions()){
if(action.getUrlName().equals(token))
return action;
}
for(Action action: getPropertyActions()){
if(action.getUrlName().equals(token))
return action;
}
return null;
}
/**
* Return all properties that are also actions.
*
* @return the list can be empty but never null. read only.
*/
public List<Action> getPropertyActions() {
List<Action> actions = new ArrayList<Action>();
for (UserProperty userProp : getProperties().values()) {
if (userProp instanceof Action) {
actions.add((Action) userProp);
}
}
return Collections.unmodifiableList(actions);
}
/**
* Return all transient actions associated with this user.
*
* @return the list can be empty but never null. read only.
*/
public List<Action> getTransientActions() {
List<Action> actions = new ArrayList<Action>();
for (TransientUserActionFactory factory: TransientUserActionFactory.all()) {
actions.addAll(factory.createFor(this));
}
return Collections.unmodifiableList(actions);
}
}
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts, id:cactusman
Copyright (c) 2004-2012, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts,
id:cactusman, Vincent Latombe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -35,10 +36,11 @@ THE SOFTWARE.
<l:task icon="images/24x24/notepad.png" href="${rootURL}/${it.url}/builds" title="${%Builds}" />
<l:task icon="images/24x24/notepad.png" href="${rootURL}/${it.url}/my-views/" title="${%My Views}" />
<l:task icon="images/24x24/setting.png" href="${rootURL}/${it.url}/configure" title="${%Configure}" permission="${app.ADMINISTER}" />
<t:actions actions="${it.propertyActions}"/>
<t:actions actions="${it.transientActions}"/>
<j:if test="${it.canDelete()}">
<l:task icon="images/24x24/edit-delete.png" href="${rootURL}/${it.url}/delete" title="${%Delete}" />
</j:if>
<!-- TODO add all UserProperties that are also actions -->
</l:tasks>
</l:side-panel>
</j:jelly>
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt
* Copyright (c) 2004-2012, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt,
* Vincent Latombe
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......@@ -29,7 +30,7 @@ import org.jvnet.hudson.test.HudsonTestCase;
public class UserTestCase extends HudsonTestCase {
public static class UserPropertyImpl extends UserProperty {
public static class UserPropertyImpl extends UserProperty implements Action {
private final String testString;
private UserPropertyDescriptor descriptorImpl = new UserPropertyDescriptorImpl();
......@@ -47,6 +48,18 @@ public class UserTestCase extends HudsonTestCase {
return descriptorImpl;
}
public String getIconFileName() {
return "/images/24x24/gear.png";
}
public String getDisplayName() {
return "UserPropertyImpl";
}
public String getUrlName() {
return "userpropertyimpl";
}
public static class UserPropertyDescriptorImpl extends UserPropertyDescriptor {
@Override
public UserProperty newInstance(User user) {
......@@ -63,7 +76,7 @@ public class UserTestCase extends HudsonTestCase {
/**
* Asserts that bug# is fixed.
*/
public void testUserPropertySummaryIsShownInUserPage() throws Exception {
public void testUserPropertySummaryAndActionAreShownInUserPage() throws Exception {
UserProperty property = new UserPropertyImpl("NeedleInPage");
UserProperty.all().add(property.getDescriptor());
......@@ -72,7 +85,10 @@ public class UserTestCase extends HudsonTestCase {
user.addProperty(property);
HtmlPage page = new WebClient().goTo("user/user-test-case");
WebAssert.assertTextPresent(page, "NeedleInPage");
WebAssert.assertTextPresentInElement(page, "NeedleInPage", "main-panel");
WebAssert.assertTextPresentInElement(page, ((Action) property).getDisplayName(), "side-panel");
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册