Describe the bug
When invoking accessibleBy() with an ability instance that was created with an empty ruleset an error is raised by @casl/[email protected]
As of version @casl/[email protected] this behavior is not observed.
The generated error output is as follows (_paths have been redacted_):
TypeError: Object prototype may only be an Object or null: undefined
at Function.create (<anonymous>)
at c (/****/node_modules/@casl/mongoose/dist/es6c/index.js:1:545)
at Function.u [as accessibleBy] (/****/node_modules/@casl/mongoose/dist/es6c/index.js:1:877)
at Function.****.statics.__find (/****/models/Model.js:181:15)
at run (/****/test.js:75:32)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async /****/test.js:217:5
Potentially relevant issues: https://github.com/stalniy/casl/issues/287
To Reproduce
The following code reproduces the error:
const casl = require('@casl/ability');
const ability = new casl.Ability([]);
model.accessibleBy(ability, 'read').find({}).orFail(new NotFoundOrForbiddenError());
Where model is a mongoose model instance patched by the @casl/mongoose plugins.
Expected behavior
No error condition. Behavior as per @casl/[email protected]
CASL Version
@casl/ability - v5.1.2
@casl/mongoose - v3.2.1
Environment:
Node.JS v12.18.3
Thanks for the issue! Yes, my bad. Will fix today.
Fixed in 3.2.2