@@ -8,7 +8,7 @@ const resolveAuthLevel = require('./src/resolveAuthLevel');
88const PermissionDeniedError = require ( './src/PermissionDeniedError' ) ;
99const 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