Disable Download on a File

cancel
Showing results for 
Search instead for 
Did you mean: 

Disable Download on a File

sakshik
Established Member
1 1 4,712

Problem: You don't want to disable download for all the files. You want to have a control over disabling download action on particular files in alfresco.

Solution: Use aspects. We will conditionalize disabling download action on an aspect and then apply that aspect to the file for which we want to disable download.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

Here are the steps:

First: Disable the top right corner Download button

Step 1) Stop alfresco server

Step 2) Create an XML file called hide-download-pdf.xml under

<ALF_HOME>\tomcat\shared\classes\alfresco\web-extension\site-data\extension:

<extension>
   <modules>
      <module>
         <id>Hide Download Buttons</id>
         <auto-deploy>true</auto-deploy>
         <customizations>
            <customization>
               <targetPackageRoot>org.alfresco</targetPackageRoot>
               <sourcePackageRoot>com.someco</sourcePackageRoot>
            </customization>
         </customizations>
      </module>
   </modules>

</extension>

Step 3) Create a file node-header.get.js with the following under 

<ALF_HOME>\tomcat\shared\classes\alfresco\web-extension/site-webscripts/com/someco/components/node-details

<import resource="classpath:/alfresco/templates/org/alfresco/import/alfresco-util.js">
var nodeDetails = AlfrescoUtil.getNodeDetails(model.nodeRef, model.site, null, model.libraryRoot);
var count = nodeDetails.item.node.properties["cm:autoVersion"];

if (count != undefined)
{
model.showDownload = "false";
}

Step 4) Restart alfresco server.

Go to a file in Alfresco -> Click Manage Aspects from the details options -> add cm:versionable aspect -> Hit Apply changes. You will see that the Download button will disappear

 

Second: Disable the Download action from browse options:

 

Step 1) Stop alfresco server

Step 2) To create a custom evaluator for an aspect, create an XML file custom-action-context.xml under
<ALF HOME>/tomcat/shared/classes/alfresco/web-extension folder.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="custom.evaluator.doclib.hasversionable" class="org.alfresco.web.evaluator.HasAspectEvaluator">
<property name="aspects">
<list>
<value>cm:versionable</value>
</list>
</property>
</bean>
</beans>

Step 3) Add the following to share-config-custom.xml under

<config evaluator="string-compare" condition="DocLibActions">
<actions>
<action id="document-download" type="link" label="actions.document.download">
<param name="href">{downloadUrl}</param>
<evaluator negate=true>custom.evaluator.doclib.hasversionable</evaluator >
</action>
</actions>

Step 4) Restart alfresco server.

Go to a file in Alfresco -> Click Manage Aspects from the details options -> add cm:versionable aspect -> Hit Apply changes. You will see that the Download action from browse menu disappeared

1 Comment