Skip to content

Commit

Permalink
Merge pull request #1306 from bkmeneguello/post-cancel-shutdown
Browse files Browse the repository at this point in the history
[FIXED JENKINS-23020 JENKINS-23942] Convert the queue's cancel shutdown to POST
(cherry picked from commit fda84f4)
  • Loading branch information
daniel-beck authored and olivergondza committed Nov 7, 2014
1 parent 68eb266 commit b73bb3d
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 3 deletions.
10 changes: 10 additions & 0 deletions core/src/main/java/hudson/model/ManagementLink.java
Expand Up @@ -112,4 +112,14 @@ public static ExtensionList<ManagementLink> all() {
public Permission getRequiredPermission() {
return null;
}

/**
* Define if the rendered link will use the default GET method or POST.
* @return true if POST must be used
* @see RequirePOST
* @since TODO
*/
public boolean getRequiresPOST() {
return false;
}
}
5 changes: 5 additions & 0 deletions core/src/main/java/jenkins/management/ShutdownLink.java
Expand Up @@ -52,4 +52,9 @@ public String getDescription() {
public String getUrlName() {
return Jenkins.getInstance().isQuietingDown() ? "cancelQuietDown" : "quietDown";
}

@Override
public boolean getRequiresPOST() {
return true;
}
}
4 changes: 2 additions & 2 deletions core/src/main/resources/jenkins/model/Jenkins/manage.jelly
Expand Up @@ -43,7 +43,7 @@ THE SOFTWARE.
<l:confirmationLink href="${_href}" post="true" message="${%are.you.sure(title)}">${title}</l:confirmationLink>
</j:when>
<j:otherwise>
<a href="${_href}">${title}</a>
<f:link href="${_href}" post="${post}">${title}</f:link>
</j:otherwise>
</j:choose>
</div>
Expand Down Expand Up @@ -86,7 +86,7 @@ THE SOFTWARE.
<l:hasPermission permission="${m.requiredPermission}">
<j:set var="icon" value="${m.iconClassName != null ? m.iconClassName : m.iconFileName}"/>
<j:if test="${icon!=null}">
<local:feature icon="${icon}" href="${m.urlName}" title="${m.displayName}" requiresConfirmation="${m.requiresConfirmation}">
<local:feature icon="${icon}" href="${m.urlName}" title="${m.displayName}" requiresConfirmation="${m.requiresConfirmation}" post="${m.requiresPOST}">
<j:out value="${m.description}"/>
<st:include it="${m}" page="info.jelly" optional="true"/>
</local:feature>
Expand Down
49 changes: 49 additions & 0 deletions core/src/main/resources/lib/form/link.jelly
@@ -0,0 +1,49 @@
<!--
The MIT License
Copyright (c) 2004-2010, Sun Microsystems, Inc., Bruno Kühnen Meneguello
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.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
<st:documentation>
Generates an anchor element with the ability to send POST requests and/or
asynchronous requests. It depends the combination of post and async attributes.

@since TODO
<st:attribute name="clazz">
Additional CSS classes.
</st:attribute>
<st:attribute name="href">
Link destination URL.
</st:attribute>
<st:attribute name="post">
If this must send a POST request.
</st:attribute>
<st:attribute name="async">
If this must send an asynchronous request.
</st:attribute>
</st:documentation>

<st:adjunct includes="lib.form.link.link"/>

<a href="${attrs.href}" class="${attrs.post ? 'post' + (attrs.async ? '-async' : '') : (attrs.async ? 'async' : '')} ${attrs.clazz}"><d:invokeBody/></a>
</j:jelly>
27 changes: 27 additions & 0 deletions core/src/main/resources/lib/form/link/link.js
@@ -0,0 +1,27 @@
Behaviour.specify('A.post', 'link.post', 0, function(element) {
element.onclick = function(evt) {
var form = document.createElement('form');
form.setAttribute('method', 'POST');
form.setAttribute('action', element.getAttribute('href'));
crumb.appendToForm(form);
document.body.appendChild(form);
form.submit();
return false;
}
});

Behaviour.specify('A.post-async', 'link.post-async', 0, function(element) {
element.onclick = function(evt) {
new Ajax.Request(element.getAttribute('href'));
return false;
}
});

Behaviour.specify('A.async', 'link.async', 0, function(element) {
element.onclick = function(evt) {
new Ajax.Request(element.getAttribute('href'), {
method : 'get'
});
return false;
}
});
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/hudson/queue.jelly
Expand Up @@ -51,7 +51,7 @@ THE SOFTWARE.
<td class="pane" colspan="2" style="white-space: normal;">
${%Jenkins is going to shut down. No further builds will be performed.}
<j:if test="${h.hasPermission(app.ADMINISTER)}">
<a href="${rootURL}/cancelQuietDown">(${%cancel})</a>
<f:link href="${rootURL}/cancelQuietDown" post="true">(${%cancel})</f:link>
</j:if>
</td>
</tr>
Expand Down

0 comments on commit b73bb3d

Please sign in to comment.