mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-22 07:12:31 +01:00
Changed some bad comments referencing the Articles module in other modules.
Typo fixed in xxx.client.modules.js files ("Application" => "Applicaion")
Full stop character removed at the end of line comments
50 lines
1.0 KiB
JavaScript
50 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Module dependencies
|
|
*/
|
|
var acl = require('acl');
|
|
|
|
// Using the memory backend
|
|
acl = new acl(new acl.memoryBackend());
|
|
|
|
/**
|
|
* Invoke Admin Permissions
|
|
*/
|
|
exports.invokeRolesPolicies = function () {
|
|
acl.allow([{
|
|
roles: ['admin'],
|
|
allows: [{
|
|
resources: '/api/users',
|
|
permissions: '*'
|
|
}, {
|
|
resources: '/api/users/:userId',
|
|
permissions: '*'
|
|
}]
|
|
}]);
|
|
};
|
|
|
|
/**
|
|
* Check If Admin Policy Allows
|
|
*/
|
|
exports.isAllowed = function (req, res, next) {
|
|
var roles = (req.user) ? req.user.roles : ['guest'];
|
|
|
|
// Check for user roles
|
|
acl.areAnyRolesAllowed(roles, req.route.path, req.method.toLowerCase(), function (err, isAllowed) {
|
|
if (err) {
|
|
// An authorization error occurred
|
|
return res.status(500).send('Unexpected authorization error');
|
|
} else {
|
|
if (isAllowed) {
|
|
// Access granted! Invoke next middleware
|
|
return next();
|
|
} else {
|
|
return res.status(403).json({
|
|
message: 'User is not authorized'
|
|
});
|
|
}
|
|
}
|
|
});
|
|
};
|