Skip to content

Commit 0ab33a8

Browse files
author
Richard Pringle
committed
Call new disable remote method from model class.
1 parent 92ed213 commit 0ab33a8

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

lib/model.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var SharedClass = require('strong-remoting').SharedClass;
1515
var extend = require('util')._extend;
1616
var format = require('util').format;
1717

18+
var deprecated = require('depd')('loopback');
19+
1820
module.exports = function(registry) {
1921
/**
2022
* The base class for **all models**.
@@ -436,7 +438,22 @@ module.exports = function(registry) {
436438
*/
437439

438440
Model.disableRemoteMethod = function(name, isStatic) {
439-
this.sharedClass.disableMethod(name, isStatic || false);
441+
deprecated('Model.disableRemoteMethod is deprecated. ' +
442+
'Use Model.disableRemoteMethodByName instead.');
443+
var key = this.sharedClass.getKeyFromMethodNameAndTarget(name, isStatic);
444+
this.sharedClass.disableMethodByName(key);
445+
this.emit('remoteMethodDisabled', this.sharedClass, key);
446+
};
447+
448+
/**
449+
* Disable remote invocation for the method with the given name.
450+
*
451+
* @param {String} name The name of the method (include "prototype." if the method is defined on the prototype).
452+
*
453+
*/
454+
455+
Model.disableRemoteMethodByName = function(name) {
456+
this.sharedClass.disableMethodByName(name);
440457
this.emit('remoteMethodDisabled', this.sharedClass, name);
441458
};
442459

test/app.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ describe('app', function() {
672672
disabledRemoteMethod = methodName;
673673
});
674674
app.model(Color);
675-
app.models.Color.disableRemoteMethod('findOne');
675+
app.models.Color.disableRemoteMethodByName('findOne');
676676
expect(remoteMethodDisabledClass).to.exist;
677677
expect(remoteMethodDisabledClass).to.eql(Color.sharedClass);
678678
expect(disabledRemoteMethod).to.exist;

test/model.test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,21 @@ describe.onServer('Remote Methods', function() {
698698
var callbackSpy = require('sinon').spy();
699699
var TestModel = app.models.TestModelForDisablingRemoteMethod;
700700
TestModel.on('remoteMethodDisabled', callbackSpy);
701-
TestModel.disableRemoteMethod('findOne');
701+
TestModel.disableRemoteMethod('findOne', true);
702+
703+
expect(callbackSpy).to.have.been.calledWith(TestModel.sharedClass, 'findOne');
704+
});
705+
706+
it('emits a `remoteMethodDisabled` event from disableRemoteMethodByName', function() {
707+
var app = loopback();
708+
var model = PersistedModel.extend('TestModelForDisablingRemoteMethod');
709+
app.dataSource('db', { connector: 'memory' });
710+
app.model(model, { dataSource: 'db' });
711+
712+
var callbackSpy = require('sinon').spy();
713+
var TestModel = app.models.TestModelForDisablingRemoteMethod;
714+
TestModel.on('remoteMethodDisabled', callbackSpy);
715+
TestModel.disableRemoteMethodByName('findOne');
702716

703717
expect(callbackSpy).to.have.been.calledWith(TestModel.sharedClass, 'findOne');
704718
});

0 commit comments

Comments
 (0)