adapt-authoring-api 1.2.0 → 1.3.0
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/AbstractApiModule.js +8 -3
- package/package.json +1 -1
package/lib/AbstractApiModule.js
CHANGED
|
@@ -514,13 +514,15 @@ class AbstractApiModule extends AbstractModule {
|
|
|
514
514
|
* @return {Promise} Rejects if access should be blocked
|
|
515
515
|
*/
|
|
516
516
|
async checkAccess (req, data) {
|
|
517
|
+
if (req.auth.isSuper) {
|
|
518
|
+
return data
|
|
519
|
+
}
|
|
517
520
|
const isArray = Array.isArray(data)
|
|
518
521
|
const filtered = []
|
|
519
522
|
let error
|
|
520
523
|
await Promise.allSettled((isArray ? data : [data]).map(async r => {
|
|
521
524
|
try {
|
|
522
|
-
if (!this.accessCheckHook.hasObservers ||
|
|
523
|
-
(await this.accessCheckHook.invoke(req, r)).some(Boolean)) {
|
|
525
|
+
if (!this.accessCheckHook.hasObservers || (await this.accessCheckHook.invoke(req, r)).some(Boolean)) {
|
|
524
526
|
filtered.push(r)
|
|
525
527
|
}
|
|
526
528
|
} catch (e) {
|
|
@@ -573,11 +575,14 @@ class AbstractApiModule extends AbstractModule {
|
|
|
573
575
|
* @param {external:MongoDBFindOptions} mongoOptions Options to be passed to the MongoDB function
|
|
574
576
|
* @return {Promise} Resolves with the single DB document
|
|
575
577
|
*/
|
|
576
|
-
async findOne (query, options, mongoOptions) {
|
|
578
|
+
async findOne (query, options = {}, mongoOptions = {}) {
|
|
577
579
|
const results = await this.find(query, options, mongoOptions)
|
|
578
580
|
if (results.length > 1) {
|
|
579
581
|
throw this.app.errors.TOO_MANY_RESULTS.setData({ actual: results.length, expected: 1, query })
|
|
580
582
|
}
|
|
583
|
+
if (options.strict !== false && !results.length) {
|
|
584
|
+
throw this.app.errors.NOT_FOUND.setData({ id: query, type: options.schemaName })
|
|
585
|
+
}
|
|
581
586
|
return results[0]
|
|
582
587
|
}
|
|
583
588
|
|