adapt-authoring-roles 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,7 +30,7 @@ class RolesModule extends AbstractApiModule {
30
30
  async initConfigRoles () {
31
31
  const mongodb = await this.app.waitForModule('mongodb')
32
32
  return Promise.allSettled(this.getConfig('roleDefinitions').map(async r => {
33
- const [doc] = await this.find({ shortName: r.shortName })
33
+ const doc = await this.findOne({ shortName: r.shortName }, { strict: false })
34
34
  if (doc) {
35
35
  try {
36
36
  await mongodb.replace(this.collectionName, { _id: doc._id }, r)
@@ -55,8 +55,7 @@ class RolesModule extends AbstractApiModule {
55
55
  */
56
56
  async shortNamesToIds (roles) {
57
57
  return Promise.all(roles.map(async r => {
58
- const [role] = await this.find({ shortName: r })
59
- if (!role) throw new Error(`role '${r}' not found`)
58
+ const role = await this.findOne({ shortName: r })
60
59
  return role._id.toString()
61
60
  }))
62
61
  }
@@ -139,13 +138,13 @@ class RolesModule extends AbstractApiModule {
139
138
  }
140
139
 
141
140
  async getSuperRoleId () {
142
- const [superRole] = await this.find({ scopes: ['*:*'] })
141
+ const superRole = await this.findOne({ scopes: ['*:*'] })
143
142
  return superRole._id.toString()
144
143
  }
145
144
 
146
145
  async isTargetSuper (_id) {
147
146
  const users = await this.app.waitForModule('users')
148
- const [user] = await users.find({ _id }, { projection: { roles: 1 } })
147
+ const user = await users.findOne({ _id }, { projection: { roles: 1 } })
149
148
  return user.roles.length === 1 && user.roles[0].toString() === await this.getSuperRoleId()
150
149
  }
151
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-roles",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Module for managing user roles",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-roles",
6
6
  "license": "GPL-3.0",