NIHVIVO-1332 Move edit links following object property statement (UI team request). Compute edit and delete access rights in advance, since edit url may need a deleteProhibited param.

This commit is contained in:
rjy7 2011-01-11 18:02:32 +00:00
parent 64fc6c7e7f
commit b7ccda71aa
2 changed files with 34 additions and 16 deletions

View file

@ -2,6 +2,8 @@
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual; package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -24,28 +26,45 @@ public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
private static final String EDIT_PATH = "edit/editRequestDispatch.jsp"; private static final String EDIT_PATH = "edit/editRequestDispatch.jsp";
private static enum EditAccess {
EDIT, DELETE;
}
private String subjectUri; // we'll use these to make the edit links private String subjectUri; // we'll use these to make the edit links
private String propertyUri; private String propertyUri;
private Map<String, String> data; private Map<String, String> data;
private EditingHelper editingHelper;
private String objectUri = null; private String objectUri = null;
private ObjectPropertyStatement objectPropertyStatement = null; private List<EditAccess> editAccessList;
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri, ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri,
String objectKey, Map<String, String> data, EditingHelper editingHelper) { String objectKey, Map<String, String> data, EditingHelper editingHelper) {
this.subjectUri = subjectUri; this.subjectUri = subjectUri;
this.propertyUri = propertyUri; this.propertyUri = propertyUri;
this.data = data; this.data = data;
this.editingHelper = editingHelper;
// If the editingHelper is non-null, we are in edit mode, so create the necessary objects. // If the editingHelper is non-null, we are in edit mode, so create the list of editing permissions.
if (this.editingHelper != null) { // We do this now rather than in getEditUrl() and getDeleteUrl(), because getEditUrl() also needs to know
// whether a delete is allowed.
if (editingHelper != null) {
objectUri = data.get(objectKey); objectUri = data.get(objectKey);
objectPropertyStatement = new ObjectPropertyStatementImpl(subjectUri, propertyUri, objectUri); editAccessList = new ArrayList<EditAccess>(); // limit size to number of elements in EditAccess
ObjectPropertyStatement objectPropertyStatement = new ObjectPropertyStatementImpl(subjectUri, propertyUri, objectUri);
// Determine whether the statement can be edited
RequestedAction action = new EditObjPropStmt(objectPropertyStatement);
PolicyDecision decision = editingHelper.getPolicy().isAuthorized(editingHelper.getIds(), action);
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
editAccessList.add(EditAccess.EDIT);
} }
// Determine whether the statement can be deleted
action = new DropObjectPropStmt(subjectUri, propertyUri, objectUri);
decision = editingHelper.getPolicy().isAuthorized(editingHelper.getIds(), action);
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
editAccessList.add(EditAccess.DELETE);
}
}
} }
@ -57,13 +76,14 @@ public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
public String getEditUrl() { public String getEditUrl() {
String editUrl = ""; String editUrl = "";
RequestedAction editAction = new EditObjPropStmt(objectPropertyStatement); if (editAccessList.contains(EditAccess.EDIT)) {
PolicyDecision decision = editingHelper.getPolicy().isAuthorized(editingHelper.getIds(), editAction);
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
ParamMap params = new ParamMap( ParamMap params = new ParamMap(
"subjectUri", subjectUri, "subjectUri", subjectUri,
"predicateUri", propertyUri, "predicateUri", propertyUri,
"objectUri", objectUri); "objectUri", objectUri);
if (! editAccessList.contains(EditAccess.DELETE)) {
params.put("deleteProhibited", "prohibited");
}
editUrl = UrlBuilder.getUrl(EDIT_PATH, params); editUrl = UrlBuilder.getUrl(EDIT_PATH, params);
} }
@ -72,9 +92,7 @@ public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
public String getDeleteUrl() { public String getDeleteUrl() {
String deleteUrl = ""; String deleteUrl = "";
RequestedAction dropAction = new DropObjectPropStmt(subjectUri, propertyUri, objectUri); if (editAccessList.contains(EditAccess.DELETE)) {
PolicyDecision decision = editingHelper.getPolicy().isAuthorized(editingHelper.getIds(), dropAction);
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
ParamMap params = new ParamMap( ParamMap params = new ParamMap(
"subjectUri", subjectUri, "subjectUri", subjectUri,
"predicateUri", propertyUri, "predicateUri", propertyUri,

View file

@ -34,8 +34,8 @@
<#macro propertyListItem statement showEditingLinks> <#macro propertyListItem statement showEditingLinks>
<li role="listitem"> <li role="listitem">
<@editingLinks statement showEditingLinks />
<#nested> <#nested>
<@editingLinks statement showEditingLinks />
</li> </li>
</#macro> </#macro>