adapt-authoring-api 1.6.0 → 1.6.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.
@@ -452,6 +452,21 @@ class AbstractApiModule extends AbstractModule {
452
452
  let results = await this.find(req.apiData.query, opts, mongoOpts)
453
453
 
454
454
  results = await this.checkAccess(req, results)
455
+
456
+ // If checkAccess filtered some results, fetch more to fill the page
457
+ const pageSize = mongoOpts.limit
458
+ if (pageSize && results.length < pageSize) {
459
+ let fetchSkip = mongoOpts.skip + pageSize
460
+ while (results.length < pageSize) {
461
+ const extra = await this.find(req.apiData.query, opts, { ...mongoOpts, skip: fetchSkip })
462
+ if (!extra.length) break
463
+ const filtered = await this.checkAccess(req, extra)
464
+ results = results.concat(filtered)
465
+ fetchSkip += extra.length
466
+ }
467
+ if (results.length > pageSize) results = results.slice(0, pageSize)
468
+ }
469
+
455
470
  results = await this.sanitise(req.apiData.schemaName, results, { isInternal: true, strict: false })
456
471
 
457
472
  res.status(this.mapStatusCode('get')).json(results)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-api",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Abstract module for creating APIs",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-api",
6
6
  "license": "GPL-3.0",