removePermission for all users/groups workaround

I take an ugly bug in removePermission JavaScript function of Alfresco 4.0.d Community Edition.

You can reproduce by this sample script:

var node = companyhome.childByNamePath("User Homes/louise");

permissions = node.getPermissions();
print("Before removePermission:");
print(permissions);

node.removePermission("Coordinator");

permissions = node.getPermissions();
print("After removePermission:");
print(permissions);

Results should be:

Before removePermission:
0 : ALLOWED;louise;All
1 : ALLOWED;ROLE_OWNER;All
2 : ALLOWED;abeecher;Coordinator

After removePermission:
0 : ALLOWED;louise;All
1 : ALLOWED;ROLE_OWNER;All
2 : ALLOWED;abeecher;Coordinator

Ok, don’t wait for 4.1, let see the workaround (removePermissionFromAll function):

var node = companyhome.childByNamePath("User Homes/louise");

permissions = node.getPermissions();
print("Before removePermission:");
print(permissions);

removePermissionFromAll(node, "Coordinator");
  
permissions = node.getPermissions();
print("After removePermission:");
print(permissions);

function removePermissionFromAll(node, roleName) {
    permissions = node.getPermissions();
    for(rpi=0;rpi

... and the better result:

Before removePermission:
0 : ALLOWED;louise;All
1 : ALLOWED;ROLE_OWNER;All
2 : ALLOWED;abeecher;Coordinator

After removePermission:
0 : ALLOWED;louise;All
1 : ALLOWED;ROLE_OWNER;All

And as a bonus track, see a simple script to remove "All" permissions in user home folders:

var node = companyhome.childByNamePath("User Homes");

var foldersInUserHomes = node.children;

for(i=0; i

Leave a Reply

Your email address will not be published. Required fields are marked *