提交 33ed006e 编写于 作者: K kohsuke

[FIXED HUDSON-2727] In 1.265.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@13651 71c3de6d-444a-0410-be80-ed276b4c234a
上级 665bbd0c
...@@ -489,8 +489,25 @@ public class Functions { ...@@ -489,8 +489,25 @@ public class Functions {
return hasPermission(Hudson.getInstance(),permission); return hasPermission(Hudson.getInstance(),permission);
} }
public static boolean hasPermission(AccessControlled object, Permission permission) throws IOException, ServletException { /**
return permission==null || object.hasPermission(permission); * This version is so that the 'hasPermission' can degrade gracefully
* if "it" is not an {@link AccessControlled} object.
*/
public static boolean hasPermission(Object object, Permission permission) throws IOException, ServletException {
if (permission == null)
return true;
if (object instanceof AccessControlled)
return ((AccessControlled)object).hasPermission(permission);
else {
List<Ancestor> ancs = Stapler.getCurrentRequest().getAncestors();
for(Ancestor anc : Iterators.reverse(ancs)) {
Object o = anc.getObject();
if (o instanceof AccessControlled) {
return ((AccessControlled)o).hasPermission(permission);
}
}
return Hudson.getInstance().hasPermission(permission);
}
} }
public static void adminCheck(StaplerRequest req, StaplerResponse rsp, Object required, Permission permission) throws IOException, ServletException { public static void adminCheck(StaplerRequest req, StaplerResponse rsp, Object required, Permission permission) throws IOException, ServletException {
......
...@@ -5,9 +5,9 @@ import hudson.model.Job; ...@@ -5,9 +5,9 @@ import hudson.model.Job;
import hudson.model.JobProperty; import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor; import hudson.model.JobPropertyDescriptor;
import hudson.model.Hudson; import hudson.model.Hudson;
import hudson.model.Run;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -136,7 +136,7 @@ public class AuthorizationMatrixProperty extends JobProperty<Job<?, ?>> { ...@@ -136,7 +136,7 @@ public class AuthorizationMatrixProperty extends JobProperty<Job<?, ?>> {
} }
public List<PermissionGroup> getAllGroups() { public List<PermissionGroup> getAllGroups() {
return Collections.singletonList(PermissionGroup.get(Item.class)); return Arrays.asList(PermissionGroup.get(Item.class),PermissionGroup.get(Run.class));
} }
public boolean showPermission(Permission p) { public boolean showPermission(Permission p) {
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
<st:include page="sidepanel.jelly" /> <st:include page="sidepanel.jelly" />
<l:main-panel> <l:main-panel>
<div style="float:right; background-color:white; z-index: 1; position:relative; margin-left: 1em"> <div style="float:right; background-color:white; z-index: 1; position:relative; margin-left: 1em">
<j:if test="${h.hasPermission(it.UPDATE)}"> <l:hasPermission permission="${it.UPDATE}">
<st:include page="logKeep.jelly" /> <st:include page="logKeep.jelly" />
</j:if> </l:hasPermission>
<j:if test="${h.hasPermission(it.DELETE)}"> <l:hasPermission permission="${it.DELETE}">
<st:include page="delete.jelly" /> <st:include page="delete.jelly" />
</j:if> </l:hasPermission>
<div style="margin-top:1em"> <div style="margin-top:1em">
${%startedAgo(it.timestampString)} ${%startedAgo(it.timestampString)}
</div><div> </div><div>
...@@ -125,4 +125,4 @@ ...@@ -125,4 +125,4 @@
</ul> </ul>
</l:main-panel> </l:main-panel>
</l:layout> </l:layout>
</j:jelly> </j:jelly>
\ No newline at end of file
...@@ -13,7 +13,7 @@ Attributes: ...@@ -13,7 +13,7 @@ Attributes:
permission object. If specified, the link will be displayed only if you have a permission permission object. If specified, the link will be displayed only if you have a permission
--> -->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:if test="${h.hasPermission(attrs.permission)}"> <j:if test="${h.hasPermission(it,attrs.permission)}">
<j:if test="${attrs.icon!=null}"> <j:if test="${attrs.icon!=null}">
<tr> <tr>
<td> <td>
...@@ -30,4 +30,4 @@ Attributes: ...@@ -30,4 +30,4 @@ Attributes:
</tr> </tr>
</j:if> </j:if>
</j:if> </j:if>
</j:jelly> </j:jelly>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册