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.
- package/lib/RolesModule.js +4 -5
- package/package.json +1 -1
package/lib/RolesModule.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
}
|