settings: make user_directory setting route
This commit is contained in:
@@ -22,12 +22,6 @@ exports = module.exports = {
|
||||
getLanguage,
|
||||
setLanguage,
|
||||
|
||||
getProfileConfig,
|
||||
setProfileConfig,
|
||||
|
||||
getGhosts,
|
||||
setGhosts,
|
||||
|
||||
provider,
|
||||
list,
|
||||
initCache,
|
||||
@@ -117,9 +111,7 @@ const assert = require('assert'),
|
||||
mounts = require('./mounts.js'),
|
||||
paths = require('./paths.js'),
|
||||
safe = require('safetydance'),
|
||||
tokens = require('./tokens.js'),
|
||||
translation = require('./translation.js'),
|
||||
users = require('./users.js'),
|
||||
_ = require('underscore');
|
||||
|
||||
const SETTINGS_FIELDS = [ 'name', 'value' ].join(',');
|
||||
@@ -144,10 +136,6 @@ const gDefaults = (function () {
|
||||
result[exports.REGISTRY_CONFIG_KEY] = {
|
||||
provider: 'noop'
|
||||
};
|
||||
result[exports.PROFILE_CONFIG_KEY] = {
|
||||
lockUserProfiles: false,
|
||||
mandatory2FA: false
|
||||
};
|
||||
|
||||
result[exports.DASHBOARD_DOMAIN_KEY] = '';
|
||||
result[exports.DASHBOARD_FQDN_KEY] = '';
|
||||
@@ -159,8 +147,6 @@ const gDefaults = (function () {
|
||||
result[exports.CONSOLE_SERVER_ORIGIN_KEY] = 'https://console.cloudron.io';
|
||||
result[exports.DEMO_KEY] = false;
|
||||
|
||||
result[exports.GHOSTS_CONFIG_KEY] = {};
|
||||
|
||||
return result;
|
||||
})();
|
||||
|
||||
@@ -347,46 +333,6 @@ async function setRegistryConfig(registryConfig) {
|
||||
notifyChange(exports.REGISTRY_CONFIG_KEY, registryConfig);
|
||||
}
|
||||
|
||||
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 setProfileConfig(directoryConfig) {
|
||||
assert.strictEqual(typeof directoryConfig, 'object');
|
||||
|
||||
if (isDemo()) throw new BoxError(BoxError.BAD_FIELD, 'Not allowed in demo mode');
|
||||
|
||||
const oldConfig = await getProfileConfig();
|
||||
await set(exports.PROFILE_CONFIG_KEY, JSON.stringify(directoryConfig));
|
||||
|
||||
if (directoryConfig.mandatory2FA && !oldConfig.mandatory2FA) {
|
||||
debug('setProfileConfig: logging out non-2FA users to enforce 2FA');
|
||||
|
||||
const allUsers = await users.list();
|
||||
for (const user of allUsers) {
|
||||
if (!user.twoFactorAuthenticationEnabled) await tokens.delByUserIdAndType(user.id, tokens.ID_WEBADMIN);
|
||||
}
|
||||
}
|
||||
|
||||
notifyChange(exports.PROFILE_CONFIG_KEY, directoryConfig);
|
||||
}
|
||||
|
||||
async function getGhosts() {
|
||||
const value = await get(exports.GHOSTS_CONFIG_KEY);
|
||||
if (value === null) return gDefaults[exports.GHOSTS_CONFIG_KEY];
|
||||
|
||||
return JSON.parse(value);
|
||||
}
|
||||
|
||||
async function setGhosts(ghosts) {
|
||||
assert.strictEqual(typeof ghosts, 'object');
|
||||
|
||||
await set(exports.GHOSTS_CONFIG_KEY, JSON.stringify(ghosts));
|
||||
notifyChange(exports.GHOSTS_CONFIG_KEY, ghosts);
|
||||
}
|
||||
|
||||
async function getLanguage() {
|
||||
const value = await get(exports.LANGUAGE_KEY);
|
||||
if (value === null) return gDefaults[exports.LANGUAGE_KEY];
|
||||
@@ -414,7 +360,7 @@ async function list() {
|
||||
result[exports.DEMO_KEY] = !!result[exports.DEMO_KEY];
|
||||
|
||||
// convert JSON objects
|
||||
[exports.BACKUP_POLICY_KEY, exports.BACKUP_CONFIG_KEY, exports.PROFILE_CONFIG_KEY, exports.SERVICES_CONFIG_KEY,
|
||||
[exports.BACKUP_POLICY_KEY, exports.BACKUP_CONFIG_KEY, exports.SERVICES_CONFIG_KEY,
|
||||
exports.REGISTRY_CONFIG_KEY ].forEach(function (key) {
|
||||
result[key] = typeof result[key] === 'object' ? result[key] : safe.JSON.parse(result[key]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user