Hide Download Button for Certain roles

cancel
Showing results for 
Search instead for 
Did you mean: 
piyush48
Established Member

Hide Download Button for Certain roles

Jump to solution

 Hi All,

I want to disable Download button for certain OOTB roles(like Collaborator etc) and allow it for remaining). What should i add to share-config file? Is there any default evaluator for hiding download button and if there how can i hide for certain roles only.

 

 

Thanks,

Piyush

2 Solutions

Accepted Solutions
abhinavmishra14
Advanced

Re: Hide Download Button for Certain roles

Jump to solution

As evaluator parent name indicates "evaluator.doclib.action.groupMembership", it evaluates groups. SiteManager, SiteConsumer,SiteCollaborator and SiteContributor are also groups within the site.

When you go to to manage permissions, Add User/Group, and search for any of the aforementioned name, it would appear as a group. Their names would be like: GROUP_site_test-site_SiteManager, here "test-site" is site short name of a site. Every sites getes these groups when they are created. You can see these groups in Admin Tools> Groups as well by clicking on "" checkbox.

SiteManager, SiteConsumer,SiteCollaborator ,SiteContributor evaluators are working for you because they are evaluated as groups. If you create a folder/file outside of site, you won't see SiteManager, SiteConsumer,SiteCollaborator ,SiteContributor groups when try to manage permissions. You would see users and groups created/available in repository.

In order to use "evaluator.doclib.action.groupMembership" evaluator, create a group via admin tools, add users to the group, go to the manage permissions of the folder/file where you want to apply e.g. Consumer role, go to Add User/Group option and select that particular group and set the Consumer role to it. 

Doc for reference: https://docs.alfresco.com/6.0/tasks/library-item-permissions.html

At last, update the evaluator, for example you created a group named "Restricted", then:

<bean id="evaluator.doclib.action.isRestricted" parent="evaluator.doclib.action.groupMembership">
 <property name="groups">
  <list>
   <value>GROUP_Restricted</value>
  </list>
  </property>
</bean>

and

<bean id="evaluator.doclib.action.isSiteConsumerOrRistricted" parent="evaluator.doclib.action.chainedMatchOne">
      <property name="evaluators">
         <list>
            <ref bean="evaluator.doclib.action.isSiteConsumer" />
            <ref bean="evaluator.doclib.action.isRestricted" />
         </list>
      </property>
    </bean>

At last, update the evaluator config on your actions e.g. "Download action" to use: 

<evaluator>evaluator.doclib.action.isSiteConsumerOrRistricted</evaluator>

To restrict the user with Consumer role for example on a file/folder, "evaluator.doclib.action.groupMembership" won't work straight forward. you would have to create your custom evaluator for this and add custom code to check Consumer role for nodes and then return true/false.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View solution in original post

abhinavmishra14
Advanced

Re: Hide Download Button for Certain roles

Jump to solution

Do it simple:

1- Add this action configuration in your share config custom/extension under  <actions> 

<action id="document-download" type="link" label="actions.document.download">

And add the newly configured evaluator in additon to already available evaluators.

<config evaluator="string-compare" condition="DocLibActions">
      <actions>
         <!-- Download document -->
         <action id="document-download" type="link" label="actions.document.download">
            <param name="href">{downloadUrl}</param>
            <param name="target">_blank</param>
            <evaluator>evaluator.doclib.action.downloadBrowser</evaluator>
            <evaluator>evaluator.doclib.action.hasContent</evaluator>
<evaluator>evaluator.doclib.action.disable</evaluator> </action>
</actions>
</config>

It would hide the action from both documen-browse and document-details action menu, based on your evaluator conditions.

For download button which you see in details page on top-right corner needs to be disabled by extending "node-header.get.js".  Set the showDownload flag to false.

function main() {
	model.showDownload="false";
	for (var each=0; each<model.widgets.length; each++)  {
		if (model.widgets[each].id == "NodeHeader") {
			model.widgets[each].options.showDownload = false;
		}
	}
}
main();

This will negate the condition to show download button in "node-header.get.html.ftl"

You can see how to extend ootb surf webscripts here:

https://docs.alfresco.com/5.2/concepts/dev-extensions-share-surf-extension-modules.html

https://docs.alfresco.com/5.2/concepts/dev-extensions-share-override-ootb-surf-webscripts.html

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View solution in original post

7 Replies
abhinavmishra14
Advanced

Re: Hide Download Button for Certain roles

Jump to solution

Look at the evaluators documentation:  

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

https://docs.alfresco.com/6.2/concepts/dev-extensions-share-evaluators.html

To explore all OOTB evaluators you can also look at the "slingshot-documentlibrary-context.xml" in your share installation. 

I would suggest you to also go through this tutorial : https://ecmarchitect.com/alfresco-developer-series-tutorials/actions/tutorial/tutorial.html#finishin...

For your case you can use these evaluators and use negation if want inverse results:

1- evaluator.doclib.action.isSiteManager

2- evaluator.doclib.action.isSiteCollaborator

3- evaluator.doclib.action.isSiteContributor

4- evaluator.doclib.action.isSiteConsumer 

The above evaluators are inherited from "evaluator.doclib.action.groupMembership". 

Bean definitions of above evaluators:

<bean id="evaluator.doclib.action.isSiteManager" parent="evaluator.doclib.action.groupMembership">
      <property name="groups">
         <list>
            <value>SiteManager</value>
         </list>
      </property>
   </bean>
   <bean id="evaluator.doclib.action.isSiteCollaborator" parent="evaluator.doclib.action.groupMembership">
      <property name="groups">
         <list>
            <value>SiteCollaborator</value>
         </list>
      </property>
   </bean>
   <bean id="evaluator.doclib.action.isSiteContributor" parent="evaluator.doclib.action.groupMembership">
      <property name="groups">
         <list>
            <value>SiteContributor</value>
         </list>
      </property>
   </bean>
   <bean id="evaluator.doclib.action.isSiteConsumer" parent="evaluator.doclib.action.groupMembership">
      <property name="groups">
         <list>
            <value>SiteConsumer</value>
         </list>
      </property>
   </bean>

To understand how "evaluator.doclib.action.groupMembership" is implemented, have a look at this class: 

https://github.com/Alfresco/share-old/blob/master/share/src/main/java/org/alfresco/web/evaluator/Has...

 

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
piyush48
Established Member

Re: Hide Download Button for Certain roles

Jump to solution

Hi @abhinavmishra14 ,

Thanks for the approach which you have provided and it works correctly with Site Roles like SiteManager,SiteCollaborator, SiteConsumer etc but my question is how to use evaluator with normal user roles like Collaborator, Coordinator, Editor, Consumer etc.

 

Like we use default evaluator with site roles is there any way we can use default evaluator with normal user roles.

If not please provide guidelines on alternative approach.

 

Thanks,

Piyush

 

abhinavmishra14
Advanced

Re: Hide Download Button for Certain roles

Jump to solution

As evaluator parent name indicates "evaluator.doclib.action.groupMembership", it evaluates groups. SiteManager, SiteConsumer,SiteCollaborator and SiteContributor are also groups within the site.

When you go to to manage permissions, Add User/Group, and search for any of the aforementioned name, it would appear as a group. Their names would be like: GROUP_site_test-site_SiteManager, here "test-site" is site short name of a site. Every sites getes these groups when they are created. You can see these groups in Admin Tools> Groups as well by clicking on "" checkbox.

SiteManager, SiteConsumer,SiteCollaborator ,SiteContributor evaluators are working for you because they are evaluated as groups. If you create a folder/file outside of site, you won't see SiteManager, SiteConsumer,SiteCollaborator ,SiteContributor groups when try to manage permissions. You would see users and groups created/available in repository.

In order to use "evaluator.doclib.action.groupMembership" evaluator, create a group via admin tools, add users to the group, go to the manage permissions of the folder/file where you want to apply e.g. Consumer role, go to Add User/Group option and select that particular group and set the Consumer role to it. 

Doc for reference: https://docs.alfresco.com/6.0/tasks/library-item-permissions.html

At last, update the evaluator, for example you created a group named "Restricted", then:

<bean id="evaluator.doclib.action.isRestricted" parent="evaluator.doclib.action.groupMembership">
 <property name="groups">
  <list>
   <value>GROUP_Restricted</value>
  </list>
  </property>
</bean>

and

<bean id="evaluator.doclib.action.isSiteConsumerOrRistricted" parent="evaluator.doclib.action.chainedMatchOne">
      <property name="evaluators">
         <list>
            <ref bean="evaluator.doclib.action.isSiteConsumer" />
            <ref bean="evaluator.doclib.action.isRestricted" />
         </list>
      </property>
    </bean>

At last, update the evaluator config on your actions e.g. "Download action" to use: 

<evaluator>evaluator.doclib.action.isSiteConsumerOrRistricted</evaluator>

To restrict the user with Consumer role for example on a file/folder, "evaluator.doclib.action.groupMembership" won't work straight forward. you would have to create your custom evaluator for this and add custom code to check Consumer role for nodes and then return true/false.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
piyush48
Established Member

Re: Hide Download Button for Certain roles

Jump to solution

Hi @abhinavmishra14 ,

Thanks for the solution and thanks for providing all the steps. 

Now I am facing one issue is that evaluator.doclib.action.disable disables download button from drop-down of the document but doesn't hide the download button when. I clicks on document detail.

Could you please guide me what should I change.

I am using following steps provided in below link just change is that I am doing it for custom role.

https://hub.alfresco.com/t5/alfresco-content-services-forum/disable-download-action-file-and-folder-...

abhinavmishra14
Advanced

Re: Hide Download Button for Certain roles

Jump to solution

Do it simple:

1- Add this action configuration in your share config custom/extension under  <actions> 

<action id="document-download" type="link" label="actions.document.download">

And add the newly configured evaluator in additon to already available evaluators.

<config evaluator="string-compare" condition="DocLibActions">
      <actions>
         <!-- Download document -->
         <action id="document-download" type="link" label="actions.document.download">
            <param name="href">{downloadUrl}</param>
            <param name="target">_blank</param>
            <evaluator>evaluator.doclib.action.downloadBrowser</evaluator>
            <evaluator>evaluator.doclib.action.hasContent</evaluator>
<evaluator>evaluator.doclib.action.disable</evaluator> </action>
</actions>
</config>

It would hide the action from both documen-browse and document-details action menu, based on your evaluator conditions.

For download button which you see in details page on top-right corner needs to be disabled by extending "node-header.get.js".  Set the showDownload flag to false.

function main() {
	model.showDownload="false";
	for (var each=0; each<model.widgets.length; each++)  {
		if (model.widgets[each].id == "NodeHeader") {
			model.widgets[each].options.showDownload = false;
		}
	}
}
main();

This will negate the condition to show download button in "node-header.get.html.ftl"

You can see how to extend ootb surf webscripts here:

https://docs.alfresco.com/5.2/concepts/dev-extensions-share-surf-extension-modules.html

https://docs.alfresco.com/5.2/concepts/dev-extensions-share-override-ootb-surf-webscripts.html

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
alantan
Member II

Re: Hide Download Button for Certain roles

Jump to solution

Hello,

I am new with alfresco, I want the consumer can only read not download. I've disabled most of the download buttons but I need to disable the Download button (only appear when there is multi versions) and the href link with F12 (No matter if there is multi versions) in Version History for Consumer as well.  I didn't find any threads about this, how can I achieve this? Could you please help? Thanks.

 

<span class="actions">

<a href="http://xxx.xxx.xxx.xxx/share/proxy/alfresco/api/node/content/versionStore/version2Store/edf39dd7-63b..." target="_blank" class="download" title="下载">&nbsp;</a>
</span>

 

MarcosChurkin
Member II

Re: Hide Download Button for Certain roles

Jump to solution

Hello, I'm trying to deactivate this button in the top right corner, I couldn't understand the Alfresco tutorial. Could you tell me how to define my model? I think I'm doing something wrong.