settings: move support config to support
This commit is contained in:
+13
-4
@@ -6,6 +6,8 @@ exports = module.exports = {
|
||||
getRemoteSupport,
|
||||
enableRemoteSupport,
|
||||
|
||||
getConfig,
|
||||
|
||||
canCreateTicket,
|
||||
canEnableRemoteSupport
|
||||
};
|
||||
@@ -13,15 +15,22 @@ exports = module.exports = {
|
||||
const appstore = require('../appstore.js'),
|
||||
assert = require('assert'),
|
||||
AuditSource = require('../auditsource.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
constants = require('../constants.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
safe = require('safetydance'),
|
||||
settings = require('../settings.js'),
|
||||
support = require('../support.js');
|
||||
|
||||
async function getConfig(req, res, next) {
|
||||
const [error, supportConfig] = await safe(support.getConfig());
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, supportConfig));
|
||||
}
|
||||
|
||||
async function canCreateTicket(req, res, next) {
|
||||
const [error, supportConfig] = await safe(settings.getSupportConfig());
|
||||
const [error, supportConfig] = await safe(support.getConfig());
|
||||
if (error) return next(new HttpError(503, error.message));
|
||||
|
||||
if (!supportConfig.submitTickets) return next(new HttpError(405, 'feature disabled by admin'));
|
||||
@@ -42,7 +51,7 @@ async function createTicket(req, res, next) {
|
||||
if (req.body.altEmail && typeof req.body.altEmail !== 'string') return next(new HttpError(400, 'altEmail must be string'));
|
||||
if (req.body.enableSshSupport && typeof req.body.enableSshSupport !== 'boolean') return next(new HttpError(400, 'enableSshSupport must be a boolean'));
|
||||
|
||||
const [error, supportConfig] = await safe(settings.getSupportConfig());
|
||||
const [error, supportConfig] = await safe(support.getConfig());
|
||||
if (error) return next(new HttpError(503, `Error getting support config: ${error.message}`));
|
||||
if (supportConfig.email !== constants.SUPPORT_EMAIL) return next(new HttpError(503, 'Sending to non-cloudron email not implemented yet'));
|
||||
|
||||
@@ -53,7 +62,7 @@ async function createTicket(req, res, next) {
|
||||
}
|
||||
|
||||
async function canEnableRemoteSupport(req, res, next) {
|
||||
const [error, supportConfig] = await safe(settings.getSupportConfig());
|
||||
const [error, supportConfig] = await safe(support.getConfig());
|
||||
if (error) return next(new HttpError(503, error.message));
|
||||
|
||||
if (!supportConfig.remoteSupport) return next(new HttpError(405, 'feature disabled by admin'));
|
||||
|
||||
Reference in New Issue
Block a user