Skip to content

Commit

Permalink
🎨 load themes not in ConfigManager (#7342)
Browse files Browse the repository at this point in the history
refs #6982
  • Loading branch information
kirrg001 authored and ErisDS committed Sep 20, 2016
1 parent 55d1e86 commit a639e48
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
20 changes: 14 additions & 6 deletions core/server/api/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 || {};

Expand All @@ -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});
})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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});
Expand All @@ -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'));
Expand All @@ -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();
Expand Down
16 changes: 1 addition & 15 deletions core/server/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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/')
},
Expand Down
2 changes: 2 additions & 0 deletions core/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
3 changes: 2 additions & 1 deletion core/server/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 0 additions & 1 deletion core/test/unit/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ describe('Config', function () {
'imagesRelPath',
'adminViews',
'helperTemplates',
'availableThemes',
'availableApps',
'clientAssets'
);
Expand Down

0 comments on commit a639e48

Please sign in to comment.