From 673e9bd62b2442b6b0d16258c651b68e3e801699 Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Mon, 29 Oct 2018 11:54:39 +1000 Subject: [PATCH] Fix notifications being sent to disabled users or services --- src/backend/internal/bitbucket-webhook.js | 4 ++++ src/backend/internal/dockerhub-webhook.js | 5 +++++ src/backend/internal/jenkins-webhook.js | 5 +++++ src/backend/internal/jira-webhook.js | 5 +++++ src/backend/internal/zendesk-webhook.js | 5 +++++ 5 files changed, 24 insertions(+) diff --git a/src/backend/internal/bitbucket-webhook.js b/src/backend/internal/bitbucket-webhook.js index f022086..740d58b 100644 --- a/src/backend/internal/bitbucket-webhook.js +++ b/src/backend/internal/bitbucket-webhook.js @@ -637,10 +637,14 @@ const internalBitbucketWebhook = { // This complex query should only get the rules for users where the event type is requested and the incoming service username is defined // and where a notification hasn't already been sent to a user for this webhook + // and where the user is not disabled, and the services are not deleted let query = ruleModel .query() .select('rule.*', 'in_sd.service_username AS in_service_username') + .joinRaw('INNER JOIN user ON user.id = rule.user_id AND user.is_disabled = 0 AND user.is_deleted = 0') + .joinRaw('INNER JOIN service AS in_service ON in_service.id = rule.in_service_id AND in_service.is_deleted = 0') + .joinRaw('INNER JOIN service AS out_service ON out_service.id = rule.out_service_id AND out_service.is_deleted = 0') .joinRaw('INNER JOIN user_has_service_data AS in_sd ON in_sd.user_id = rule.user_id AND in_sd.service_id = rule.in_service_id') .where('rule.is_deleted', 0) .andWhere('rule.in_service_id', data.service_id) diff --git a/src/backend/internal/dockerhub-webhook.js b/src/backend/internal/dockerhub-webhook.js index a754e88..4fe8516 100644 --- a/src/backend/internal/dockerhub-webhook.js +++ b/src/backend/internal/dockerhub-webhook.js @@ -244,10 +244,15 @@ const internalDockerhubWebhook = { // This complex query should only get the rules for users // where a notification hasn't already been sent to a user for this webhook + // and where a notification hasn't already been sent to a user for this webhook + // and where the user is not disabled, and the services are not deleted let query = ruleModel .query() .select('rule.*') + .joinRaw('INNER JOIN user ON user.id = rule.user_id AND user.is_disabled = 0 AND user.is_deleted = 0') + .joinRaw('INNER JOIN service AS in_service ON in_service.id = rule.in_service_id AND in_service.is_deleted = 0') + .joinRaw('INNER JOIN service AS out_service ON out_service.id = rule.out_service_id AND out_service.is_deleted = 0') .where('rule.is_deleted', 0) .andWhere('rule.in_service_id', data.service_id) .andWhere('rule.trigger', event_type) diff --git a/src/backend/internal/jenkins-webhook.js b/src/backend/internal/jenkins-webhook.js index 139db38..2cd416a 100644 --- a/src/backend/internal/jenkins-webhook.js +++ b/src/backend/internal/jenkins-webhook.js @@ -282,10 +282,15 @@ const internalJenkinsWebhook = { // This complex query should only get the rules for users // where a notification hasn't already been sent to a user for this webhook + // and where a notification hasn't already been sent to a user for this webhook + // and where the user is not disabled, and the services are not deleted let query = ruleModel .query() .select('rule.*') + .joinRaw('INNER JOIN user ON user.id = rule.user_id AND user.is_disabled = 0 AND user.is_deleted = 0') + .joinRaw('INNER JOIN service AS in_service ON in_service.id = rule.in_service_id AND in_service.is_deleted = 0') + .joinRaw('INNER JOIN service AS out_service ON out_service.id = rule.out_service_id AND out_service.is_deleted = 0') .where('rule.is_deleted', 0) .andWhere('rule.in_service_id', data.service_id) .andWhere('rule.trigger', event_type) diff --git a/src/backend/internal/jira-webhook.js b/src/backend/internal/jira-webhook.js index dc6163b..30552e4 100644 --- a/src/backend/internal/jira-webhook.js +++ b/src/backend/internal/jira-webhook.js @@ -838,10 +838,15 @@ const internalJiraWebhook = { // This complex query should only get the rules for users where the event type is requested and the incoming service username is defined // and where a notification hasn't already been sent to a user for this webhook + // and where a notification hasn't already been sent to a user for this webhook + // and where the user is not disabled, and the services are not deleted let query = ruleModel .query() .select('rule.*', 'in_sd.service_username AS in_service_username') + .joinRaw('INNER JOIN user ON user.id = rule.user_id AND user.is_disabled = 0 AND user.is_deleted = 0') + .joinRaw('INNER JOIN service AS in_service ON in_service.id = rule.in_service_id AND in_service.is_deleted = 0') + .joinRaw('INNER JOIN service AS out_service ON out_service.id = rule.out_service_id AND out_service.is_deleted = 0') .joinRaw('INNER JOIN user_has_service_data AS in_sd ON in_sd.user_id = rule.user_id AND in_sd.service_id = rule.in_service_id') .where('rule.is_deleted', 0) .andWhere('rule.in_service_id', data.service_id) diff --git a/src/backend/internal/zendesk-webhook.js b/src/backend/internal/zendesk-webhook.js index e583b52..d740119 100644 --- a/src/backend/internal/zendesk-webhook.js +++ b/src/backend/internal/zendesk-webhook.js @@ -607,10 +607,15 @@ const internalZendeskWebhook = { // This complex query should only get the rules for users where the event type is requested and the incoming service username is defined // and where a notification hasn't already been sent to a user for this webhook // Note: the table's `service_username` here should be the Zendesk Email Address, lowercased. + // and where a notification hasn't already been sent to a user for this webhook + // and where the user is not disabled, and the services are not deleted let query = ruleModel .query() .select('rule.*', 'in_sd.service_username AS in_service_username') + .joinRaw('INNER JOIN user ON user.id = rule.user_id AND user.is_disabled = 0 AND user.is_deleted = 0') + .joinRaw('INNER JOIN service AS in_service ON in_service.id = rule.in_service_id AND in_service.is_deleted = 0') + .joinRaw('INNER JOIN service AS out_service ON out_service.id = rule.out_service_id AND out_service.is_deleted = 0') .joinRaw('INNER JOIN user_has_service_data AS in_sd ON in_sd.user_id = rule.user_id AND in_sd.service_id = rule.in_service_id') .where('rule.is_deleted', 0) .andWhere('rule.in_service_id', data.service_id)