Assigning permissions to a user
We will see in this recipe how to assign various permissions to a particular user.
How to do it...
1. Create a new script file in the Company Home>Data Dictionary>Scripts>Cookbook folder and save this code. Let’s say the file is named
assignpermission.js
.var qry = "@cm\\:name:\"Test_JS_API.txt\""; var docs = search.luceneSearch(qry); if (docs.length > 0) { var doc = docs[0]; if (doc.hasPermission("ChangePermissions")) { var usr = people.getPerson("snig.bhaumik"); if (usr != null) { doc.setPermission("Write", "snig.bhaumik"); doc.setPermission("Delete", "snig.bhaumik"); doc.setPermission("AddChildren", "snig.bhaumik"); doc.setPermission("Execute", "snig.bhaumik"); } } }
2. Execute the script using Run Action on the document Test_JS_API.txt in the Chapter 8 folder.
3. Upon executing the script, the user snig.bhaumik will have write, delete, and execute the permission of this document.
4. Let’s examine what happened behind the scenes. This was the original...