Merge pull request #97 from strongloop/bug/check-access

Dont attempt access checking on models without a check access method
This commit is contained in:
Ritchie Martori 2013-12-12 16:01:33 -08:00
commit 591ed86444
1 changed files with 20 additions and 16 deletions

View File

@ -164,23 +164,27 @@ app.enableAuth = function() {
var modelInstance = ctx.instance;
var modelId = modelInstance && modelInstance.id || req.param('id');
Model.checkAccess(
req.accessToken,
modelId,
method.name,
function(err, allowed) {
if(err) {
console.log(err);
next(err);
} else if(allowed) {
next();
} else {
var e = new Error('Access Denied');
e.statusCode = 401;
next(e);
if(Model.checkAccess) {
Model.checkAccess(
req.accessToken,
modelId,
method.name,
function(err, allowed) {
if(err) {
console.log(err);
next(err);
} else if(allowed) {
next();
} else {
var e = new Error('Access Denied');
e.statusCode = 401;
next(e);
}
}
}
);
);
} else {
next();
}
});
}