settings: async'ify
* directory config * unstable app config
This commit is contained in:
@@ -23,16 +23,15 @@ const assert = require('assert'),
|
||||
users = require('../users.js'),
|
||||
_ = require('underscore');
|
||||
|
||||
function authorize(req, res, next) {
|
||||
async function authorize(req, res, next) {
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
settings.getDirectoryConfig(function (error, directoryConfig) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error, directoryConfig] = await settings.getDirectoryConfig();
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
if (directoryConfig.lockUserProfiles) return next(new HttpError(403, 'admin has disallowed users from editing profiles'));
|
||||
if (directoryConfig.lockUserProfiles) return next(new HttpError(403, 'admin has disallowed users from editing profiles'));
|
||||
|
||||
next();
|
||||
});
|
||||
next();
|
||||
}
|
||||
|
||||
async function get(req, res, next) {
|
||||
|
||||
@@ -15,6 +15,7 @@ const assert = require('assert'),
|
||||
externalLdap = require('../externalldap.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
safe = require('safetydance'),
|
||||
settings = require('../settings.js');
|
||||
|
||||
function getAutoupdatePattern(req, res, next) {
|
||||
@@ -165,24 +166,22 @@ function setDynamicDnsConfig(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
function getUnstableAppsConfig(req, res, next) {
|
||||
settings.getUnstableAppsConfig(function (error, enabled) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
async function getUnstableAppsConfig(req, res, next) {
|
||||
const [error, enabled] = await safe(settings.getUnstableAppsConfig());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { enabled: enabled }));
|
||||
});
|
||||
next(new HttpSuccess(200, { enabled }));
|
||||
}
|
||||
|
||||
function setUnstableAppsConfig(req, res, next) {
|
||||
async function setUnstableAppsConfig(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
if (typeof req.body.enabled !== 'boolean') return next(new HttpError(400, 'enabled boolean is required'));
|
||||
|
||||
settings.setUnstableAppsConfig(req.body.enabled, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error] = await safe(settings.setUnstableAppsConfig(req.body.enabled));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
});
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
function getRegistryConfig(req, res, next) {
|
||||
@@ -211,25 +210,23 @@ function setRegistryConfig(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
function getDirectoryConfig(req, res, next) {
|
||||
settings.getDirectoryConfig(function (error, directoryConfig) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
async function getDirectoryConfig(req, res, next) {
|
||||
const [error, directoryConfig] = await settings.getDirectoryConfig();
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, directoryConfig));
|
||||
});
|
||||
next(new HttpSuccess(200, directoryConfig));
|
||||
}
|
||||
|
||||
function setDirectoryConfig(req, res, next) {
|
||||
async function setDirectoryConfig(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'));
|
||||
|
||||
settings.setDirectoryConfig(req.body, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error] = await safe(settings.setDirectoryConfig(req.body));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, {}));
|
||||
});
|
||||
next(new HttpSuccess(200, {}));
|
||||
}
|
||||
|
||||
function getSysinfoConfig(req, res, next) {
|
||||
|
||||
Reference in New Issue
Block a user