From 75932e2805b7a4a2e73711724eac04cee1d3bbba Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Mon, 5 Mar 2018 17:03:54 +0100 Subject: [PATCH] Collect app information for feedback email --- src/appstore.js | 23 +++++++++++++++++------ src/routes/cloudron.js | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/appstore.js b/src/appstore.js index 226147a99..1d8c39782 100644 --- a/src/appstore.js +++ b/src/appstore.js @@ -18,7 +18,8 @@ exports = module.exports = { AppstoreError: AppstoreError }; -var assert = require('assert'), +var apps = require('./apps.js'), + assert = require('assert'), async = require('async'), config = require('./config.js'), debug = require('debug')('box:appstore'), @@ -311,16 +312,26 @@ function sendFeedback(info, callback) { assert.strictEqual(typeof info.description, 'string'); assert.strictEqual(typeof callback, 'function'); + function collectAppInfoIfNeeded(callback) { + if (!info.appId) return callback(); + apps.get(info.appId, callback); + } + getAppstoreConfig(function (error, appstoreConfig) { if (error) return callback(error); - var url = config.apiServerOrigin() + '/api/v1/users/' + appstoreConfig.userId + '/cloudrons/' + appstoreConfig.cloudronId + '/feedback'; + collectAppInfoIfNeeded(function (error, result) { + if (error) console.error('Unable to get app info', error); + if (result) info.app = result; - superagent.post(url).query({ accessToken: appstoreConfig.token }).send(info).timeout(10 * 1000).end(function (error, result) { - if (error && !error.response) return callback(new AppstoreError(AppstoreError.EXTERNAL_ERROR, error)); - if (result.statusCode !== 201) return callback(new AppstoreError(AppstoreError.EXTERNAL_ERROR, util.format('Bad response: %s %s', result.statusCode, result.text))); + var url = config.apiServerOrigin() + '/api/v1/users/' + appstoreConfig.userId + '/cloudrons/' + appstoreConfig.cloudronId + '/feedback'; - callback(null); + superagent.post(url).query({ accessToken: appstoreConfig.token }).send(info).timeout(10 * 1000).end(function (error, result) { + if (error && !error.response) return callback(new AppstoreError(AppstoreError.EXTERNAL_ERROR, error)); + if (result.statusCode !== 201) return callback(new AppstoreError(AppstoreError.EXTERNAL_ERROR, util.format('Bad response: %s %s', result.statusCode, result.text))); + + callback(null); + }); }); }); } diff --git a/src/routes/cloudron.js b/src/routes/cloudron.js index 72009d60d..a20de70e1 100644 --- a/src/routes/cloudron.js +++ b/src/routes/cloudron.js @@ -89,6 +89,7 @@ function feedback(req, res, next) { if (VALID_TYPES.indexOf(req.body.type) === -1) return next(new HttpError(400, 'unknown type')); if (typeof req.body.subject !== 'string' || !req.body.subject) return next(new HttpError(400, 'subject must be string')); if (typeof req.body.description !== 'string' || !req.body.description) return next(new HttpError(400, 'description must be string')); + if (req.body.appId && typeof req.body.appId !== 'string') return next(new HttpError(400, 'appId must be string')); appstore.sendFeedback(_.extend(req.body, { email: req.user.email, displayName: req.user.displayName }), function (error) { if (error && error.reason === AppstoreError.BILLING_REQUIRED) return next(new HttpError(402, 'Login to App Store to create support tickets. You can also email support@cloudron.io'));