Skip to content

Commit

Permalink
Changes authorization and ACL initialization to avoid creating new AC…
Browse files Browse the repository at this point in the history
…L instances whenever ACL is requested by a module.
  • Loading branch information
ajmueller committed Jun 13, 2016
1 parent 5124371 commit b8ba012
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ var MongoStore = require('connect-mongo')(session);
var config = require('./config');

var authentication = require('./authentication');
var authorization = require('./authorization');

var app = express();

app.use(sslRedirect());

mongoose.connect(config.db.uri);
mongoose.connection.on('connected', function(test) {
authorization.init();
require('./authorization').init();
});
mongoose.connection.on('error', function() {
console.log('There is an issue with your MongoDB connection. Please make sure MongoDB is running.');
Expand Down
12 changes: 6 additions & 6 deletions authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ var acl = require('acl');
var mongoose = require('mongoose');
var config = require('./config');

acl = new acl(new acl.mongodbBackend(mongoose.connection.db, config.db.aclCollectionPrefix), { debug: function(string) { console.log(string); } });

module.exports = {
init: function() {
var aclInstance = module.exports.getAcl();

aclInstance.addRoleParents('superAdmin', 'admin');
aclInstance.addRoleParents('admin', 'user');
acl.addRoleParents('superAdmin', 'admin');
acl.addRoleParents('admin', 'user');

aclInstance.allow([
acl.allow([
{
roles: ['admin'],
allows: [
Expand All @@ -32,6 +32,6 @@ module.exports = {
},

getAcl: function() {
return new acl(new acl.mongodbBackend(mongoose.connection.db, config.db.aclCollectionPrefix), { debug: function(string) { console.log(string); } });
return acl;
}
};

0 comments on commit b8ba012

Please sign in to comment.