diff --git a/core/server/api/themes.js b/core/server/api/themes.js index b9c9d8271f..15c8f69363 100644 --- a/core/server/api/themes.js +++ b/core/server/api/themes.js @@ -9,7 +9,8 @@ var Promise = require('bluebird'), events = require('../events'), storage = require('../storage'), settings = require('./settings'), - utils = require('./utils'), + apiUtils = require('./utils'), + utils = require('./../utils'), i18n = require('../i18n'), themes; @@ -19,6 +20,13 @@ var Promise = require('bluebird'), * **See:** [API Methods](index.js.html#api%20methods) */ themes = { + loadThemes: function () { + return utils.readThemes(config.paths.themePath) + .then(function (result) { + config.paths.availableThemes = result; + }); + }, + upload: function upload(options) { options = options || {}; @@ -37,7 +45,7 @@ themes = { throw new errors.ValidationError(i18n.t('errors.api.themes.overrideCasper')); } - return utils.handlePermissions('themes', 'add')(options) + return apiUtils.handlePermissions('themes', 'add')(options) .then(function () { return gscan.checkZip(zip, {keepExtractedDir: true}); }) @@ -75,7 +83,7 @@ themes = { // force reload of availableThemes // right now the logic is in the ConfigManager // if we create a theme collection, we don't have to read them from disk - return config.loadThemes(); + return themes.loadThemes(); }) .then(function () { // the settings endpoint is used to fetch the availableThemes @@ -118,7 +126,7 @@ themes = { return Promise.reject(new errors.BadRequestError(i18n.t('errors.api.themes.invalidRequest'))); } - return utils.handlePermissions('themes', 'read')(options) + return apiUtils.handlePermissions('themes', 'read')(options) .then(function () { events.emit('theme.downloaded', themeName); return storageAdapter.serve({isTheme: true, name: themeName}); @@ -134,7 +142,7 @@ themes = { theme, storageAdapter = storage.getStorage('themes'); - return utils.handlePermissions('themes', 'destroy')(options) + return apiUtils.handlePermissions('themes', 'destroy')(options) .then(function () { if (name === 'casper') { throw new errors.ValidationError(i18n.t('errors.api.themes.destroyCasper')); @@ -150,7 +158,7 @@ themes = { return storageAdapter.delete(name, config.paths.themePath); }) .then(function () { - return config.loadThemes(); + return themes.loadThemes(); }) .then(function () { return settings.updateSettingsCache(); diff --git a/core/server/config/index.js b/core/server/config/index.js index dbec806b65..c8ff8a8c57 100644 --- a/core/server/config/index.js +++ b/core/server/config/index.js @@ -10,7 +10,6 @@ var path = require('path'), validator = require('validator'), readDirectory = require('../utils/read-directory'), - readThemes = require('../utils/read-themes'), errors = require('../errors'), configUrl = require('./url'), packageInfo = require('../../../package.json'), @@ -78,24 +77,12 @@ ConfigManager.prototype.init = function (rawConfig) { // just the object appropriate for this NODE_ENV self.set(rawConfig); - return self.loadThemes() - .then(function () { - return self.loadApps(); - }) + return self.loadApps() .then(function () { return self._config; }); }; -ConfigManager.prototype.loadThemes = function () { - var self = this; - - return readThemes(self._config.paths.themePath) - .then(function (result) { - self._config.paths.availableThemes = result; - }); -}; - ConfigManager.prototype.loadApps = function () { var self = this; @@ -232,7 +219,6 @@ ConfigManager.prototype.set = function (config) { adminViews: path.join(corePath, '/server/views/'), helperTemplates: path.join(corePath, '/server/helpers/tpl/'), - availableThemes: this._config.paths.availableThemes || {}, availableApps: this._config.paths.availableApps || {}, clientAssets: path.join(corePath, '/built/assets/') }, diff --git a/core/server/index.js b/core/server/index.js index d2f7671811..4fb20225c4 100644 --- a/core/server/index.js +++ b/core/server/index.js @@ -74,6 +74,8 @@ function init(options) { // Load our config.js file from the local file system. return config.load(options.config).then(function () { return config.checkDeprecated(); + }).then(function () { + return api.themes.loadThemes(); }).then(function () { models.init(); }).then(function () { diff --git a/core/server/utils/index.js b/core/server/utils/index.js index a0f5d9ace3..f6e602d0ff 100644 --- a/core/server/utils/index.js +++ b/core/server/utils/index.js @@ -102,7 +102,8 @@ utils = { readCSV: require('./read-csv'), removeOpenRedirectFromUrl: require('./remove-open-redirect-from-url'), - zipFolder: require('./zip-folder') + zipFolder: require('./zip-folder'), + readThemes: require('./read-themes') }; module.exports = utils; diff --git a/core/test/unit/config_spec.js b/core/test/unit/config_spec.js index 8a071d3569..ad8954365e 100644 --- a/core/test/unit/config_spec.js +++ b/core/test/unit/config_spec.js @@ -110,7 +110,6 @@ describe('Config', function () { 'imagesRelPath', 'adminViews', 'helperTemplates', - 'availableThemes', 'availableApps', 'clientAssets' );