Skip to content

Commit

Permalink
🎨 change how we get and set config
Browse files Browse the repository at this point in the history
refs #6982
- a replace for all config usages
- always use config.get or config.set
- this a pure replacement, no logic has changed

[ci skip]
  • Loading branch information
kirrg001 authored and ErisDS committed Sep 20, 2016
1 parent 4aaacff commit 0ae0a0b
Show file tree
Hide file tree
Showing 77 changed files with 315 additions and 317 deletions.
2 changes: 1 addition & 1 deletion core/server/api/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ authentication = {
}

function sendResetNotification(data) {
var baseUrl = config.forceAdminSSL ? (config.urlSSL || config.url) : config.url,
var baseUrl = config.get('forceAdminSSL') ? (config.get('urlSSL') || config.get('url')) : config.get('url'),
resetUrl = baseUrl.replace(/\/$/, '') +
'/ghost/reset/' +
globalUtils.encodeBase64URLsafe(data.resetToken) + '/';
Expand Down
12 changes: 6 additions & 6 deletions core/server/api/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ function fetchAvailableTimezones() {

function getAboutConfig() {
return {
version: config.ghostVersion,
version: config.get('ghostVersion'),
environment: process.env.NODE_ENV,
database: config.database.client,
mail: _.isObject(config.mail) ? config.mail.transport : ''
database: config.get('database').client,
mail: _.isObject(config.get('mail')) ? config.get('mail').transport : ''
};
}

Expand All @@ -33,9 +33,9 @@ function getBaseConfig() {
useGravatar: {value: !config.isPrivacyDisabled('useGravatar'), type: 'bool'},
publicAPI: labsFlag('publicAPI'),
internalTags: labsFlag('internalTags'),
blogUrl: {value: config.url.replace(/\/$/, ''), type: 'string'},
blogTitle: {value: config.theme.title, type: 'string'},
routeKeywords: {value: JSON.stringify(config.routeKeywords), type: 'json'}
blogUrl: {value: config.get('url').replace(/\/$/, ''), type: 'string'},
blogTitle: {value: config.get('theme').title, type: 'string'},
routeKeywords: {value: JSON.stringify(config.get('routeKeywords')), type: 'json'}
};
}

Expand Down
2 changes: 1 addition & 1 deletion core/server/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ cacheInvalidationHeader = function cacheInvalidationHeader(req, result) {
if (hasStatusChanged || wasPublishedUpdated) {
return INVALIDATE_ALL;
} else {
return config.urlFor({relativeUrl: '/' + config.routeKeywords.preview + '/' + post.uuid + '/'});
return utils.url.urlFor({relativeUrl: '/' + config.get('routeKeywords').preview + '/' + post.uuid + '/'});
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions core/server/api/schedules.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ var _ = require('lodash'),
Promise = require('bluebird'),
moment = require('moment'),
config = require('../config'),
pipeline = require(config.paths.corePath + '/server/utils/pipeline'),
dataProvider = require(config.paths.corePath + '/server/models'),
i18n = require(config.paths.corePath + '/server/i18n'),
errors = require(config.paths.corePath + '/server/errors'),
apiPosts = require(config.paths.corePath + '/server/api/posts'),
pipeline = require(config.get('paths').corePath + '/server/utils/pipeline'),
dataProvider = require(config.get('paths').corePath + '/server/models'),
i18n = require(config.get('paths').corePath + '/server/i18n'),
errors = require(config.get('paths').corePath + '/server/errors'),
apiPosts = require(config.get('paths').corePath + '/server/api/posts'),
utils = require('./utils');

/**
Expand All @@ -21,7 +21,7 @@ exports.publishPost = function publishPost(object, options) {
}

var post, publishedAtMoment,
publishAPostBySchedulerToleranceInMinutes = config.times.publishAPostBySchedulerToleranceInMinutes;
publishAPostBySchedulerToleranceInMinutes = config.get('times').publishAPostBySchedulerToleranceInMinutes;

// CASE: only the scheduler client is allowed to publish (hardcoded because of missing client permission system)
if (!options.context || !options.context.client || options.context.client !== 'ghost-scheduler') {
Expand Down
32 changes: 16 additions & 16 deletions core/server/api/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ updateConfigCache = function () {
}
}

config.set({
theme: {
title: (settingsCache.title && settingsCache.title.value) || '',
description: (settingsCache.description && settingsCache.description.value) || '',
logo: (settingsCache.logo && settingsCache.logo.value) || '',
cover: (settingsCache.cover && settingsCache.cover.value) || '',
navigation: (settingsCache.navigation && JSON.parse(settingsCache.navigation.value)) || [],
postsPerPage: (settingsCache.postsPerPage && settingsCache.postsPerPage.value) || 5,
permalinks: (settingsCache.permalinks && settingsCache.permalinks.value) || '/:slug/',
twitter: (settingsCache.twitter && settingsCache.twitter.value) || '',
facebook: (settingsCache.facebook && settingsCache.facebook.value) || '',
timezone: (settingsCache.activeTimezone && settingsCache.activeTimezone.value) || config.theme.timezone
},
labs: labsValue
config.set('theme:title', (settingsCache.title && settingsCache.title.value) || '');
config.set('theme:description', (settingsCache.description && settingsCache.description.value) || '');
config.set('theme:logo', (settingsCache.logo && settingsCache.logo.value) || '');
config.set('theme:cover', (settingsCache.cover && settingsCache.cover.value) || '');
config.set('theme:navigation', (settingsCache.navigation && JSON.parse(settingsCache.navigation.value)) || []);
config.set('theme:postsPerPage', (settingsCache.postsPerPage && settingsCache.postsPerPage.value) || config.get('theme').postsPerPage);
config.set('theme:permalinks', (settingsCache.permalinks && settingsCache.permalinks.value) || config.get('theme').permalinks);
config.set('theme:twitter', (settingsCache.twitter && settingsCache.twitter.value) || '');
config.set('theme:facebook', (settingsCache.facebook && settingsCache.facebook.value) || '');
config.set('theme:timezone', (settingsCache.activeTimezone && settingsCache.activeTimezone.value) || config.get('theme').timezone);
config.set('theme:url', config.get('url') ? config.get('url').replace(/\/$/, '') : '');

_.each(labsValue, function (value, key) {
config.set('labs:' + key, value);
});
};

Expand Down Expand Up @@ -177,8 +177,8 @@ readSettingsResult = function (settingsModels) {

return memo;
}, {}),
themes = config.paths.availableThemes,
apps = config.paths.availableApps,
themes = config.get('paths').availableThemes,
apps = config.get('paths').availableApps,
res;

if (settings.activeTheme && themes) {
Expand Down
16 changes: 8 additions & 8 deletions core/server/api/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ var Promise = require('bluebird'),
*/
themes = {
loadThemes: function () {
return utils.readThemes(config.paths.themePath)
return utils.readThemes(config.get('paths').themePath)
.then(function (result) {
config.paths.availableThemes = result;
config.set('paths:availableThemes', result);
});
},

Expand Down Expand Up @@ -63,12 +63,12 @@ themes = {
);
})
.then(function () {
return storageAdapter.exists(config.paths.themePath + '/' + zip.shortName);
return storageAdapter.exists(config.get('paths').themePath + '/' + zip.shortName);
})
.then(function (themeExists) {
// delete existing theme
if (themeExists) {
return storageAdapter.delete(zip.shortName, config.paths.themePath);
return storageAdapter.delete(zip.shortName, config.get('paths').themePath);
}
})
.then(function () {
Expand All @@ -77,7 +77,7 @@ themes = {
return storageAdapter.save({
name: zip.shortName,
path: theme.path
}, config.paths.themePath);
}, config.get('paths').themePath);
})
.then(function () {
// force reload of availableThemes
Expand Down Expand Up @@ -119,7 +119,7 @@ themes = {

download: function download(options) {
var themeName = options.name,
theme = config.paths.availableThemes[themeName],
theme = config.get('paths').availableThemes[themeName],
storageAdapter = storage.getStorage('themes');

if (!theme) {
Expand Down Expand Up @@ -148,14 +148,14 @@ themes = {
throw new errors.ValidationError(i18n.t('errors.api.themes.destroyCasper'));
}

theme = config.paths.availableThemes[name];
theme = config.get('paths').availableThemes[name];

if (!theme) {
throw new errors.NotFoundError(i18n.t('errors.api.themes.themeDoesNotExist'));
}

events.emit('theme.deleted', name);
return storageAdapter.delete(name, config.paths.themePath);
return storageAdapter.delete(name, config.get('paths').themePath);
})
.then(function () {
return themes.loadThemes();
Expand Down
2 changes: 1 addition & 1 deletion core/server/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sendInviteEmail = function sendInviteEmail(user) {

return dataProvider.User.generateResetToken(user.email, expires, dbHash);
}).then(function (resetToken) {
var baseUrl = config.forceAdminSSL ? (config.urlSSL || config.url) : config.url;
var baseUrl = config.get('forceAdminSSL') ? (config.get('urlSSL') || config.get('url')) : config.get('url');

emailData.resetLink = baseUrl.replace(/\/$/, '') + '/ghost/signup/' + globalUtils.encodeBase64URLsafe(resetToken) + '/';

Expand Down
2 changes: 1 addition & 1 deletion core/server/apps/amp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ module.exports = {
},

setupRoutes: function setupRoutes(blogRouter) {
blogRouter.use('*/' + config.routeKeywords.amp + '/', router);
blogRouter.use('*/' + config.get('routeKeywords').amp + '/', router);
}
};
2 changes: 1 addition & 1 deletion core/server/apps/amp/lib/helpers/amp_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function getAmperizeHTML(html, post) {
}

// make relative URLs abolute
html = makeAbsoluteUrl(html, config.url, post.url).html();
html = makeAbsoluteUrl(html, config.get('url'), post.url).html();

if (!amperizeCache[post.id] || moment(new Date(amperizeCache[post.id].updated_at)).diff(new Date(post.updated_at)) < 0) {
return new Promise(function (resolve) {
Expand Down
2 changes: 1 addition & 1 deletion core/server/apps/amp/tests/router_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('AMP Controller', function () {
body: {}
};

defaultPath = path.join(configUtils.config.paths.appRoot, '/core/server/apps/amp/lib/views/amp.hbs');
defaultPath = path.join(configUtils.config.get('paths').appRoot, '/core/server/apps/amp/lib/views/amp.hbs');

configUtils.set({
theme: {
Expand Down
6 changes: 3 additions & 3 deletions core/server/apps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ function getInstalledApps() {
return Promise.reject(e);
}

return installed.concat(config.internalApps);
return installed.concat(config.get('internalApps'));
});
}

function saveInstalledApps(installedApps) {
return getInstalledApps().then(function (currentInstalledApps) {
var updatedAppsInstalled = _.difference(_.uniq(installedApps.concat(currentInstalledApps)), config.internalApps);
var updatedAppsInstalled = _.difference(_.uniq(installedApps.concat(currentInstalledApps)), config.get('internalApps'));

return api.settings.edit({settings: [{key: 'installedApps', value: updatedAppsInstalled}]}, {context: {internal: true}});
});
Expand All @@ -44,7 +44,7 @@ module.exports = {

appsToLoad = JSON.parse(aApps.value) || [];

appsToLoad = appsToLoad.concat(config.internalApps);
appsToLoad = appsToLoad.concat(config.get('internalApps'));
});
} catch (e) {
errors.logError(
Expand Down
6 changes: 3 additions & 3 deletions core/server/apps/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ var path = require('path'),
loader;

function isInternalApp(name) {
return _.includes(config.internalApps, name);
return _.includes(config.get('internalApps'), name);
}

// Get the full path to an app by name
function getAppAbsolutePath(name) {
if (isInternalApp(name)) {
return path.join(config.paths.internalAppPath, name);
return path.join(config.get('paths').internalAppPath, name);
}

return path.join(config.paths.appPath, name);
return path.join(config.get('paths').appPath, name);
}

// Get a relative path to the given apps root, defaults
Expand Down
4 changes: 2 additions & 2 deletions core/server/apps/private-blogging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
if (utils.url.getSubdir()) {
var paths = utils.url.getSubdir().split('/');

if (paths.pop() === config.routeKeywords.private) {
if (paths.pop() === config.get('routeKeywords').private) {
errors.logErrorAndExit(
new Error(i18n.t('errors.config.urlCannotContainPrivateSubdir.error')),
i18n.t('errors.config.urlCannotContainPrivateSubdir.description'),
Expand All @@ -26,6 +26,6 @@ module.exports = {
},

setupRoutes: function setupRoutes(blogRouter) {
blogRouter.use('/' + config.routeKeywords.private + '/', router);
blogRouter.use('/' + config.get('routeKeywords').private + '/', router);
}
};
2 changes: 1 addition & 1 deletion core/server/apps/private-blogging/lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var _ = require('lodash'),
session = require('cookie-session'),
utils = require('../../../utils'),
i18n = require('../../../i18n'),
privateRoute = '/' + config.routeKeywords.private + '/',
privateRoute = '/' + config.get('routeKeywords').private + '/',
protectedSecurity = [],
privateBlogging;

Expand Down
2 changes: 1 addition & 1 deletion core/server/apps/private-blogging/tests/controller_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Private Controller', function () {
params: {}
};

defaultPath = path.join(configUtils.config.paths.appRoot, '/core/server/apps/private-blogging/lib/views/private.hbs');
defaultPath = path.join(configUtils.config.get('paths').appRoot, '/core/server/apps/private-blogging/lib/views/private.hbs');

configUtils.set({
theme: {
Expand Down
4 changes: 2 additions & 2 deletions core/server/apps/subscribers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function makeHidden(name, extras) {
function subscribeFormHelper(options) {
var root = options.data.root,
data = _.merge({}, options.hash, _.pick(root, params), {
action: path.join('/', globalUtils.url.getSubdir(), config.routeKeywords.subscribe, '/'),
action: path.join('/', globalUtils.url.getSubdir(), config.get('routeKeywords').subscribe, '/'),
script: new hbs.handlebars.SafeString(subscribeScript),
hidden: new hbs.handlebars.SafeString(
makeHidden('confirm') +
Expand Down Expand Up @@ -71,7 +71,7 @@ module.exports = {
},

setupRoutes: function setupRoutes(blogRouter) {
blogRouter.use('/' + config.routeKeywords.subscribe + '/', function labsEnabledRouter(req, res, next) {
blogRouter.use('/' + config.get('routeKeywords').subscribe + '/', function labsEnabledRouter(req, res, next) {
if (labs.isSet('subscribers') === true) {
return router.apply(this, arguments);
}
Expand Down
2 changes: 1 addition & 1 deletion core/server/config/overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"themes": {
"extensions": [".zip"],
"contentTypes": ["application/zip", "application/x-zip-compressed"]
"contentTypes": ["application/zip", "application/x-zip-compressed", "application/octet-stream"]
}
},
"storage": {
Expand Down
4 changes: 2 additions & 2 deletions core/server/controllers/frontend/channel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ channelConfig = function channelConfig() {
},
tag: {
name: 'tag',
route: '/' + config.routeKeywords.tag + '/:slug/',
route: '/' + config.get('routeKeywords').tag + '/:slug/',
postOptions: {
filter: 'tags:\'%s\''
},
Expand All @@ -27,7 +27,7 @@ channelConfig = function channelConfig() {
},
author: {
name: 'author',
route: '/' + config.routeKeywords.author + '/:slug/',
route: '/' + config.get('routeKeywords').author + '/:slug/',
postOptions: {
filter: 'author:\'%s\''
},
Expand Down
6 changes: 3 additions & 3 deletions core/server/controllers/frontend/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var express = require('express'),
channelRouter;

function handlePageParam(req, res, next, page) {
var pageRegex = new RegExp('/' + config.routeKeywords.page + '/(.*)?/'),
var pageRegex = new RegExp('/' + config.get('routeKeywords').page + '/(.*)?/'),
rssRegex = new RegExp('/rss/(.*)?/');

page = parseInt(page, 10);
Expand Down Expand Up @@ -50,8 +50,8 @@ rssRouter = function rssRouter(channelConfig) {
router.get('/feed/', function redirectToRSS(req, res) {
return utils.redirect301(res, utils.url.getSubdir() + req.baseUrl + baseRoute);
});
router.param('page', handlePageParam);

router.param('page', handlePageParam);
return router;
};

Expand All @@ -65,7 +65,7 @@ channelRouter = function router() {

var channelsRouter = express.Router({mergeParams: true}),
baseRoute = '/',
pageRoute = '/' + config.routeKeywords.page + '/:page/';
pageRoute = '/' + config.get('routeKeywords').page + '/:page/';

_.each(channelConfig.list(), function (channel) {
var channelRouter = express.Router({mergeParams: true}),
Expand Down
6 changes: 3 additions & 3 deletions core/server/controllers/frontend/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
var config = require('../../config'),

// Context patterns, should eventually come from Channel configuration
privatePattern = new RegExp('^\\/' + config.routeKeywords.private + '\\/'),
subscribePattern = new RegExp('^\\/' + config.routeKeywords.subscribe + '\\/'),
ampPattern = new RegExp('\\/' + config.routeKeywords.amp + '\\/$'),
privatePattern = new RegExp('^\\/' + config.get('routeKeywords').private + '\\/'),
subscribePattern = new RegExp('^\\/' + config.get('routeKeywords').subscribe + '\\/'),
ampPattern = new RegExp('\\/' + config.get('routeKeywords').amp + '\\/$'),
rssPattern = new RegExp('^\\/rss\\/'),
homePattern = new RegExp('^\\/$');

Expand Down
2 changes: 1 addition & 1 deletion core/server/controllers/frontend/fetch-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ _.extend(defaultPostQuery, queryDefaults, {
function fetchPostsPerPage(options) {
options = options || {};

var postsPerPage = parseInt(config.theme.postsPerPage);
var postsPerPage = parseInt(config.get('theme').postsPerPage);

// No negative posts per page, must be number
if (!isNaN(postsPerPage) && postsPerPage > 0) {
Expand Down
2 changes: 1 addition & 1 deletion core/server/controllers/frontend/post-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function getOptionsFormat(linkStructure) {

function postLookup(postUrl) {
var postPath = url.parse(postUrl).path,
postPermalink = config.theme.permalinks,
postPermalink = config.get('theme').permalinks,
pagePermalink = '/:slug/',
isEditURL = false,
isAmpURL = false,
Expand Down
Loading

0 comments on commit 0ae0a0b

Please sign in to comment.