diff --git a/migrations/20220113223425-settings-rename-directory-config-to-profile-config.js b/migrations/20220113223425-settings-rename-directory-config-to-profile-config.js new file mode 100644 index 000000000..2d1fc3abb --- /dev/null +++ b/migrations/20220113223425-settings-rename-directory-config-to-profile-config.js @@ -0,0 +1,9 @@ +'use strict'; + +exports.up = function(db, callback) { + db.runSql('UPDATE settings SET name=? WHERE name=?', [ 'directory_config', 'profile_config' ], callback); +}; + +exports.down = function(db, callback) { + db.runSql('UPDATE settings SET name=? WHERE name=?', [ 'profile_config', 'directory_config' ], callback); +}; diff --git a/src/appstore.js b/src/appstore.js index 30137da7c..b8a404968 100644 --- a/src/appstore.js +++ b/src/appstore.js @@ -49,7 +49,7 @@ let gFeatures = { privateDockerRegistry: false, branding: false, support: false, - directoryConfig: false, + profileConfig: false, mailboxMaxCount: 5, emailPremium: false }; diff --git a/src/cloudron.js b/src/cloudron.js index e05e17b38..f7adf18a0 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -157,8 +157,8 @@ async function getConfig() { cloudronName: allSettings[settings.CLOUDRON_NAME_KEY], footer: branding.renderFooter(allSettings[settings.FOOTER_KEY] || constants.FOOTER), features: appstore.getFeatures(), - profileLocked: allSettings[settings.DIRECTORY_CONFIG_KEY].lockUserProfiles, - mandatory2FA: allSettings[settings.DIRECTORY_CONFIG_KEY].mandatory2FA + profileLocked: allSettings[settings.PROFILE_CONFIG_KEY].lockUserProfiles, + mandatory2FA: allSettings[settings.PROFILE_CONFIG_KEY].mandatory2FA }; } diff --git a/src/routes/settings.js b/src/routes/settings.js index 58b0b7f47..718db5679 100644 --- a/src/routes/settings.js +++ b/src/routes/settings.js @@ -5,7 +5,7 @@ exports = module.exports = { get, // owner only settings - setBackupConfig + setBackupConfig, }; const assert = require('assert'), @@ -235,20 +235,20 @@ async function setRegistryConfig(req, res, next) { next(new HttpSuccess(200)); } -async function getDirectoryConfig(req, res, next) { - const [error, directoryConfig] = await safe(settings.getDirectoryConfig()); +async function getProfileConfig(req, res, next) { + const [error, directoryConfig] = await safe(settings.getProfileConfig()); if (error) return next(BoxError.toHttpError(error)); next(new HttpSuccess(200, directoryConfig)); } -async function setDirectoryConfig(req, res, next) { +async function setProfileConfig(req, res, next) { assert.strictEqual(typeof req.body, 'object'); if (typeof req.body.lockUserProfiles !== 'boolean') return next(new HttpError(400, 'lockUserProfiles is required')); if (typeof req.body.mandatory2FA !== 'boolean') return next(new HttpError(400, 'mandatory2FA is required')); - const [error] = await safe(settings.setDirectoryConfig(req.body)); + const [error] = await safe(settings.setProfileConfig(req.body)); if (error) return next(BoxError.toHttpError(error)); next(new HttpSuccess(200, {})); @@ -307,7 +307,7 @@ function get(req, res, next) { case settings.AUTOUPDATE_PATTERN_KEY: return getAutoupdatePattern(req, res, next); case settings.TIME_ZONE_KEY: return getTimeZone(req, res, next); - case settings.DIRECTORY_CONFIG_KEY: return getDirectoryConfig(req, res, next); + case settings.PROFILE_CONFIG_KEY: return getProfileConfig(req, res, next); case settings.SUPPORT_CONFIG_KEY: return getSupportConfig(req, res, next); default: return next(new HttpError(404, 'No such setting')); @@ -330,7 +330,7 @@ function set(req, res, next) { case settings.AUTOUPDATE_PATTERN_KEY: return setAutoupdatePattern(req, res, next); case settings.TIME_ZONE_KEY: return setTimeZone(req, res, next); - case settings.DIRECTORY_CONFIG_KEY: return setDirectoryConfig(req, res, next); + case settings.PROFILE_CONFIG_KEY: return setProfileConfig(req, res, next); default: return next(new HttpError(404, 'No such setting')); } diff --git a/src/settings.js b/src/settings.js index 1fce6fff6..35fdf6de4 100644 --- a/src/settings.js +++ b/src/settings.js @@ -58,8 +58,8 @@ exports = module.exports = { getFooter, setFooter, - getDirectoryConfig, - setDirectoryConfig, + getProfileConfig, + setProfileConfig, getAppstoreListingConfig, setAppstoreListingConfig, @@ -105,7 +105,7 @@ exports = module.exports = { SYSINFO_CONFIG_KEY: 'sysinfo_config', APPSTORE_LISTING_CONFIG_KEY: 'appstore_listing_config', SUPPORT_CONFIG_KEY: 'support_config', - DIRECTORY_CONFIG_KEY: 'directory_config', + PROFILE_CONFIG_KEY: 'profile_config', GHOSTS_CONFIG_KEY: 'ghosts_config', REVERSE_PROXY_CONFIG_KEY: 'reverseproxy_config', @@ -204,7 +204,7 @@ const gDefaults = (function () { result[exports.SYSINFO_CONFIG_KEY] = { provider: 'generic' }; - result[exports.DIRECTORY_CONFIG_KEY] = { + result[exports.PROFILE_CONFIG_KEY] = { lockUserProfiles: false, mandatory2FA: false }; @@ -608,19 +608,19 @@ async function setSysinfoConfig(sysinfoConfig) { notifyChange(exports.SYSINFO_CONFIG_KEY, sysinfoConfig); } -async function getDirectoryConfig() { - const value = await get(exports.DIRECTORY_CONFIG_KEY); - if (value === null) return gDefaults[exports.DIRECTORY_CONFIG_KEY]; +async function getProfileConfig() { + const value = await get(exports.PROFILE_CONFIG_KEY); + if (value === null) return gDefaults[exports.PROFILE_CONFIG_KEY]; return JSON.parse(value); } -async function setDirectoryConfig(directoryConfig) { +async function setProfileConfig(directoryConfig) { assert.strictEqual(typeof directoryConfig, 'object'); if (isDemo()) throw new BoxError(BoxError.BAD_FIELD, 'Not allowed in demo mode'); - const oldConfig = await getDirectoryConfig(); - await set(exports.DIRECTORY_CONFIG_KEY, JSON.stringify(directoryConfig)); + const oldConfig = await getProfileConfig(); + await set(exports.PROFILE_CONFIG_KEY, JSON.stringify(directoryConfig)); if (directoryConfig.mandatory2FA && !oldConfig.mandatory2FA) { debug('setDirectoryConfig: logging out non-2FA users to enforce 2FA'); @@ -631,7 +631,7 @@ async function setDirectoryConfig(directoryConfig) { } } - notifyChange(exports.DIRECTORY_CONFIG_KEY, directoryConfig); + notifyChange(exports.PROFILE_CONFIG_KEY, directoryConfig); } async function getReverseProxyConfig() { @@ -758,7 +758,7 @@ async function list() { result[exports.DEMO_KEY] = !!result[exports.DEMO_KEY]; // convert JSON objects - [exports.BACKUP_CONFIG_KEY, exports.DIRECTORY_CONFIG_KEY, exports.SERVICES_CONFIG_KEY, exports.EXTERNAL_LDAP_KEY, exports.REGISTRY_CONFIG_KEY, exports.SYSINFO_CONFIG_KEY, exports.REVERSE_PROXY_CONFIG_KEY ].forEach(function (key) { + [exports.BACKUP_CONFIG_KEY, exports.PROFILE_CONFIG_KEY, exports.SERVICES_CONFIG_KEY, exports.EXTERNAL_LDAP_KEY, exports.REGISTRY_CONFIG_KEY, exports.SYSINFO_CONFIG_KEY, exports.REVERSE_PROXY_CONFIG_KEY ].forEach(function (key) { result[key] = typeof result[key] === 'object' ? result[key] : safe.JSON.parse(result[key]); });