Merge pull request #166 from strongloop/feature/acl-subclass
Make sure the configured ACL submodel is used
This commit is contained in:
commit
323d5f80b0
|
@ -117,10 +117,20 @@ Model.setup = function () {
|
||||||
/*!
|
/*!
|
||||||
* Get the reference to ACL in a lazy fashion to avoid race condition in require
|
* Get the reference to ACL in a lazy fashion to avoid race condition in require
|
||||||
*/
|
*/
|
||||||
var ACL = null;
|
var _aclModel = null;
|
||||||
function getACL() {
|
Model._ACL = function getACL(ACL) {
|
||||||
return ACL || (ACL = require('./acl').ACL);
|
if(ACL !== undefined) {
|
||||||
}
|
// The function is used as a setter
|
||||||
|
_aclModel = ACL;
|
||||||
|
}
|
||||||
|
if(_aclModel) {
|
||||||
|
return _aclModel;
|
||||||
|
}
|
||||||
|
var aclModel = require('./acl').ACL;
|
||||||
|
_aclModel = loopback.getModelByType(aclModel);
|
||||||
|
return _aclModel;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the given access token can invoke the method
|
* Check if the given access token can invoke the method
|
||||||
|
@ -137,9 +147,9 @@ function getACL() {
|
||||||
Model.checkAccess = function(token, modelId, method, callback) {
|
Model.checkAccess = function(token, modelId, method, callback) {
|
||||||
var ANONYMOUS = require('./access-token').ANONYMOUS;
|
var ANONYMOUS = require('./access-token').ANONYMOUS;
|
||||||
token = token || ANONYMOUS;
|
token = token || ANONYMOUS;
|
||||||
var ACL = getACL();
|
var aclModel = Model._ACL();
|
||||||
var methodName = 'string' === typeof method? method: method && method.name;
|
var methodName = 'string' === typeof method? method: method && method.name;
|
||||||
ACL.checkAccessForToken(token, this.modelName, modelId, methodName, callback);
|
aclModel.checkAccessForToken(token, this.modelName, modelId, methodName, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -158,7 +168,7 @@ Model._getAccessTypeForMethod = function(method) {
|
||||||
'method is a required argument and must be a RemoteMethod object'
|
'method is a required argument and must be a RemoteMethod object'
|
||||||
);
|
);
|
||||||
|
|
||||||
var ACL = getACL();
|
var ACL = Model._ACL();
|
||||||
|
|
||||||
switch(method.name) {
|
switch(method.name) {
|
||||||
case'create':
|
case'create':
|
||||||
|
|
|
@ -612,6 +612,16 @@ describe('Model', function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Model._getACLModel()', function() {
|
||||||
|
it('should return the subclass of ACL', function() {
|
||||||
|
var Model = require('../').Model;
|
||||||
|
var acl = ACL.extend('acl');
|
||||||
|
Model._ACL(null); // Reset the ACL class for the base model
|
||||||
|
var model = Model._ACL();
|
||||||
|
assert.equal(model, acl);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// describe('Model.hasAndBelongsToMany()', function() {
|
// describe('Model.hasAndBelongsToMany()', function() {
|
||||||
// it("TODO: implement / document", function(done) {
|
// it("TODO: implement / document", function(done) {
|
||||||
// /* example -
|
// /* example -
|
||||||
|
|
Loading…
Reference in New Issue