mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Renamed settings index.js to settings-service.js
- in line with our policy of not keeping logic in index.js files - Note: callign all services service.js is no more helpful :D
This commit is contained in:
parent
56a1143e53
commit
54b4a3c351
10 changed files with 87 additions and 90 deletions
|
@ -97,7 +97,7 @@ async function initCore({ghostServer, config, bootLogger, frontend}) {
|
|||
|
||||
// Settings are a core concept we use settings to store key-value pairs used in critical pathways as well as public data like the site title
|
||||
debug('Begin: settings');
|
||||
const settings = require('./server/services/settings');
|
||||
const settings = require('./server/services/settings/settings-service');
|
||||
await settings.init();
|
||||
await settings.syncEmailSettings(config.get('hostSettings:emailVerification:verified'));
|
||||
debug('End: settings');
|
||||
|
@ -235,7 +235,7 @@ async function initDynamicRouting() {
|
|||
routing.routerManager.start(routeSettings);
|
||||
const getRoutesHash = () => routeSettingsService.api.getCurrentHash();
|
||||
|
||||
const settings = require('./server/services/settings');
|
||||
const settings = require('./server/services/settings/settings-service');
|
||||
await settings.syncRoutesHash(getRoutesHash);
|
||||
|
||||
debug('End: Dynamic Routing');
|
||||
|
|
|
@ -4,7 +4,7 @@ const models = require('../../models');
|
|||
const routeSettings = require('../../services/route-settings');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const {BadRequestError} = require('@tryghost/errors');
|
||||
const settingsService = require('../../services/settings');
|
||||
const settingsService = require('../../services/settings/settings-service');
|
||||
const membersService = require('../../services/members');
|
||||
const stripeService = require('../../services/stripe');
|
||||
|
||||
|
@ -12,7 +12,7 @@ const settingsBREADService = settingsService.getSettingsBREADServiceInstance();
|
|||
|
||||
const messages = {
|
||||
failedSendingEmail: 'Failed Sending Email'
|
||||
|
||||
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -38,7 +38,7 @@ if (parentPort) {
|
|||
const permissions = require('./services/permissions');
|
||||
await permissions.init();
|
||||
|
||||
const settings = require('./services/settings');
|
||||
const settings = require('./services/settings/settings-service');
|
||||
await settings.init();
|
||||
// Finished INIT
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ const APIVersionCompatibilityService = require('@tryghost/api-version-compatibil
|
|||
const versionMismatchHandler = require('@tryghost/mw-api-version-mismatch');
|
||||
const ghostVersion = require('@tryghost/version');
|
||||
const {GhostMailer} = require('../mail');
|
||||
const settingsService = require('../../services/settings');
|
||||
const settingsService = require('../settings/settings-service');
|
||||
const models = require('../../models');
|
||||
const urlUtils = require('../../../shared/url-utils');
|
||||
const settingsCache = require('../../../shared/settings-cache');
|
||||
|
|
|
@ -1,77 +1 @@
|
|||
/**
|
||||
* Settings Lib
|
||||
* A collection of utilities for handling settings including a cache
|
||||
*/
|
||||
const events = require('../../lib/common/events');
|
||||
const models = require('../../models');
|
||||
const labs = require('../../../shared/labs');
|
||||
const SettingsCache = require('../../../shared/settings-cache');
|
||||
const SettingsBREADService = require('./settings-bread-service');
|
||||
const {obfuscatedSetting, isSecretSetting, hideValueIfSecret} = require('./settings-utils');
|
||||
|
||||
/**
|
||||
* @returns {SettingsBREADService} instance of the PostsService
|
||||
*/
|
||||
const getSettingsBREADServiceInstance = () => {
|
||||
return new SettingsBREADService({
|
||||
SettingsModel: models.Settings,
|
||||
settingsCache: SettingsCache,
|
||||
labsService: labs
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Initialize the cache, used in boot and in testing
|
||||
*/
|
||||
async init() {
|
||||
const settingsCollection = await models.Settings.populateDefaults();
|
||||
SettingsCache.init(events, settingsCollection);
|
||||
},
|
||||
|
||||
/**
|
||||
* Restore the cache, used during e2e testing only
|
||||
*/
|
||||
reset() {
|
||||
SettingsCache.reset(events);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles synchronization of routes.yaml hash loaded in the frontend with
|
||||
* the value stored in the settings table.
|
||||
* getRoutesHash is a function to allow keeping "frontend" decoupled from settings
|
||||
*
|
||||
* @param {function} getRoutesHash function fetching currently loaded routes file hash
|
||||
*/
|
||||
async syncRoutesHash(getRoutesHash) {
|
||||
const currentRoutesHash = await getRoutesHash();
|
||||
|
||||
if (SettingsCache.get('routes_hash') !== currentRoutesHash) {
|
||||
return await models.Settings.edit([{
|
||||
key: 'routes_hash',
|
||||
value: currentRoutesHash
|
||||
}], {context: {internal: true}});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles email setting synchronization when email has been verified per instance
|
||||
*
|
||||
* @param {boolean} configValue current email verification value from local config
|
||||
*/
|
||||
async syncEmailSettings(configValue) {
|
||||
const isEmailDisabled = SettingsCache.get('email_verification_required');
|
||||
|
||||
if (configValue === true && isEmailDisabled) {
|
||||
return await models.Settings.edit([{
|
||||
key: 'email_verification_required',
|
||||
value: false
|
||||
}], {context: {internal: true}});
|
||||
}
|
||||
},
|
||||
|
||||
obfuscatedSetting,
|
||||
isSecretSetting,
|
||||
hideValueIfSecret,
|
||||
getSettingsBREADServiceInstance
|
||||
};
|
||||
module.exports = require('./settings-service');
|
||||
|
|
77
core/server/services/settings/settings-service.js
Normal file
77
core/server/services/settings/settings-service.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* Settings Lib
|
||||
* A collection of utilities for handling settings including a cache
|
||||
*/
|
||||
const events = require('../../lib/common/events');
|
||||
const models = require('../../models');
|
||||
const labs = require('../../../shared/labs');
|
||||
const SettingsCache = require('../../../shared/settings-cache');
|
||||
const SettingsBREADService = require('./settings-bread-service');
|
||||
const {obfuscatedSetting, isSecretSetting, hideValueIfSecret} = require('./settings-utils');
|
||||
|
||||
/**
|
||||
* @returns {SettingsBREADService} instance of the PostsService
|
||||
*/
|
||||
const getSettingsBREADServiceInstance = () => {
|
||||
return new SettingsBREADService({
|
||||
SettingsModel: models.Settings,
|
||||
settingsCache: SettingsCache,
|
||||
labsService: labs
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Initialize the cache, used in boot and in testing
|
||||
*/
|
||||
async init() {
|
||||
const settingsCollection = await models.Settings.populateDefaults();
|
||||
SettingsCache.init(events, settingsCollection);
|
||||
},
|
||||
|
||||
/**
|
||||
* Restore the cache, used during e2e testing only
|
||||
*/
|
||||
reset() {
|
||||
SettingsCache.reset(events);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles synchronization of routes.yaml hash loaded in the frontend with
|
||||
* the value stored in the settings table.
|
||||
* getRoutesHash is a function to allow keeping "frontend" decoupled from settings
|
||||
*
|
||||
* @param {function} getRoutesHash function fetching currently loaded routes file hash
|
||||
*/
|
||||
async syncRoutesHash(getRoutesHash) {
|
||||
const currentRoutesHash = await getRoutesHash();
|
||||
|
||||
if (SettingsCache.get('routes_hash') !== currentRoutesHash) {
|
||||
return await models.Settings.edit([{
|
||||
key: 'routes_hash',
|
||||
value: currentRoutesHash
|
||||
}], {context: {internal: true}});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles email setting synchronization when email has been verified per instance
|
||||
*
|
||||
* @param {boolean} configValue current email verification value from local config
|
||||
*/
|
||||
async syncEmailSettings(configValue) {
|
||||
const isEmailDisabled = SettingsCache.get('email_verification_required');
|
||||
|
||||
if (configValue === true && isEmailDisabled) {
|
||||
return await models.Settings.edit([{
|
||||
key: 'email_verification_required',
|
||||
value: false
|
||||
}], {context: {internal: true}});
|
||||
}
|
||||
},
|
||||
|
||||
obfuscatedSetting,
|
||||
isSecretSetting,
|
||||
hideValueIfSecret,
|
||||
getSettingsBREADServiceInstance
|
||||
};
|
|
@ -1,8 +1,4 @@
|
|||
/**
|
||||
* The settings with type "site" were originally meant to be public
|
||||
* This has been misused - unsplash and slack are incorrectly stored there
|
||||
* https://github.com/TryGhost/Ghost/issues/10318
|
||||
*
|
||||
* This file acts as an allowlist for "public" settings
|
||||
*/
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ const ContentAPITestAgent = require('./content-api-test-agent');
|
|||
const db = require('./db-utils');
|
||||
|
||||
// Services that need resetting
|
||||
const settingsService = require('../../core/server/services/settings');
|
||||
const settingsService = require('../../core/server/services/settings/settings-service');
|
||||
|
||||
/**
|
||||
* @param {Object} [options={}]
|
||||
|
|
|
@ -15,7 +15,7 @@ const boot = require('../../core/boot');
|
|||
const db = require('../../core/server/data/db');
|
||||
const models = require('../../core/server/models');
|
||||
const urlService = require('../../core/server/services/url');
|
||||
const settingsService = require('../../core/server/services/settings');
|
||||
const settingsService = require('../../core/server/services/settings/settings-service');
|
||||
const routeSettingsService = require('../../core/server/services/route-settings');
|
||||
const themeService = require('../../core/server/services/themes');
|
||||
const limits = require('../../core/server/services/limits');
|
||||
|
|
|
@ -14,7 +14,7 @@ const models = require('../../core/server/models');
|
|||
const {fixtureManager} = require('../../core/server/data/schema/fixtures');
|
||||
const emailAnalyticsService = require('../../core/server/services/email-analytics');
|
||||
const permissions = require('../../core/server/services/permissions');
|
||||
const settingsService = require('../../core/server/services/settings');
|
||||
const settingsService = require('../../core/server/services/settings/settings-service');
|
||||
const labsService = require('../../core/shared/labs');
|
||||
|
||||
// Other Test Utilities
|
||||
|
|
Loading…
Reference in a new issue