Name
sn_entitlement.UserHasRoleInMemoryCache
Description
No description available
Script
var UserHasRoleInMemoryCache = Class.create();
UserHasRoleInMemoryCache.prototype = {
/**
* Create an in-memory cache of the data in sys_user_has_role limited to the roleIds that are provided
* in this constructor.
*
* @param meteredRoleIds The super-set of roleIds to load into the in-memory cache
*/
initialize: function(meteredRoleIds) {
this._membershipInMemoryCache = this._constructInMemoryCache(meteredRoleIds);
},
/**
* Retrieve the roleIds assigned to the user
*
* @param userId The sys_user.sys_id to retrieve roles for
* @returns {string[]} An array of sys_user_role.sys_id values
*/
getRoleIdsByUserId: function(userId) {
return this._membershipInMemoryCache.getValsById(userId);
},
/**
* Setup the in-memory cache to hold the appropriate data
*
* @param meteredRoleIds The super-set of roleIds to load into the in-memory cache
* @returns {sn_entitlement.MembershipInMemoryCache} A configured in-memory cache object
* @private
*/
_constructInMemoryCache: function(meteredRoleIds) {
const keyName = 'user';
const valName = 'role';
const gr = new GlideRecord('sys_user_has_role');
gr.addQuery('role', 'IN', meteredRoleIds);
gr.addQuery('user.active', true);
gr.query();
return new sn_entitlement.MembershipInMemoryCache(gr, keyName, valName, meteredRoleIds.length);
},
type: 'UserHasRoleInMemoryCache'
};
Sys ID
f65d3ff4ff836110468365d7d3b8fee4