incorporating APLAWS patch

r1674 | chrisg23 | 2007-09-19 17:14:18 +0200 (Mi, 19 Sep 2007) 
Refactor - extract permission checks on action links so that concrete implementations may override the check if required


git-svn-id: https://svn.libreccm.org/ccm/trunk@31 8810af33-2d31-482b-a856-94f89814c4df
master
pb 2008-02-15 20:45:08 +00:00
parent 7ec05e633f
commit a3f1171a53
2 changed files with 79 additions and 20 deletions

View File

@ -78,26 +78,39 @@ public abstract class AbstractDomainObjectDetails
Iterator actions = getDomainObjectActions(); Iterator actions = getDomainObjectActions();
while (actions.hasNext()) { while (actions.hasNext()) {
String action = (String)actions.next(); String action = (String)actions.next();
boolean actionVisible = true; if (isActionVisible(action, dobj, state)) {
PrivilegeDescriptor privilege = getDomainObjectActionPrivilege(action); Element actionEl = parent.newChildElement(m_prefix + ":action",
if (privilege != null) { getNamespace());
Party party = Kernel.getContext().getParty(); actionEl.addAttribute("name", action);
if (party == null) { actionEl.addAttribute("url", getDomainObjectActionLink(state,
party = Kernel.getPublicUser(); dobj, action));
} }
Assert.truth(dobj.getObjectType().isSubtypeOf(ACSObject.BASE_DATA_OBJECT_TYPE), }
"I can only check permissions on ACS Objects - this domain Object is not a subtype of ACSObject "); }
PermissionDescriptor permission = new PermissionDescriptor(privilege,(ACSObject) dobj,party); /**
actionVisible = PermissionService.checkPermission(permission); * determine whether this action should be rendered. Default
} * implementation returns true unless a privilege has been
if (actionVisible) { * specified for the action in which case a permission check
Element actionEl = parent.newChildElement(m_prefix + ":action", * is carried out for the current user.
getNamespace()); * @param action
actionEl.addAttribute("name", action); * @param dobj
actionEl.addAttribute("url", * @param state
getDomainObjectActionLink(state, dobj, action)); * @return
} */
protected boolean isActionVisible (String action, DomainObject dobj, PageState state) {
boolean actionVisible = true;
PrivilegeDescriptor privilege = getDomainObjectActionPrivilege(action);
if (privilege != null) {
Party party = Kernel.getContext().getParty();
if (party == null) {
party = Kernel.getPublicUser();
}
Assert.truth(dobj.getObjectType().isSubtypeOf(ACSObject.BASE_DATA_OBJECT_TYPE),
"I can only check permissions on ACS Objects - this domain Object is not a subtype of ACSObject ");
PermissionDescriptor permission = new PermissionDescriptor(privilege,(ACSObject) dobj,party);
actionVisible = PermissionService.checkPermission(permission);
}
return actionVisible;
} }
} }
}

View File

@ -25,8 +25,15 @@ import com.arsdigita.bebop.parameters.IntegerParameter;
import com.arsdigita.domain.DomainObject; import com.arsdigita.domain.DomainObject;
import com.arsdigita.domain.DomainCollection; import com.arsdigita.domain.DomainCollection;
import com.arsdigita.domain.DomainObjectXMLRenderer; import com.arsdigita.domain.DomainObjectXMLRenderer;
import com.arsdigita.kernel.ACSObject;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.kernel.Party;
import com.arsdigita.kernel.permissions.PermissionDescriptor;
import com.arsdigita.kernel.permissions.PermissionService;
import com.arsdigita.kernel.permissions.PrivilegeDescriptor;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import com.arsdigita.util.Assert;
import com.arsdigita.web.URL; import com.arsdigita.web.URL;
import com.arsdigita.web.ParameterMap; import com.arsdigita.web.ParameterMap;
import com.arsdigita.web.Web; import com.arsdigita.web.Web;
@ -95,12 +102,51 @@ public abstract class AbstractDomainObjectList
Iterator actions = getDomainObjectActions(); Iterator actions = getDomainObjectActions();
while (actions.hasNext()) { while (actions.hasNext()) {
String action = (String)actions.next(); String action = (String)actions.next();
if (isActionVisible(action, dobj, state)) {
Element el = generateActionXML(state, dobj, action); Element el = generateActionXML(state, dobj, action);
objEl.addContent(el); objEl.addContent(el);
} }
}
return objEl; return objEl;
} }
/**
* determine whether this action should be rendered. Default
* implementation returns true unless a privilege has been
* specified for the action in which case a permission check
* is carried out for the current user.
* @param action
* @param dobj
* @param state
* @return
*/
protected boolean isActionVisible (String action, DomainObject dobj, PageState state) {
boolean actionVisible = true;
PrivilegeDescriptor privilege = getDomainObjectActionPrivilege(action);
if (privilege != null) {
Party party = Kernel.getContext().getParty();
if (party == null) {
party = Kernel.getPublicUser();
}
Assert
.truth(
dobj.getObjectType().isSubtypeOf(
ACSObject.BASE_DATA_OBJECT_TYPE),
"I can only check permissions on ACS Objects - this domain Object is not a subtype of ACSObject ");
PermissionDescriptor permission = new PermissionDescriptor(
privilege, (ACSObject) dobj, party);
actionVisible = PermissionService.checkPermission(permission);
}
return actionVisible;
}
protected Element generatePaginatorXML(PageState state, protected Element generatePaginatorXML(PageState state,
DomainCollection objs) { DomainCollection objs) {
Integer pageNumberVal = (Integer)state.getValue(m_pageNumber); Integer pageNumberVal = (Integer)state.getValue(m_pageNumber);