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:
parent
64fc6c7e7f
commit
b7ccda71aa
2 changed files with 34 additions and 16 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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 enum EditAccess {
|
||||
EDIT, DELETE;
|
||||
}
|
||||
|
||||
private String subjectUri; // we'll use these to make the edit links
|
||||
private String propertyUri;
|
||||
private Map<String, String> data;
|
||||
|
||||
private EditingHelper editingHelper;
|
||||
private String objectUri = null;
|
||||
private ObjectPropertyStatement objectPropertyStatement = null;
|
||||
|
||||
private List<EditAccess> editAccessList;
|
||||
|
||||
ObjectPropertyStatementTemplateModel(String subjectUri, String propertyUri,
|
||||
String objectKey, Map<String, String> data, EditingHelper editingHelper) {
|
||||
this.subjectUri = subjectUri;
|
||||
this.propertyUri = propertyUri;
|
||||
this.data = data;
|
||||
this.editingHelper = editingHelper;
|
||||
|
||||
// If the editingHelper is non-null, we are in edit mode, so create the necessary objects.
|
||||
if (this.editingHelper != null) {
|
||||
// If the editingHelper is non-null, we are in edit mode, so create the list of editing permissions.
|
||||
// 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);
|
||||
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() {
|
||||
String editUrl = "";
|
||||
RequestedAction editAction = new EditObjPropStmt(objectPropertyStatement);
|
||||
PolicyDecision decision = editingHelper.getPolicy().isAuthorized(editingHelper.getIds(), editAction);
|
||||
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
|
||||
if (editAccessList.contains(EditAccess.EDIT)) {
|
||||
ParamMap params = new ParamMap(
|
||||
"subjectUri", subjectUri,
|
||||
"predicateUri", propertyUri,
|
||||
"objectUri", objectUri);
|
||||
if (! editAccessList.contains(EditAccess.DELETE)) {
|
||||
params.put("deleteProhibited", "prohibited");
|
||||
}
|
||||
editUrl = UrlBuilder.getUrl(EDIT_PATH, params);
|
||||
}
|
||||
|
||||
|
@ -72,9 +92,7 @@ public class ObjectPropertyStatementTemplateModel extends BaseTemplateModel {
|
|||
|
||||
public String getDeleteUrl() {
|
||||
String deleteUrl = "";
|
||||
RequestedAction dropAction = new DropObjectPropStmt(subjectUri, propertyUri, objectUri);
|
||||
PolicyDecision decision = editingHelper.getPolicy().isAuthorized(editingHelper.getIds(), dropAction);
|
||||
if (decision != null && decision.getAuthorized() == Authorization.AUTHORIZED) {
|
||||
if (editAccessList.contains(EditAccess.DELETE)) {
|
||||
ParamMap params = new ParamMap(
|
||||
"subjectUri", subjectUri,
|
||||
"predicateUri", propertyUri,
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
|
||||
<#macro propertyListItem statement showEditingLinks>
|
||||
<li role="listitem">
|
||||
<@editingLinks statement showEditingLinks />
|
||||
<#nested>
|
||||
<@editingLinks statement showEditingLinks />
|
||||
</li>
|
||||
</#macro>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue