Skip to content

Commit 24184fc

Browse files
authored
Allowed methods (#21)
* Options for adding methods back on as allowed
1 parent 6b7df9f commit 24184fc

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const resolveAuthLevel = require('./src/resolveAuthLevel');
88
const PermissionDeniedError = require('./src/PermissionDeniedError');
99
const IncompatibleMethodError = require('./src/IncompatibleMethodError');
1010

11-
module.exports = (schema) => {
11+
module.exports = (schema, installationOptions) => {
1212
async function save(doc, options) {
1313
const authLevels = await resolveAuthLevel(schema, options, doc);
1414
if (doc.isNew && !hasPermission(schema, authLevels, 'create')) {
@@ -142,11 +142,16 @@ module.exports = (schema) => {
142142
return hasPermission(this.schema, authLevels, 'create');
143143
};
144144

145-
schema.statics.create = function cannotCreate() {
146-
throw new IncompatibleMethodError('Model.create');
147-
};
145+
const allowedMethods = _.get(installationOptions, 'allowedMethods');
146+
if (!_.includes(allowedMethods, 'create')) {
147+
schema.statics.create = function cannotCreate() {
148+
throw new IncompatibleMethodError('Model.create');
149+
};
150+
}
148151

149-
schema.statics.remove = function cannotRemove() {
150-
throw new IncompatibleMethodError('Model.remove');
151-
};
152+
if (!_.includes(allowedMethods, 'remove')) {
153+
schema.statics.remove = function cannotRemove() {
154+
throw new IncompatibleMethodError('Model.remove');
155+
};
156+
}
152157
};

0 commit comments

Comments
 (0)