From 788f4e9e39906b7424e67172eb76985ca8fdbdb4 Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Wed, 15 May 2019 18:32:29 -0300 Subject: [PATCH] Livechat CRM secret token optional (#14022) --- app/livechat/server/config.js | 2 +- app/livechat/server/hooks/sendToCRM.js | 3 +-- app/livechat/server/lib/Livechat.js | 11 +++++------ server/startup/migrations/index.js | 1 + server/startup/migrations/v145.js | 17 +++++++++++++++++ 5 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 server/startup/migrations/v145.js diff --git a/app/livechat/server/config.js b/app/livechat/server/config.js index ec72d838583..92c6ced8322 100644 --- a/app/livechat/server/config.js +++ b/app/livechat/server/config.js @@ -157,7 +157,7 @@ Meteor.startup(function() { i18nLabel: 'Webhook_URL', }); - settings.add('Livechat_secret_token', false, { + settings.add('Livechat_secret_token', '', { type: 'string', group: 'Livechat', section: 'CRM_Integration', diff --git a/app/livechat/server/hooks/sendToCRM.js b/app/livechat/server/hooks/sendToCRM.js index a09b06177e9..8e5dd50d80e 100644 --- a/app/livechat/server/hooks/sendToCRM.js +++ b/app/livechat/server/hooks/sendToCRM.js @@ -6,9 +6,8 @@ import { Livechat } from '../lib/Livechat'; const msgNavType = 'livechat_navigation_history'; const crmEnabled = () => { - const secretToken = settings.get('Livechat_secret_token'); const webhookUrl = settings.get('Livechat_webhookUrl'); - return secretToken !== '' && secretToken !== undefined && webhookUrl !== '' && webhookUrl !== undefined; + return webhookUrl !== '' && webhookUrl !== undefined; }; const sendMessageType = (msgType) => { diff --git a/app/livechat/server/lib/Livechat.js b/app/livechat/server/lib/Livechat.js index 0826a5ee2ac..2119a53f908 100644 --- a/app/livechat/server/lib/Livechat.js +++ b/app/livechat/server/lib/Livechat.js @@ -583,12 +583,11 @@ export const Livechat = { sendRequest(postData, callback, trying = 1) { try { - const options = { - headers: { - 'X-RocketChat-Livechat-Token': settings.get('Livechat_secret_token'), - }, - data: postData, - }; + const options = { data: postData }; + const secretToken = settings.get('Livechat_secret_token'); + if (secretToken !== '' && secretToken !== undefined) { + Object.assign(options, { headers: { 'X-RocketChat-Livechat-Token': secretToken } }); + } return HTTP.post(settings.get('Livechat_webhookUrl'), options); } catch (e) { Livechat.logger.webhook.error(`Response error on ${ trying } try ->`, e); diff --git a/server/startup/migrations/index.js b/server/startup/migrations/index.js index 404e61fded3..9b4975b7342 100644 --- a/server/startup/migrations/index.js +++ b/server/startup/migrations/index.js @@ -142,4 +142,5 @@ import './v141'; import './v142'; import './v143'; import './v144'; +import './v145'; import './xrun'; diff --git a/server/startup/migrations/v145.js b/server/startup/migrations/v145.js new file mode 100644 index 00000000000..f0f81bda68b --- /dev/null +++ b/server/startup/migrations/v145.js @@ -0,0 +1,17 @@ +import { Migrations } from '../../../app/migrations'; +import { Settings } from '../../../app/models'; + +Migrations.add({ + version: 145, + up() { + const setting = Settings.findOne({ _id: 'Livechat_secret_token' }); + + if (setting && setting.value === false) { + Settings.update({ _id: 'Livechat_secret_token' }, { + $set: { + value: '', + }, + }); + } + }, +});