REPO-164 / REPO-1150: fix minor regress (eg. if recursively locking nodes via includeChildren)

-  MNT-16446, MNT-14945

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129826 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2016-08-24 12:11:40 +00:00
parent 215660d5a3
commit d00a88e618
2 changed files with 82 additions and 17 deletions

View File

@@ -83,6 +83,7 @@
<property name="behaviourFilter" ref="policyBehaviourFilter" /> <property name="behaviourFilter" ref="policyBehaviourFilter" />
<property name="permissionService" ref="PermissionService"/> <property name="permissionService" ref="PermissionService"/>
<property name="lockService" ref="LockService"/> <property name="lockService" ref="LockService"/>
<property name="dictionaryService" ref="DictionaryService"/>
</bean> </bean>
<!-- Policies/behaviours for forum-related nodes --> <!-- Policies/behaviours for forum-related nodes -->

View File

@@ -54,6 +54,8 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.site.SiteModel; import org.alfresco.repo.site.SiteModel;
import org.alfresco.service.cmr.activities.ActivityService; import org.alfresco.service.cmr.activities.ActivityService;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.lock.LockService; import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockStatus; import org.alfresco.service.cmr.lock.LockStatus;
import org.alfresco.service.cmr.lock.NodeLockedException; import org.alfresco.service.cmr.lock.NodeLockedException;
@@ -69,6 +71,7 @@ import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.site.SiteService; import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.EqualsHelper;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.alfresco.util.registry.NamedObjectRegistry; import org.alfresco.util.registry.NamedObjectRegistry;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@@ -83,8 +86,9 @@ import org.springframework.extensions.surf.util.AbstractLifecycleBean;
* @since 4.0 * @since 4.0
*/ */
// TODO consolidate this and ScriptCommentService and the implementations of comments.* web scripts. // TODO consolidate this and ScriptCommentService and the implementations of comments.* web scripts.
public class CommentServiceImpl extends AbstractLifecycleBean public class CommentServiceImpl extends AbstractLifecycleBean implements CommentService,
implements CommentService, NodeServicePolicies.BeforeDeleteNodePolicy, NodeServicePolicies.BeforeUpdateNodePolicy NodeServicePolicies.BeforeDeleteNodePolicy,
NodeServicePolicies.OnUpdatePropertiesPolicy
{ {
private static Log logger = LogFactory.getLog(CommentServiceImpl.class); private static Log logger = LogFactory.getLog(CommentServiceImpl.class);
@@ -105,6 +109,7 @@ public class CommentServiceImpl extends AbstractLifecycleBean
private BehaviourFilter behaviourFilter; private BehaviourFilter behaviourFilter;
private PermissionService permissionService; private PermissionService permissionService;
private LockService lockService; private LockService lockService;
private DictionaryService dictionaryService;
private NamedObjectRegistry<CannedQueryFactory<? extends Object>> cannedQueryRegistry; private NamedObjectRegistry<CannedQueryFactory<? extends Object>> cannedQueryRegistry;
@@ -153,6 +158,11 @@ public class CommentServiceImpl extends AbstractLifecycleBean
this.lockService = lockService; this.lockService = lockService;
} }
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
@Override @Override
protected void onBootstrap(ApplicationEvent event) protected void onBootstrap(ApplicationEvent event)
{ {
@@ -196,12 +206,16 @@ public class CommentServiceImpl extends AbstractLifecycleBean
{ {
this.lockService = (LockService)ctx.getBean("LockService"); this.lockService = (LockService)ctx.getBean("LockService");
} }
if (this.dictionaryService == null)
{
this.dictionaryService = (DictionaryService)ctx.getBean("DictionaryService");
}
} }
this.policyComponent.bindClassBehaviour( this.policyComponent.bindClassBehaviour(
NodeServicePolicies.BeforeUpdateNodePolicy.QNAME, NodeServicePolicies.OnUpdatePropertiesPolicy.QNAME,
ForumModel.TYPE_POST, ForumModel.TYPE_POST,
new JavaBehaviour(this, "beforeUpdateNode")); new JavaBehaviour(this, "onUpdateProperties"));
this.policyComponent.bindClassBehaviour( this.policyComponent.bindClassBehaviour(
NodeServicePolicies.BeforeDeleteNodePolicy.QNAME, NodeServicePolicies.BeforeDeleteNodePolicy.QNAME,
ForumModel.TYPE_POST, ForumModel.TYPE_POST,
@@ -603,18 +617,37 @@ public class CommentServiceImpl extends AbstractLifecycleBean
} }
@Override @Override
public void beforeUpdateNode(NodeRef commentNodeRef) public void onUpdateProperties(NodeRef commentNodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
{ {
NodeRef discussableNodeRef = getDiscussableAncestor(commentNodeRef); NodeRef discussableNodeRef = getDiscussableAncestor(commentNodeRef);
if (discussableNodeRef != null) if (discussableNodeRef != null)
{ {
if (behaviourFilter.isEnabled(ContentModel.ASPECT_LOCKABLE) if (behaviourFilter.isEnabled(ContentModel.ASPECT_LOCKABLE)
&& isWorkingCopyOrLocked(discussableNodeRef)) && isWorkingCopyOrLocked(discussableNodeRef))
{
List<QName> changedProperties = getChangedProperties(before, after);
// check if comment updated (rather than some other change, eg. addition of lockable aspect only)
boolean commentUpdated = false;
for (QName changedProperty : changedProperties)
{
PropertyDefinition propertyDef = dictionaryService.getProperty(changedProperty);
if (propertyDef != null)
{
if (propertyDef.getContainerClass().getName().equals(ContentModel.TYPE_CONTENT))
{
commentUpdated = true;
break;
}
}
}
if (commentUpdated)
{ {
throw new NodeLockedException(discussableNodeRef); throw new NodeLockedException(discussableNodeRef);
} }
else }
{
boolean canEdit = canEditPermission(commentNodeRef); boolean canEdit = canEditPermission(commentNodeRef);
if (! canEdit) if (! canEdit)
{ {
@@ -622,6 +655,39 @@ public class CommentServiceImpl extends AbstractLifecycleBean
} }
} }
} }
// see also RenditionedAspect
private List<QName> getChangedProperties(Map<QName, Serializable> before, Map<QName, Serializable> after)
{
List<QName> results = new ArrayList<QName>();
for (QName propQName : before.keySet())
{
if (after.keySet().contains(propQName) == false)
{
// property was deleted
results.add(propQName);
}
else
{
Serializable beforeValue = before.get(propQName);
Serializable afterValue = after.get(propQName);
if (EqualsHelper.nullSafeEquals(beforeValue, afterValue) == false)
{
// Property was changed
results.add(propQName);
}
}
}
for (QName propQName : after.keySet())
{
if (before.containsKey(propQName) == false)
{
// property was added
results.add(propQName);
}
}
return results;
} }
@Override @Override
@@ -635,8 +701,7 @@ public class CommentServiceImpl extends AbstractLifecycleBean
{ {
throw new NodeLockedException(discussableNodeRef); throw new NodeLockedException(discussableNodeRef);
} }
else
{
boolean canDelete = canDeletePermission(commentNodeRef); boolean canDelete = canDeletePermission(commentNodeRef);
if (! canDelete) if (! canDelete)
{ {
@@ -645,4 +710,3 @@ public class CommentServiceImpl extends AbstractLifecycleBean
} }
} }
} }
}