File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed
Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -441,7 +441,20 @@ module.exports = function(registry) {
441441 */
442442
443443 Model . disableRemoteMethod = function ( name , isStatic ) {
444- this . sharedClass . disableMethod ( name , isStatic || false ) ;
444+ var key = this . sharedClass . getKeyFromMethodNameAndTarget ( name , isStatic ) ;
445+ this . sharedClass . disableMethodByName ( key ) ;
446+ this . emit ( 'remoteMethodDisabled' , this . sharedClass , key ) ;
447+ } ;
448+
449+ /**
450+ * Disable remote invocation for the method with the given name.
451+ *
452+ * @param {String } name The name of the method (include "prototype." if the method is defined on the prototype).
453+ *
454+ */
455+
456+ Model . disableRemoteMethodByName = function ( name ) {
457+ this . sharedClass . disableMethodByName ( name ) ;
445458 this . emit ( 'remoteMethodDisabled' , this . sharedClass , name ) ;
446459 } ;
447460
Original file line number Diff line number Diff line change @@ -677,7 +677,7 @@ describe('app', function() {
677677 disabledRemoteMethod = methodName ;
678678 } ) ;
679679 app . model ( Color ) ;
680- app . models . Color . disableRemoteMethod ( 'findOne' ) ;
680+ app . models . Color . disableRemoteMethodByName ( 'findOne' ) ;
681681 expect ( remoteMethodDisabledClass ) . to . exist ;
682682 expect ( remoteMethodDisabledClass ) . to . eql ( Color . sharedClass ) ;
683683 expect ( disabledRemoteMethod ) . to . exist ;
Original file line number Diff line number Diff line change @@ -707,7 +707,21 @@ describe.onServer('Remote Methods', function() {
707707 var callbackSpy = require ( 'sinon' ) . spy ( ) ;
708708 var TestModel = app . models . TestModelForDisablingRemoteMethod ;
709709 TestModel . on ( 'remoteMethodDisabled' , callbackSpy ) ;
710- TestModel . disableRemoteMethod ( 'findOne' ) ;
710+ TestModel . disableRemoteMethod ( 'findOne' , true ) ;
711+
712+ expect ( callbackSpy ) . to . have . been . calledWith ( TestModel . sharedClass , 'findOne' ) ;
713+ } ) ;
714+
715+ it ( 'emits a `remoteMethodDisabled` event from disableRemoteMethodByName' , function ( ) {
716+ var app = loopback ( ) ;
717+ var model = PersistedModel . extend ( 'TestModelForDisablingRemoteMethod' ) ;
718+ app . dataSource ( 'db' , { connector : 'memory' } ) ;
719+ app . model ( model , { dataSource : 'db' } ) ;
720+
721+ var callbackSpy = require ( 'sinon' ) . spy ( ) ;
722+ var TestModel = app . models . TestModelForDisablingRemoteMethod ;
723+ TestModel . on ( 'remoteMethodDisabled' , callbackSpy ) ;
724+ TestModel . disableRemoteMethodByName ( 'findOne' ) ;
711725
712726 expect ( callbackSpy ) . to . have . been . calledWith ( TestModel . sharedClass , 'findOne' ) ;
713727 } ) ;
You can’t perform that action at this time.
0 commit comments