mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
AVM locking UI evaluators. Actions such as Edit, Update are hidden if the item is locked.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6021 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing
|
||||
*/
|
||||
package org.alfresco.web.action.evaluator;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.service.cmr.avm.locking.AVMLockingService;
|
||||
import org.alfresco.web.action.ActionEvaluator;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.app.servlet.FacesHelper;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.bean.wcm.AVMBrowseBean;
|
||||
|
||||
/**
|
||||
* Evaluator to return if a item is accessable due to a WCM user level lock.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class WCMLockEvaluator implements ActionEvaluator
|
||||
{
|
||||
/**
|
||||
* @return true if the item is not locked by another user
|
||||
*/
|
||||
public boolean evaluate(Node node)
|
||||
{
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
AVMLockingService avmLockService = Repository.getServiceRegistry(fc).getAVMLockingService();
|
||||
AVMBrowseBean avmBrowseBean = (AVMBrowseBean)FacesHelper.getManagedBean(fc, AVMBrowseBean.BEAN_NAME);
|
||||
|
||||
String path = AVMNodeConverter.ToAVMVersionPath(node.getNodeRef()).getSecond();
|
||||
String username = Application.getCurrentUser(fc).getUserName();
|
||||
|
||||
return avmLockService.hasAccess(avmBrowseBean.getWebProject().getNodeRef(), path, username);
|
||||
}
|
||||
}
|
@@ -30,7 +30,6 @@ import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.repo.avm.wf.AVMSubmittedAspect;
|
||||
import org.alfresco.service.cmr.avm.AVMService;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.web.action.ActionEvaluator;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.bean.wcm.AVMUtil;
|
||||
@@ -41,12 +40,15 @@ import org.alfresco.web.bean.wcm.AVMUtil;
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class WCMWorkflowDeletedEvaluator implements ActionEvaluator
|
||||
public class WCMWorkflowDeletedEvaluator extends WCMLockEvaluator
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
|
||||
*/
|
||||
public boolean evaluate(final Node node)
|
||||
{
|
||||
boolean proceed = false;
|
||||
if (super.evaluate(node))
|
||||
{
|
||||
final FacesContext facesContext = FacesContext.getCurrentInstance();
|
||||
final AVMService avmService = Repository.getServiceRegistry(facesContext).getAVMService();
|
||||
@@ -56,7 +58,9 @@ public class WCMWorkflowDeletedEvaluator implements ActionEvaluator
|
||||
|
||||
// evaluate to true if we are within a workflow store (i.e. list of resources in the task
|
||||
// dialog) or not part of an already in-progress workflow
|
||||
return (AVMUtil.isWorkflowStore(AVMUtil.getStoreName(path)) ||
|
||||
proceed = (AVMUtil.isWorkflowStore(AVMUtil.getStoreName(path)) ||
|
||||
avmService.hasAspect(version, path, AVMSubmittedAspect.ASPECT) == false);
|
||||
}
|
||||
return proceed;
|
||||
}
|
||||
}
|
@@ -30,7 +30,6 @@ import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.repo.avm.wf.AVMSubmittedAspect;
|
||||
import org.alfresco.service.cmr.avm.AVMService;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.web.action.ActionEvaluator;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.bean.wcm.AVMUtil;
|
||||
@@ -40,12 +39,15 @@ import org.alfresco.web.bean.wcm.AVMUtil;
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class WCMWorkflowEvaluator implements ActionEvaluator
|
||||
public class WCMWorkflowEvaluator extends WCMLockEvaluator
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
|
||||
*/
|
||||
public boolean evaluate(final Node node)
|
||||
{
|
||||
boolean proceed = false;
|
||||
if (super.evaluate(node))
|
||||
{
|
||||
final FacesContext facesContext = FacesContext.getCurrentInstance();
|
||||
final AVMService avmService = Repository.getServiceRegistry(facesContext).getAVMService();
|
||||
@@ -55,8 +57,10 @@ public class WCMWorkflowEvaluator implements ActionEvaluator
|
||||
|
||||
// evaluate to true if we are not deleted and within a workflow store (i.e. list of resources
|
||||
// in the task dialog) or not part of an already in-progress workflow
|
||||
return ((AVMUtil.isWorkflowStore(AVMUtil.getStoreName(path)) ||
|
||||
proceed = ((AVMUtil.isWorkflowStore(AVMUtil.getStoreName(path)) ||
|
||||
avmService.hasAspect(version, path, AVMSubmittedAspect.ASPECT) == false) &&
|
||||
avmService.lookup(version, path) != null);
|
||||
}
|
||||
return proceed;
|
||||
}
|
||||
}
|
||||
|
@@ -43,6 +43,7 @@ import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.WCMAppModel;
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.service.cmr.avm.AVMService;
|
||||
import org.alfresco.service.cmr.avm.locking.AVMLockingService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
@@ -88,8 +89,8 @@ public class CreateWebsiteWizard extends BaseWizardBean
|
||||
private static Log logger = LogFactory.getLog(CreateWebsiteWizard.class);
|
||||
|
||||
protected boolean editMode = false;
|
||||
|
||||
protected String dnsName;
|
||||
|
||||
protected String title;
|
||||
protected String name;
|
||||
protected String description;
|
||||
@@ -99,6 +100,7 @@ public class CreateWebsiteWizard extends BaseWizardBean
|
||||
protected AVMService avmService;
|
||||
protected WorkflowService workflowService;
|
||||
protected PersonService personService;
|
||||
protected AVMLockingService avmLockingService;
|
||||
|
||||
/** datamodel for table of selected forms */
|
||||
protected DataModel formsDataModel = null;
|
||||
@@ -217,6 +219,9 @@ public class CreateWebsiteWizard extends BaseWizardBean
|
||||
// navigate to the Websites folder so we can see the newly created folder
|
||||
this.navigator.setCurrentNodeId(websiteParent.getId());
|
||||
|
||||
// inform the locking service about this new instance
|
||||
this.avmLockingService.addWebProject(avmStore);
|
||||
|
||||
outcome = AlfrescoNavigationHandler.CLOSE_WIZARD_OUTCOME;
|
||||
}
|
||||
return outcome;
|
||||
@@ -371,6 +376,14 @@ public class CreateWebsiteWizard extends BaseWizardBean
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param avmLockingService The AVMLockingService to set
|
||||
*/
|
||||
public void setAvmLockingService(AVMLockingService avmLockingService)
|
||||
{
|
||||
this.avmLockingService = avmLockingService;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Bean getters and setters
|
||||
|
@@ -26,7 +26,9 @@ package org.alfresco.web.bean.wcm;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
@@ -34,6 +36,9 @@ import javax.faces.context.FacesContext;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.service.cmr.avm.AVMService;
|
||||
import org.alfresco.service.cmr.avm.locking.AVMLock;
|
||||
import org.alfresco.service.cmr.avm.locking.AVMLockingException;
|
||||
import org.alfresco.service.cmr.avm.locking.AVMLockingService;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.model.FileExistsException;
|
||||
@@ -55,7 +60,7 @@ public class EditFilePropertiesDialog extends EditContentPropertiesDialog
|
||||
{
|
||||
protected AVMBrowseBean avmBrowseBean;
|
||||
protected AVMService avmService;
|
||||
|
||||
protected AVMLockingService avmLockingService;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Bean property getters and setters
|
||||
@@ -76,6 +81,14 @@ public class EditFilePropertiesDialog extends EditContentPropertiesDialog
|
||||
this.avmService = avmService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param avmLockingService The AVMLockingService to set
|
||||
*/
|
||||
public void setAvmLockingService(AVMLockingService avmLockingService)
|
||||
{
|
||||
this.avmLockingService = avmLockingService;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Dialog implementation
|
||||
@@ -93,6 +106,27 @@ public class EditFilePropertiesDialog extends EditContentPropertiesDialog
|
||||
throws Exception
|
||||
{
|
||||
NodeRef nodeRef = this.editableNode.getNodeRef();
|
||||
String webProjectId = this.avmBrowseBean.getWebProject().getStoreId();
|
||||
String avmPath = AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond();
|
||||
String[] storePath = avmPath.split(":");
|
||||
String username = Application.getCurrentUser(context).getUserName();
|
||||
|
||||
try
|
||||
{
|
||||
if (this.avmLockingService.hasAccess(webProjectId, avmPath, username) == false)
|
||||
{
|
||||
throw new AVMLockingException("avmlockservice.locked", new Object[]{avmPath});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.avmLockingService.getLock(webProjectId, avmPath) == null)
|
||||
{
|
||||
List<String> owners = new ArrayList<String>(1);
|
||||
owners.add(username);
|
||||
AVMLock lock = new AVMLock(webProjectId, storePath[0], storePath[1], AVMLockingService.Type.DISCRETIONARY, owners);
|
||||
this.avmLockingService.lockPath(lock);
|
||||
}
|
||||
}
|
||||
Map<String, Object> editedProps = this.editableNode.getProperties();
|
||||
|
||||
// handle the name property separately, it is a special case for AVM nodes
|
||||
@@ -123,7 +157,7 @@ public class EditFilePropertiesDialog extends EditContentPropertiesDialog
|
||||
// add the "titled" aspect if required, properties will get set below
|
||||
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TITLED) == false)
|
||||
{
|
||||
nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
|
||||
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
|
||||
}
|
||||
|
||||
// add the remaining properties
|
||||
@@ -165,6 +199,14 @@ public class EditFilePropertiesDialog extends EditContentPropertiesDialog
|
||||
this.fileFolderService.rename(nodeRef, name);
|
||||
editedProps.put(ContentModel.PROP_NAME.toString(), name);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (this.avmLockingService.getLock(webProjectId, avmPath) != null)
|
||||
{
|
||||
this.avmLockingService.removeLock(webProjectId, avmPath);
|
||||
}
|
||||
}
|
||||
|
||||
return outcome;
|
||||
}
|
||||
|
@@ -25,7 +25,10 @@
|
||||
package org.alfresco.web.ui.repo.component.evaluator;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.el.ValueBinding;
|
||||
|
||||
import org.alfresco.config.ConfigException;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.web.action.ActionEvaluator;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.ui.common.component.evaluator.BaseEvaluator;
|
||||
@@ -72,6 +75,7 @@ public class ActionInstanceEvaluator extends BaseEvaluator
|
||||
// standard component attributes are restored by the super class
|
||||
super.restoreState(context, values[0]);
|
||||
this.evaluator = (ActionEvaluator)values[1];
|
||||
this.evaluatorClassName = (String)values[2];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,10 +83,11 @@ public class ActionInstanceEvaluator extends BaseEvaluator
|
||||
*/
|
||||
public Object saveState(FacesContext context)
|
||||
{
|
||||
Object values[] = new Object[2];
|
||||
Object values[] = new Object[] {
|
||||
// standard component attributes are saved by the super class
|
||||
values[0] = super.saveState(context);
|
||||
values[1] = this.evaluator;
|
||||
super.saveState(context),
|
||||
this.evaluator,
|
||||
this.evaluatorClassName };
|
||||
return (values);
|
||||
}
|
||||
|
||||
@@ -91,6 +96,24 @@ public class ActionInstanceEvaluator extends BaseEvaluator
|
||||
*/
|
||||
public ActionEvaluator getEvaluator()
|
||||
{
|
||||
if (this.evaluator == null)
|
||||
{
|
||||
Object objEvaluator;
|
||||
try
|
||||
{
|
||||
Class clazz = Class.forName(getEvaluatorClassName());
|
||||
objEvaluator = clazz.newInstance();
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unable to construct action evaluator: " + getEvaluatorClassName());
|
||||
}
|
||||
if (objEvaluator instanceof ActionEvaluator == false)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Must implement ActionEvaluator interface: " + getEvaluatorClassName());
|
||||
}
|
||||
this.evaluator = (ActionEvaluator)objEvaluator;
|
||||
}
|
||||
return this.evaluator;
|
||||
}
|
||||
|
||||
@@ -102,6 +125,27 @@ public class ActionInstanceEvaluator extends BaseEvaluator
|
||||
this.evaluator = evaluator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the evaluatorClassName
|
||||
*/
|
||||
public String getEvaluatorClassName()
|
||||
{
|
||||
ValueBinding vb = getValueBinding("evaluatorClassName");
|
||||
if (vb != null)
|
||||
{
|
||||
this.evaluatorClassName = (String)vb.getValue(getFacesContext());
|
||||
}
|
||||
return this.evaluatorClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param evaluatorClassName the evaluatorClassName to set
|
||||
*/
|
||||
public void setEvaluatorClassName(String evaluatorClassName)
|
||||
{
|
||||
this.evaluatorClassName = evaluatorClassName;
|
||||
}
|
||||
|
||||
private ActionEvaluator evaluator;
|
||||
private String evaluatorClassName;
|
||||
}
|
||||
|
@@ -40,4 +40,36 @@ public class ActionInstanceEvaluatorTag extends GenericEvaluatorTag
|
||||
{
|
||||
return "org.alfresco.faces.ActionInstanceEvaluator";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.faces.webapp.UIComponentTag#setProperties(javax.faces.component.UIComponent)
|
||||
*/
|
||||
protected void setProperties(UIComponent component)
|
||||
{
|
||||
super.setProperties(component);
|
||||
setStringProperty(component, "evaluatorClassName", this.evaluatorClassName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.servlet.jsp.tagext.Tag#release()
|
||||
*/
|
||||
public void release()
|
||||
{
|
||||
super.release();
|
||||
this.evaluatorClassName = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the evaluatorClassName
|
||||
*
|
||||
* @param evaluatorClassName the evaluatorClassName
|
||||
*/
|
||||
public void setEvaluatorClassName(String evaluatorClassName)
|
||||
{
|
||||
this.evaluatorClassName = evaluatorClassName;
|
||||
}
|
||||
|
||||
|
||||
/** the evaluatorClassName */
|
||||
private String evaluatorClassName;
|
||||
}
|
||||
|
@@ -2746,6 +2746,10 @@
|
||||
<property-name>personService</property-name>
|
||||
<value>#{PersonService}</value>
|
||||
</managed-property>
|
||||
<managed-property>
|
||||
<property-name>avmLockingService</property-name>
|
||||
<value>#{AVMLockingService}</value>
|
||||
</managed-property>
|
||||
</managed-bean>
|
||||
|
||||
<managed-bean>
|
||||
@@ -3196,6 +3200,10 @@
|
||||
<property-name>avmService</property-name>
|
||||
<value>#{AVMService}</value>
|
||||
</managed-property>
|
||||
<managed-property>
|
||||
<property-name>avmLockingService</property-name>
|
||||
<value>#{AVMLockingService}</value>
|
||||
</managed-property>
|
||||
<managed-property>
|
||||
<property-name>fileFolderService</property-name>
|
||||
<value>#{FileFolderService}</value>
|
||||
|
@@ -1466,6 +1466,36 @@
|
||||
</attribute>
|
||||
</tag>
|
||||
|
||||
<tag>
|
||||
<name>actionInstanceEvaluator</name>
|
||||
<tag-class>org.alfresco.web.ui.repo.tag.evaluator.ActionInstanceEvaluatorTag</tag-class>
|
||||
<body-content>JSP</body-content>
|
||||
|
||||
<attribute>
|
||||
<name>id</name>
|
||||
<required>false</required>
|
||||
<rtexprvalue>true</rtexprvalue>
|
||||
</attribute>
|
||||
|
||||
<attribute>
|
||||
<name>value</name>
|
||||
<required>true</required>
|
||||
<rtexprvalue>true</rtexprvalue>
|
||||
</attribute>
|
||||
|
||||
<attribute>
|
||||
<name>evaluatorClassName</name>
|
||||
<required>true</required>
|
||||
<rtexprvalue>true</rtexprvalue>
|
||||
</attribute>
|
||||
|
||||
<attribute>
|
||||
<name>binding</name>
|
||||
<required>false</required>
|
||||
<rtexprvalue>true</rtexprvalue>
|
||||
</attribute>
|
||||
</tag>
|
||||
|
||||
<tag>
|
||||
<name>multiValueSelector</name>
|
||||
<tag-class>org.alfresco.web.ui.repo.tag.MultiValueSelectorTag</tag-class>
|
||||
|
@@ -151,7 +151,9 @@
|
||||
<h:panelGroup id="props-panel-facets">
|
||||
<f:facet name="title">
|
||||
<r:permissionEvaluator value="#{FileDetailsBean.document}" allow="Write">
|
||||
<r:actionInstanceEvaluator value="#{FileDetailsBean.document}" evaluatorClassName="org.alfresco.web.action.evaluator.WCMWorkflowEvaluator">
|
||||
<a:actionLink id="titleLink1" value="#{msg.modify}" showLink="false" image="/images/icons/Change_details.gif" action="dialog:editAvmFileProperties" />
|
||||
</r:actionInstanceEvaluator>
|
||||
</r:permissionEvaluator>
|
||||
</f:facet>
|
||||
</h:panelGroup>
|
||||
|
Reference in New Issue
Block a user