How do I check if referenced user has write access to a specific record

jyates
Giga Contributor

Our CMDB manager would like to send a notification to the owner of a CI only if they have write access to the CI.   Is there any way to check a users permission when you are not logged in as the user?

I have found the following:

function evalACL(user, record, operation, field) {  

  var currentUser = gs.getUserID();  

  gs.getSession().onlineImpersonate(user);  

  var sm = GlideSecurityManager.get();  

  var aclCheck = 'record/' + record.getTableName();  

  if (!JSUtil.nil(field) ) {  

  aclCheck = aclCheck + '.' + field;  

  }  

  aclCheck = aclCheck + '/' + operation;  

  gs.print(aclCheck);  

  var hasRights = sm.hasRightsTo(aclCheck, record);  

  gs.getSession.onlineImpersonate(currentUser );  

  return hasRights;  

}  

Here: ACL's & permissions

However, this requires impersonating the user, which we are a bit apprehensive to do.

Any guidance would be appreciated.   Thanks.

1 REPLY 1

LaurentChicoine
Tera Guru

This is an old question, however, I was looking to do exactly this. I find out there is a function in the GlideSecurityManager that allows you to set the rights as a specific user so you can then evaluate ACL. It is pretty much the same as an impersonation, however it only affects the roles and ACL part.



The function is GlideSecurityManager.get().setUser(userObject)



Where the user object is a user object that you get using gs.getUser().getUserByID('user_name_or_sys_id').



Don't forget to set back the setUser to the current user otherwise your user would have the other users access until it's session ends.