adapt-authoring-roles 1.4.1 → 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.
@@ -1,4 +1,4 @@
1
- name: Standard.js formatting check
1
+ name: Lint
2
2
  on: push
3
3
  jobs:
4
4
  default:
@@ -9,4 +9,4 @@ jobs:
9
9
  with:
10
10
  node-version: 'lts/*'
11
11
  - run: npm install
12
- - run: npx standard
12
+ - run: npx standard
@@ -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
  }
@@ -96,10 +95,9 @@ class RolesModule extends AbstractApiModule {
96
95
 
97
96
  /** @override */
98
97
  async setValues () {
99
- /** @ignore */ this.root = 'roles'
98
+ await super.setValues()
100
99
  /** @ignore */ this.schemaName = 'role'
101
100
  /** @ignore */ this.collectionName = 'roles'
102
- this.useDefaultRouteConfig()
103
101
  }
104
102
 
105
103
  /**
@@ -140,13 +138,13 @@ class RolesModule extends AbstractApiModule {
140
138
  }
141
139
 
142
140
  async getSuperRoleId () {
143
- const [superRole] = await this.find({ scopes: ['*:*'] })
141
+ const superRole = await this.findOne({ scopes: ['*:*'] })
144
142
  return superRole._id.toString()
145
143
  }
146
144
 
147
145
  async isTargetSuper (_id) {
148
146
  const users = await this.app.waitForModule('users')
149
- const [user] = await users.find({ _id }, { projection: { roles: 1 } })
147
+ const user = await users.findOne({ _id }, { projection: { roles: 1 } })
150
148
  return user.roles.length === 1 && user.roles[0].toString() === await this.getSuperRoleId()
151
149
  }
152
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-roles",
3
- "version": "1.4.1",
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",
@@ -44,7 +44,7 @@
44
44
  ]
45
45
  },
46
46
  "dependencies": {
47
- "adapt-authoring-api": "^2.0.0"
47
+ "adapt-authoring-api": "^3.0.0"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "adapt-authoring-auth": "^2.0.0",
package/routes.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "root": "roles"
3
+ }
@@ -13,10 +13,8 @@ import assert from 'node:assert/strict'
13
13
  /** Build a minimal RolesModule-like instance with sensible stub defaults */
14
14
  function createInstance (overrides) {
15
15
  const instance = {
16
- root: undefined,
17
16
  schemaName: undefined,
18
17
  collectionName: undefined,
19
- useDefaultRouteConfig: mock.fn(),
20
18
  app: {
21
19
  waitForModule: mock.fn(async () => ({})),
22
20
  errors: {
@@ -46,10 +44,8 @@ function createInstance (overrides) {
46
44
  // ── Method references (copied from source for isolated testing) ─────
47
45
 
48
46
  async function setValues () {
49
- this.root = 'roles'
50
47
  this.schemaName = 'role'
51
48
  this.collectionName = 'roles'
52
- this.useDefaultRouteConfig()
53
49
  }
54
50
 
55
51
  async function getScopesForRole (_id) {
@@ -171,12 +167,6 @@ describe('RolesModule', () => {
171
167
  // ── setValues ──────────────────────────────────────────────────────
172
168
 
173
169
  describe('setValues', () => {
174
- it('should set root to "roles"', async () => {
175
- const inst = createInstance()
176
- await setValues.call(inst)
177
- assert.equal(inst.root, 'roles')
178
- })
179
-
180
170
  it('should set schemaName to "role"', async () => {
181
171
  const inst = createInstance()
182
172
  await setValues.call(inst)
@@ -188,12 +178,6 @@ describe('RolesModule', () => {
188
178
  await setValues.call(inst)
189
179
  assert.equal(inst.collectionName, 'roles')
190
180
  })
191
-
192
- it('should call useDefaultRouteConfig', async () => {
193
- const inst = createInstance()
194
- await setValues.call(inst)
195
- assert.equal(inst.useDefaultRouteConfig.mock.callCount(), 1)
196
- })
197
181
  })
198
182
 
199
183
  // ── getScopesForRole ───────────────────────────────────────────────