cancel
Showing results for 
Search instead for 
Did you mean: 

I want Versioning done or Updated on Documents with Aspect cm:versionable

piyush48
Star Contributor
Star Contributor

Hi  All,

I want to disable Versioning for all the documents without cm:versionable aspect that is to disable upload new Version button etc. Only documents with cm:versionable aspect can only be versioned as of my requirement.

Please anyone can provide guidelines or steps if possible.

Thanks and Regards,

Piyush

5 REPLIES 5

abhinavmishra14
World-Class Innovator
World-Class Innovator

cm:versionable aspect is applied by default whenever you create a new node. Not sure you read this post carefully:

https://hub.alfresco.com/t5/alfresco-content-services-forum/version-history-does-not-include-propert...

It by default sets following properties on the uploaded node:

cm:autoVersion => true - Tells that when the cm:versionable aspect is applied and initial snap shot of the node was taken.

cm:initialVersion => true - Tells that when ever a change is made to the "content of a node" that has the versionable aspect applied a new version will be created.

cm:autoVersionOnUpdateProps => false - Tells that version won't be incremented when properties are updated on a node.

Removing this aspect is not a good idea. I would suggest you to categorize the document (by content type) and set the above properties when nodes are created. 

For example, you have content types "demo:myCustomContent" and "demo:myCustomSupportContent". You want "demo:myCustomContent" to allow display upload new version action and allow versioning on content/property updates. but for "demo:myCustomSupportContent" you don't want "upload new version" action to show and don't want version change on properties update. 

In this case, you can implement a behavior which listens to NodeServicePolicies.OnCreateNodePolicy.onCreateNode event. In the implementation, you can check-----

https://docs.alfresco.com/6.0/references/dev-extension-points-behaviors.html

if [ node has "cm:versionable" aspect and type is "demo:myCustomContent"] then

   set the following properties (
       cm:autoVersionOnUpdateProps => true
) else if [ node has "cm:versionable" aspect and type is "demo:myCustomSupportContent"] then   set the following properties (    
cm:autoVersion => false
cm:autoVersionOnUpdateProps => false
)

Example:

private void setVersionProps(final NodeRef nodeRef) { if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) && DemoModel.MyCustomContent.TYPE.equals(nodeService.getType(nodeRef))) { final Map<QName,Serializable> props = nodeService.getProperties(nodeRef); props.put(ContentModel.PROP_AUTO_VERSION_PROPS, true); nodeService.addProperties(nodeRef, props); } else if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) && DemoModel.MyCustomSupportContent.TYPE.equals(nodeService.getType(nodeRef))) { final Map<QName,Serializable> props = nodeService.getProperties(nodeRef); props.put(ContentModel.PROP_AUTO_VERSION, false); props.put(ContentModel.PROP_AUTO_VERSION_PROPS, false); nodeService.addProperties(nodeRef, props); } }

Add an evaluator for Upload new version action, to check if "cm:autoVersion" and "cm:autoVersionOnUpdateProps" values are true, then show action else hide. This ootb evaluator can be used to test the condition "evaluator.doclib.action.metadataValue"

https://docs.alfresco.com/6.0/concepts/doclib-predefined-evaluators-reference.html

example:

<bean id="evaluator.doclib.action.isNodeAllowedForVersioning" parent="evaluator.doclib.action.metadataValue">
	<property name="accessor" value="node.properties.cm:autoVersion" />
	<property name="comparator">
		<bean class="org.alfresco.web.evaluator.StringEqualsComparator">
			<property name="value" value="true" />
		</bean>
	</property>
</bean>

<bean id="evaluator.doclib.action.isNodeAllowedForVersioningOnPropUpdate" parent="evaluator.doclib.action.metadataValue">
	<property name="accessor" value="node.properties.cm:autoVersionOnUpdateProps" />
	<property name="comparator">
		<bean class="org.alfresco.web.evaluator.StringEqualsComparator">
			<property name="value" value="true" />
		</bean>
	</property>
</bean>
~Abhinav
(ACSCE, AWS SAA, Azure Admin)

Hii @abhinavmishra14 ,

Sorry if I couldnt explain my reuirement properly before. What I need is that intially is that I want to unable global versioning for all as my project is migration type and after all documents are migrated I need to disable the versioning accordingly by removing Cm: versionable to the document or folder that is no one could upload new version or change document version.

Thanks,

Piyush

Even if you are migrating documents, it is not recommeneded to remove the versionable aspect. You will loose the version history of the documents even if its the initial version available.

i would suggest to keep the cm:versionable aspect as is and set the properties (cm:autoVersion, cm:autoVersionOnUpdateProps) to false after you are done with migration. 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

Hi @abhinavmishra14 ,

Thanks for making me understand correctly how things work with versioning. After disabling cm:autoVersion, cm:autoVersionOnUpdateProps will no user be able to upload new version because i tried it and i can able to upload new version through upload new version button and thus my requirement of disabling versioning after migration is not fulfilled.

Thanks,

Piyush

After you set the properties, you can hide/disable/put restrictions on upload new version action. Check the bottom of this thread: https://hub.alfresco.com/t5/alfresco-content-services-forum/i-want-versioning-done-or-updated-on-doc...

~Abhinav
(ACSCE, AWS SAA, Azure Admin)