cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Script : is this algorithm feasible please ? -->

aurelien2
Champ in-the-making
Champ in-the-making
Here is a script in a madeup language. It checks the permissions on the actual document triggered and sends an email alert to all people who can read the file except to the person who triggered the alert (he already knows…) :

user = getcurrentuser();
document = getcurrentdocument();
perms = getpermissions(document);

for each(perms as perm) {
   if (perm["username"] != user.getname()) {
      mail = newmail();
      mail.subject = "new document "" + document.getname() + "" changed";
      mail.to = getPersonFromName(perm["username"]).getemail();
      mail.from = "admin@mysite.com";
      mail.body = "blah blah " + document.geturl() + "blabla. Bye.";
      mail.send();
   }
}

1) Is thi possible using the javascript API? Could you give me a hint on how to implement the "perms = getpermissions" and "for each (perms as perm)" please? I dont know how to parse tokenised string in javascript :s

2) Are discussions nodes taken care of, this way? Is there any way i can detect that the current node is a discussion and mention it in the email?

Any help greatly apreciated !! Smiley Happy

Aurélien
3 REPLIES 3

aurelien2
Champ in-the-making
Champ in-the-making
Anyone?

I am willing to pay for such answers, what company could I ask for such works? (french based company)

Thanks !

kevinr
Star Contributor
Star Contributor
The JavaScript API already has a getPermissions() method to retrieve the permissions explicitly set on a node:
http://wiki.alfresco.com/wiki/JavaScript_API#Permission_and_Security_API

There is also an API for retrieving People nodes given the username retrieved from the permission data:
http://wiki.alfresco.com/wiki/JavaScript_API#People_API

The issue here is that the getPermissions() method only retrieves the permissions explicity applied to a node. It does not return and calculate the permissions as inherited from any parent nodes and which therefore also apply. However using the node.parent API and the JavaScript Permissions API method inheritsPermissions() you can work out all permissions applied to a node including the inheritance chain. In addition, Groups of users are returned in the getPermissions() data, but again you can use the People API to calculate which users are in the Groups and in turn get those users emails addresses. You may want to do some background reading on the way Alfresco permissions work on our wiki first!

Hope this helps,

Kevin

aurelien2
Champ in-the-making
Champ in-the-making
Many thanks ! I will give it a try Smiley Happy

BTW if i cant get this to work, is there any way i can ask a company/someone to do it instead? I sold an Alfresco install for a test to a company, but they want some customization. We dont have budget right now to buy a full licence, but we do for some development.