Home > Alfresco > Removing Permission of a User or Group in Alfresco Using Javascript

Removing Permission of a User or Group in Alfresco Using Javascript


In my last post, I have discussed how you can grant permissions to a user or group in a certain space or folder. This can be done by either using the Alfresco Web Client (Alfresco UI) or by using the permission service JavaScript API provided by Alfresco. By creating a JavaScript web script, one can add or delete permissions of a user or group in a specific folder/space. This post is  related to my previous post I created,  but in this section we will  discuss about removing the permission applied using JavaScript API.


Alfresco provided a javascript API we can use to remove set permissions. Below are the two methods we can use:

1. void removePermission(string permission) – Remove a permission for ALL users from the node.

2. void removePermission(string permission, string authority) – Remove a permission for the specified authority (e.g. username or group) from the node.

As an example (taken from my previous post), we can also create  another web scripts which removes permission on a node:

a. removePermission.get.desc.xml – the descriptor file that will register our web script, example:

    <shortname>Remove Permission</shortname>
    <description>Remove Permission of a User or  Group from a Folder or Space</description>
    <format default=”html”/>

b.  removePermission.get.html.ftl –  the file that will display the response from Alfresco, example:


c. removePermission.get.js – java-script that will contain the logic of our code. Here, we will use Alfresco java-script API for  setting the permission of  a folder, example:

/*Remove permission to a folder using Alfresco javascript API*/

//search for the folder node using lucene search
var folderNode =  search.luceneSearch(“TYPE:\”{http://www.alfresco.org/model/content/1.0}folder\” AND @cm\\:name:”+args.folderName);

//make sure we only get one node

if(folderNode.length == 1){
//remove permission “Contributor” from all users or group
//remove permission “Contributor” from group ANYTHINGALFRESCOGROUP

folderNode[0].removePermission(“Contributor”, “GROUP_ANYTHINGALFRESCOGROUP”);
model.myStatus = “Permission was removed successfully!”;
}else  if (folderNode.length == 0){
//no node was found
model.myStatus = “Folder not found”;
//either greater than two  was found
model.myStatus = “Duplicate folder found”;

You can try the above code on your Alfresco installation and see if it works. Just follow the steps on how  to create a web script and upload it in Web Scripts Extension space. I hope this helps! =P

  1. August 13, 2011 at 1:50 am

    Its good to see you’re sharing your knowledge about alfresco, master bernie 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: