Skip to content

Commit

Permalink
control the presence of the abort icon based on permission.
Browse files Browse the repository at this point in the history
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@6579 71c3de6d-444a-0410-be80-ed276b4c234a
  • Loading branch information
kohsuke committed Jan 12, 2008
1 parent 5edc0f1 commit e260817
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
5 changes: 1 addition & 4 deletions core/src/main/java/hudson/model/AbstractBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,8 @@ public List<AbstractBuild> getBuilds() {
}
}

/**
* People can stop a build if they can start a build.
*/
public void checkAbortPermission() {
getParent().getACL().checkPermission(AbstractProject.BUILD);
getParent().getACL().checkPermission(AbstractProject.ABORT);
}

//
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/hudson/model/AbstractProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -937,4 +937,8 @@ public int compare(Integer o1, Integer o2) {
private static final Logger LOGGER = Logger.getLogger(AbstractProject.class.getName());

public static final Permission BUILD = new Permission(PERMISSIONS, "Build", Permission.UPDATE);
/**
* Permission to abort a build. For now, let's make it the same as {@link #BUILD}
*/
public static final Permission ABORT = BUILD;
}
13 changes: 13 additions & 0 deletions core/src/main/java/hudson/model/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.acegisecurity.AccessDeniedException;


/**
Expand Down Expand Up @@ -162,6 +163,18 @@ public void doStop( StaplerRequest req, StaplerResponse rsp ) throws IOException
rsp.forwardToPreviousPage(req);
}

/**
* Checks if the current user has a permission to stop this build.
*/
public boolean hasStopPermission() {
try {
executable.checkAbortPermission();
return true;
} catch (AccessDeniedException e) {
return false;
}
}

public Computer getOwner() {
return owner;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/lib/hudson/executors.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
<t:buildProgressBar build="${e.currentExecutable}"/>
</td>
<td class="pane" width="16" align="center" valign="middle">
<l:isAdmin>
<j:if test="${e.hasStopPermission()}">
<a href="${rootURL}/computers/${cloop.index}/executors/${eloop.index}/stop"><img src="${imagesURL}/16x16/stop.gif" alt="${%terminate this build}" /></a>
</l:isAdmin>
</j:if>
</td>
</j:otherwise>
</j:choose>
Expand Down

0 comments on commit e260817

Please sign in to comment.