diff --git a/HISTORY.md b/HISTORY.md index d1dbaa0b2f3..6241f5134ed 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,7 @@ - [NEW] Permission `join-without-join-code` assigned to admins and bots by default (#6139) - [NEW] Integrations, both incoming and outgoing, now have access to the models. Example: `Users.findOneById(id)` (#6336) - [FIX] Incoming integrations would break when trying to use the `Store` feature. +- [FIX] Outgoing webhooks which have an error and they're retrying would still retry even if the integration was disabled. (#4835) ## 0.54.2 - 2017-Mar-24 diff --git a/packages/rocketchat-integrations/server/lib/triggerHandler.js b/packages/rocketchat-integrations/server/lib/triggerHandler.js index fc7212477f2..a4066474330 100644 --- a/packages/rocketchat-integrations/server/lib/triggerHandler.js +++ b/packages/rocketchat-integrations/server/lib/triggerHandler.js @@ -54,6 +54,16 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler } } + isTriggerEnabled(trigger) { + for (const trig of Object.values(this.triggers)) { + if (trig[trigger._id]) { + return trig[trigger._id].enabled; + } + } + + return false; + } + updateHistory({ historyId, step, integration, event, data, triggerWord, ranPrepareScript, prepareSentMessage, processSentMessage, resultMessage, finished, url, httpCallData, httpError, httpResult, error, errorStack }) { const history = { type: 'outgoing-webhook', @@ -532,7 +542,7 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler logger.outgoing.debug(`Found ${ triggersToExecute.length } to iterate over and see if the match the event.`); for (const triggerToExecute of triggersToExecute) { - logger.outgoing.debug(`Is ${ triggerToExecute.name } enabled, ${ triggerToExecute.enabled }, and what is the event? ${ triggerToExecute.event }`); + logger.outgoing.debug(`Is "${ triggerToExecute.name }" enabled, ${ triggerToExecute.enabled }, and what is the event? ${ triggerToExecute.event }`); if (triggerToExecute.enabled === true && triggerToExecute.event === event) { this.executeTrigger(triggerToExecute, argObject); } @@ -546,6 +556,11 @@ RocketChat.integrations.triggerHandler = new class RocketChatIntegrationHandler } executeTriggerUrl(url, trigger, { event, message, room, owner, user }, theHistoryId, tries = 0) { + if (!this.isTriggerEnabled(trigger)) { + logger.outgoing.warn(`The trigger "${ trigger.name }" is no longer enabled, stopping execution of it at try: ${ tries }`); + return; + } + logger.outgoing.debug(`Starting to execute trigger: ${ trigger.name } (${ trigger._id })`); let word;