In the past, we published some blog posts about public shared content functionality in Alfresco Share, and the implications of having undesired and uncontrolled public content in production enviroments.
In the previous posts, we tried to help Alfresco administrators to control the urls published by final users, via simple Alfresco FTS queries or even with a virtual folder template. But, in many situations we would like some kind of expiration date for that public content. In that case, we need:
cm:effectivity
cm:from
cm:to
<!-- Registration of JS content behaviour on Add Aspect--> <bean id="OnAddAspectPolicyOnQshared" class="org.alfresco.repo.policy.registration.ClassPolicyRegistration" parent="policyRegistration"> <property name="policyName"> <value>{http://www.alfresco.org}onAddAspect</value> </property> <property name="className"> <value>{http://www.alfresco.org/model/qshare/1.0}shared</value> </property> <property name="behaviour"> <bean class="org.alfresco.repo.jscript.ScriptBehaviour" parent="scriptBehaviour"> <property name="location"> <bean class="org.alfresco.repo.jscript.ClasspathScriptLocation"> <constructor-arg> <value>alfresco/resources/scripts/add-aspect-effectivity.js</value> </constructor-arg> </bean> </property> </bean> </property> </bean>
// // add-aspect-effectivity.js // // Effectivity script for custom behaviour on adding aspect qshared // function getFormattedDate(mydate) { var str = mydate.getFullYear() + "-" + (mydate.getMonth() + 1) + "-" + mydate.getDate() return str; } // Have a look at the behaviour object that should have been passed if (behaviour == null) { logger.log("The behaviour object has not been set."); scriptFailed = true; } // Check the name of the behaviour if (behaviour.name == null && behaviour.name != "onUpdateProperties") { logger.log("The behaviour name has not been set correctly."); scriptFailed = true; } else { logger.log("Behaviour name: " + behaviour.name); //logger.log("behav:"+behaviour); } // Check behaviour arguments if (behaviour.args == null) { logger.log("The args have not been set."); scriptFailed = true; } else { var node = behaviour.args[0]; var before = behaviour.args[1]; var after = behaviour.args[2]; var date1 = new Date(); var date2 = new Date(); date2.setDate(date2.getDate()+30); node.addAspect("cm:effectivity"); node.properties["cm:from"] = getFormattedDate(date1); node.properties["cm:to"] = getFormattedDate(date2); logger.warn("[zk] Setting effectivity sharing to: " + getFormattedDate(date2) ); node.save(); }
qshare:shared
var nodes = search.luceneSearch('ASPECT:"qshare:shared" AND @cm\\:to:[MIN TO NOW]'); var count = 0; logger.warn("[zk] Starting effectivity qshared:"); for each(var node in nodes) { count = count + 1; logger.warn(count + ": "+node.displayPath+"/"+node.name); logger.warn("[zk] This public url is expired --> "+node.properties["cm:to"]); logger.warn("[zk] Cleaning the aspect.."); node.removeAspect("qshare:shared"); //node.removeAspect("cm:effectivity"); node.save(); } logger.warn("[zk] Done.");
The full details on the customization are published in our corporate github: