Question

I'm trying to determine if the current user has delete rights. I can check the ACLEntry for the person, but if they are getting their access privileges fro one or more groups this will mean cycling through the group names in the ACL and checking if they have delete right then see if the user is a member of the group. This could be a fairly intensive process. I have heard that there might be a method in the ext Lib but have not been able to find anything. What is the best way to determine if the user can delete documents?

Was it helpful?

Solution

Adapting this example slightly, here's a function that would allow you to query this privilege (and a few others, for good measure):

function getUserPrivileges() {
    var privileges = database.queryAccessPrivileges(context.getUser().getDistinguishedName());
    return {
        createDocuments: ((privileges & NotesDatabase.DBACL_CREATE_DOCS) > 0),
        deleteDocuments: ((privileges & NotesDatabase.DBACL_DELETE_DOCS) > 0),
        readPublicDocuments: ((privileges & NotesDatabase.DBACL_READ_PUBLIC_DOCS) > 0),
        writePublicDocuments: ((privileges & NotesDatabase.DBACL_WRITE_PUBLIC_DOCS) > 0)
    };
}

If you add the above to a script library, then any code that references that library could include logic like the following:

if (getUserPrivileges().deleteDocuments) {
    // delete something…
}

For additional flexibility, you could adjust the getUserPrivileges() function to be passed a handle on the specific database the user is trying to delete from instead of always assuming it's the current.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top