cancel
Showing results for 
Search instead for 
Did you mean: 

Script to remove control of a document from its creator?

pdoggett
Champ in-the-making
Champ in-the-making
What I am trying to do is configure a space into which users can place documents but, once placed, the document ceases to be under the user's control (ie, is no longer editable or deletable by the owner).

I have tried the following, which comes very close:
if (document.isDocument) {
document.removePermission("FullControl","ROLE_OWNER");
document.setOwner("admin");
props = new Array(1);
props["cm:lockType"] = "READ_ONLY_LOCK";
props["cm:lockOwner"] = "admin";
document.addAspect("cm:lockable", props);
}

The 'removePermission' line appears to have no effect.  The creator of the document can still unlock (and hence edit, delete) the document.

I have tried
document.removePermission("Unlock","ROLE_OWNER");
but I suspect that I need something closer to
document.removePermission("Unlock","ROLE_CREATOR");

Is there a way to do this that does not require changing
model/permissionDefinitions.xml?

After the script has been run, the following is shown in the node browser:
Properties
cm:lockOwner == admin
cmSmiley Surprisedwner == admin
cm:creator == alfuser1
cm:description
cm:lockType = READ_ONLY_LOCK
cm:author == <empty>
cm:modifier == alfuser1

Aspects
cmSmiley Surprisedwnable
cm:auditable
cm:titled
cm:lockable
{http://www.alfresco.org/model/system/1.0}referenceable
cm:author

Cheers,
Philip
1 REPLY 1

ljjuarez
Champ in-the-making
Champ in-the-making
Hi Phillip, first of all excuse my poor english.

I have created a script with the next code executed by a rule:
document.setInheritsPermissions(false);
It is mandatory to comment in permissionDefinitions.xml file (at the end of file)the next line:

<!– For now, owners can always see, find and manipulate their stuff –>
<!– <globalPermission permission="FullControl" authority="ROLE_OWNER"/> –>
then reboot Alfresco.

Warning: if you don't comment this line, the owner's document will always have all their permissions intact.

and it works perfectly !!!!

Now nobody except admin has permission about this document, so that any user with Space Contributor permission can add a document into a Space and then he no longer has permits on his own document, no read, no write, … nothing.

If you want to give permissions (e.g.) to reviewer's group to this document you could add the next line to the javascript code:

document.setPermissions("Coordinator", "GROUP_REVIEWERS");
Important: this code line is to be put before the other code line (setInerithsPermissions), because once has been executed the user can no longer assign permissions.
I helped me a lot these links:
http://forums.alfresco.com/en/viewtopic.php?f=12&t=6775&hilit=role+owner
http://forums.alfresco.com/en/viewtopic.php?f=5&t=3498&hilit=owner+remove+control

I hope this can help you or someone else.

Regards
Javier