From 6cbcfac72b5e37b4f94d7bb10cd1c324d1f8af23 Mon Sep 17 00:00:00 2001 From: Harry Wolff Date: Sun, 21 Sep 2014 16:54:32 -0400 Subject: [PATCH] Removes objectTypeModelMap to reduce circular dependency. refs #2455 - also note areas where we still have lazy loading of modules. - moves one lazy loading to non-lazy require. --- core/server/api/mail.js | 3 +-- core/server/errors/index.js | 2 +- core/server/permissions/index.js | 9 +++++++-- core/server/permissions/object-type-model-map.js | 7 ------- 4 files changed, 9 insertions(+), 12 deletions(-) delete mode 100644 core/server/permissions/object-type-model-map.js diff --git a/core/server/api/mail.js b/core/server/api/mail.js index 8fa794c969..da49ddf04a 100644 --- a/core/server/api/mail.js +++ b/core/server/api/mail.js @@ -5,6 +5,7 @@ var _ = require('lodash'), config = require('../config'), canThis = require('../permissions').canThis, errors = require('../errors'), + mailer = require('../mail'), Models = require('../models'), path = require('path'), fs = require('fs'), @@ -29,8 +30,6 @@ mail = { * @returns {Promise} */ send: function (object, options) { - var mailer = require('../mail'); - return canThis(options.context).send.mail().then(function () { return mailer.send(object.mail[0].message) .then(function (data) { diff --git a/core/server/errors/index.js b/core/server/errors/index.js index 05179aa8ce..3075863f66 100644 --- a/core/server/errors/index.js +++ b/core/server/errors/index.js @@ -24,7 +24,7 @@ var _ = require('lodash'), colors.setTheme({silly: 'rainbow'}); // Shim right now to deal with circular dependencies. -// @TODO: remove circular dependency +// @TODO(hswolff): remove circular dependency and lazy require. function getConfigModule() { if (!config) { config = require('../config'); diff --git a/core/server/permissions/index.js b/core/server/permissions/index.js index a9781c5f7d..86e49b6a71 100644 --- a/core/server/permissions/index.js +++ b/core/server/permissions/index.js @@ -50,8 +50,13 @@ CanThisResult = function () { }; CanThisResult.prototype.buildObjectTypeHandlers = function (objTypes, actType, context, permissionLoad) { - // @TODO: remove this lazy require - var objectTypeModelMap = require('./object-type-model-map'); + var objectTypeModelMap = { + post: Models.Post, + role: Models.Role, + user: Models.User, + permission: Models.Permission, + setting: Models.Settings + }; // Iterate through the object types, i.e. ['post', 'tag', 'user'] return _.reduce(objTypes, function (objTypeHandlers, objType) { diff --git a/core/server/permissions/object-type-model-map.js b/core/server/permissions/object-type-model-map.js deleted file mode 100644 index 9845093489..0000000000 --- a/core/server/permissions/object-type-model-map.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - post: require('../models/post').Post, - role: require('../models/role').Role, - user: require('../models/user').User, - permission: require('../models/permission').Permission, - setting: require('../models/settings').Settings -};