Add supportConfig in database
This commit is contained in:
@@ -4,7 +4,10 @@ exports = module.exports = {
|
||||
createTicket: createTicket,
|
||||
|
||||
getRemoteSupport: getRemoteSupport,
|
||||
enableRemoteSupport: enableRemoteSupport
|
||||
enableRemoteSupport: enableRemoteSupport,
|
||||
|
||||
canCreateTicket: canCreateTicket,
|
||||
canEnableRemoteSupport: canEnableRemoteSupport
|
||||
};
|
||||
|
||||
var appstore = require('../appstore.js'),
|
||||
@@ -13,9 +16,20 @@ var appstore = require('../appstore.js'),
|
||||
constants = require('../constants.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
settings = require('../settings.js'),
|
||||
support = require('../support.js'),
|
||||
_ = require('underscore');
|
||||
|
||||
function canCreateTicket(req, res, next) {
|
||||
settings.getSupportConfig(function (error, supportConfig) {
|
||||
if (error) return next(new HttpError(503, error.message));
|
||||
|
||||
if (!supportConfig.submitTickets) return next(new HttpError(405, 'feature disabled by admin'));
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
function createTicket(req, res, next) {
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
@@ -28,10 +42,25 @@ function createTicket(req, res, next) {
|
||||
if (req.body.appId && typeof req.body.appId !== 'string') return next(new HttpError(400, 'appId must be string'));
|
||||
if (req.body.altEmail && typeof req.body.altEmail !== 'string') return next(new HttpError(400, 'altEmail must be string'));
|
||||
|
||||
appstore.createTicket(_.extend({ }, req.body, { email: req.user.email, displayName: req.user.displayName }), auditSource.fromRequest(req), function (error) {
|
||||
if (error) return next(new HttpError(503, `Error contacting cloudron.io: ${error.message}. Please email ${constants.SUPPORT_EMAIL}`));
|
||||
settings.getSupportConfig(function (error, supportConfig) {
|
||||
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'));
|
||||
|
||||
next(new HttpSuccess(201, { message: `An email for sent to ${constants.SUPPORT_EMAIL}. We will get back shortly!` }));
|
||||
appstore.createTicket(_.extend({ }, req.body, { email: req.user.email, displayName: req.user.displayName }), auditSource.fromRequest(req), function (error, result) {
|
||||
if (error) return next(new HttpError(503, `Error contacting cloudron.io: ${error.message}. Please email ${constants.SUPPORT_EMAIL}`));
|
||||
|
||||
next(new HttpSuccess(201, result));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function canEnableRemoteSupport(req, res, next) {
|
||||
settings.getSupportConfig(function (error, supportConfig) {
|
||||
if (error) return next(new HttpError(503, error.message));
|
||||
|
||||
if (!supportConfig.remoteSupport) return next(new HttpError(405, 'feature disabled by admin'));
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user