Skip to content

Commit

Permalink
Add function for scope retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
taylortom committed Mar 23, 2023
1 parent 87771ea commit 9d01c67
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/RolesModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ class RolesModule extends AbstractApiModule {
}))
}

/**
* Returns the list of scopes for the given role
* @param {String | ObjectId} _id The _id of the role
* @returns {Array<String>} Array of scopes
*/
async getScopesForRole (_id) {
const allRoles = await this.find()
const scopes = []
let role = allRoles.find(r => r._id.toString() === _id.toString())
do {
scopes.push(...role.scopes)
role = allRoles.find(r => r.shortName === role.extends)
} while (role)
return scopes
}

/**
* Handles setting defined default roles when new users are added
* @return {Promise}
Expand Down

0 comments on commit 9d01c67

Please sign in to comment.