From 37cc056c1bf24fdeaa2fd55f432dc2442b0c9ec5 Mon Sep 17 00:00:00 2001 From: Selase Krakani <849886+s3lase@users.noreply.github.com> Date: Wed, 26 Apr 2023 22:38:28 +0000 Subject: [PATCH] FIX: Ensure group-filtered group user event webhooks fire (#21254) Group user event webhooks filtered by group fail silently because the `group_ids` job arg wasn't being passed into the job. This change add's `group_ids` to the `EmitWebHookEvent` jobs queued for `user_added_to_group` and `user_removed_from_group` events. --- app/models/group.rb | 1 + config/initializers/012-web_hook_events.rb | 1 + spec/models/web_hook_spec.rb | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/app/models/group.rb b/app/models/group.rb index 5e63d19b97d..741ae34e265 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -810,6 +810,7 @@ class Group < ActiveRecord::Base :user_removed_from_group, id: group_user.id, payload: payload, + group_ids: [self.id], ) end diff --git a/config/initializers/012-web_hook_events.rb b/config/initializers/012-web_hook_events.rb index cf769d96da3..d7a7e2979b8 100644 --- a/config/initializers/012-web_hook_events.rb +++ b/config/initializers/012-web_hook_events.rb @@ -100,6 +100,7 @@ DiscourseEvent.on(:user_added_to_group) do |user, group, options| group_user, :user_added_to_group, WebHookGroupUserSerializer, + group_ids: [group.id], ) end diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rb index 2752997d846..4ededd18a81 100644 --- a/spec/models/web_hook_spec.rb +++ b/spec/models/web_hook_spec.rb @@ -558,7 +558,10 @@ RSpec.describe WebHook do job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first expect(job_args["event_name"]).to eq("user_added_to_group") + expect(job_args["group_ids"]).to contain_exactly(group.id) + payload = JSON.parse(job_args["payload"]) + expect(payload["group_id"]).to eq(group.id) expect(payload["user_id"]).to eq(user.id) expect(payload["notification_level"]).to eq(group.default_notification_level) @@ -577,7 +580,10 @@ RSpec.describe WebHook do job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first expect(job_args["event_name"]).to eq("user_removed_from_group") + expect(job_args["group_ids"]).to contain_exactly(group.id) + payload = JSON.parse(job_args["payload"]) + expect(payload["group_id"]).to eq(group.id) expect(payload["user_id"]).to eq(user.id) end