Skip to content

Commit

Permalink
Fix notifications being sent to disabled users or services
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Curnow committed Oct 29, 2018
1 parent e869e42 commit 673e9bd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/backend/internal/bitbucket-webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/backend/internal/dockerhub-webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/backend/internal/jenkins-webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/backend/internal/jira-webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/backend/internal/zendesk-webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 673e9bd

Please sign in to comment.