Skip to content
Browse files
[FIXED JENKINS-35168] Resolve the context ModelObject when it isn…
…'t a `ModelObeject`
  • Loading branch information
stephenc committed May 27, 2016
1 parent be60a05 commit 3169dcd267ffb4c2ff0b27be5495ee1d9571ef35
Showing with 28 additions and 2 deletions.
  1. +21 −0 src/main/java/com/cloudbees/plugins/credentials/
  2. +7 −2 src/main/resources/lib/credentials/select.jelly
@@ -94,9 +94,30 @@ public String getDisplayName() {
return Messages.CredentialsSelectHelper_DisplayName();

* Fixes up the context in case we are called from a page where the context is not a ModelObject.
* @param context the initial guess of the context.
* @return the resolved context.
* @since 2.0.7
public ModelObject resolveContext(Object context) {
if (context instanceof ModelObject) {
return (ModelObject) context;
StaplerRequest request = Stapler.getCurrentRequest();
if (request != null) {
return request.findAncestorObject(ModelObject.class);
return null;

* Returns the {@link StoreItem} instances for the current Stapler request.
* @param context the context in which to retrieve the store items.
* @param includeUser {@code true} to also include any User scoped stores.
* @return the {@link StoreItem} instances for the current Stapler request.
* @since 2.0.5
@@ -45,13 +45,17 @@
<st:attribute name="includeUser">
If the user's scoped stores should be included
<st:attribute name="context">
The context within which to look up the stores. (defaults to <code>it</code> (jelly) / <code>my</code> (groovy))
<j:set var="value" value="${attrs.value ?: instance[attrs.field] ?: attrs.default}" />
<j:set var="paramValue" value="${attrs.expressionAllowed and value.startsWith('${') and value.endsWith('}')}"/>
<j:set var="paramDefault" value="${attrs.expressionAllowed and attrs.default.startsWith('${') and attrs.default.endsWith('}')}"/>
<j:set var="selectHelper" value="${app.getDescriptorByName('com.cloudbees.plugins.credentials.CredentialsSelectHelper')}"/>
<j:set var="includeUser" value="${attrs.includeUser ? true : false}"/>
<j:set var="context" value="${selectHelper.resolveContext(attrs.context ?: it)}"/>
<div class="credentials-select-control">
<j:if test="${attrs.expressionAllowed}">
<label field-disabled="true">
@@ -71,8 +75,9 @@
default="${paramDefault?'':attrs.default}" value="${paramValue?(paramDefault?'':attrs.default):value}"/>
<!-- TODO add support for checking permissions against stores in request path -->
<j:set var="storeItems" value="${selectHelper.getStoreItems(context, includeUser)}"/>
<j:when test="${h.hasPermission(selectHelper.CREATE)}">
<j:when test="${h.hasPermission(selectHelper.CREATE) and storeItems != null and !storeItems.isEmpty()}">
<button type="button" class="credentials-add-menu" menualign="${attrs.menuAlign}"
<l:icon class="icon-credentials-new-credential icon-sm"/>
@@ -81,7 +86,7 @@
<div class="credentials-add-menu-items yuimenu">
<div class="bd">
<ul class="first-of-type">
<j:forEach var="storeItem" items="${selectHelper.getStoreItems(it, includeUser)}">
<j:forEach var="storeItem" items="${storeItems}">
<li class="yuimenuitem" data-url="${storeItem.url}/dialog" disabled="${storeItem.enabled?null:'disabled'}">
<span class="yuimenuitemlabel" tooltip="${storeItem.description}">
<l:icon class="${storeItem.iconClassName} icon-sm"/>

0 comments on commit 3169dcd

Please sign in to comment.