UNPKG

d2

Version:

Javascript library for DHIS2

43 lines (38 loc) 1.12 kB
const auths = Symbol('authorities') /** * Simple wrapper class for the user authorities list * * @memberof module:current-user */ class UserAuthorities { /** * Creates the UserAuthorities object based off the given set of the user's authorities. * * @param {string[]} authorities A set of the user's authorities. */ constructor(authorities = []) { this[auths] = new Set(authorities) } /** * Checks if the given authority is in the user's authority list. * * If the user has the 'ALL' authority any request for a authority will return `true`. * * @param {string} authority The authority to check for */ has(authority) { if (this[auths].has('ALL')) { return true } return this[auths].has(authority) } /** * Factory method for a UserAuthorities instance * * @param {string[]} authorities A set of the user's authorities as recieved from the api. */ static create(authorities) { return new UserAuthorities(authorities) } } export default UserAuthorities