diff --git a/app/jobs/regular/emit_web_hook_event.rb b/app/jobs/regular/emit_web_hook_event.rb index f58b558ebb1..82832d946d5 100644 --- a/app/jobs/regular/emit_web_hook_event.rb +++ b/app/jobs/regular/emit_web_hook_event.rb @@ -56,7 +56,6 @@ module Jobs def build_web_hook_body(args, web_hook) body = {} - guardian = Guardian.new(Discourse.system_user) event_type = args[:event_type].to_s if ping_event?(event_type) diff --git a/app/serializers/web_hook_user_serializer.rb b/app/serializers/web_hook_user_serializer.rb index 8ddd71c8e6c..e964174bad8 100644 --- a/app/serializers/web_hook_user_serializer.rb +++ b/app/serializers/web_hook_user_serializer.rb @@ -1,4 +1,6 @@ class WebHookUserSerializer < UserSerializer + attributes :external_id + # remove staff attributes def staff_attributes(*attrs) end @@ -6,4 +8,13 @@ class WebHookUserSerializer < UserSerializer def include_email? scope.is_admin? end + + def include_external_id? + scope.is_admin? && object.single_sign_on_record + end + + def external_id + object.single_sign_on_record.external_id + end + end diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rb index dbb53ca8371..73f4470c8f4 100644 --- a/spec/models/web_hook_spec.rb +++ b/spec/models/web_hook_spec.rb @@ -188,7 +188,7 @@ describe WebHook do end it 'should enqueue the right hooks for user events' do - user_web_hook = Fabricate(:user_web_hook, active: true) + _user_web_hook = Fabricate(:user_web_hook, active: true) Sidekiq::Testing.fake! do user diff --git a/spec/serializers/web_hook_user_serializer_spec.rb b/spec/serializers/web_hook_user_serializer_spec.rb index ad854ca13e2..3734587bb30 100644 --- a/spec/serializers/web_hook_user_serializer_spec.rb +++ b/spec/serializers/web_hook_user_serializer_spec.rb @@ -1,14 +1,21 @@ require 'rails_helper' RSpec.describe WebHookUserSerializer do - let(:user) { Fabricate(:user) } + let(:user) do + user = Fabricate(:user) + SingleSignOnRecord.create!(user_id: user.id, external_id: '12345', last_payload: '') + user + end + let(:admin) { Fabricate(:admin) } - subject { described_class.new(user, scope: Guardian.new(admin), root: false) } - - it "should include the user's email" do - payload = subject.as_json + let :serializer do + WebHookUserSerializer.new(user, scope: Guardian.new(admin), root: false) + end + it "should include relevant user info" do + payload = serializer.as_json expect(payload[:email]).to eq(user.email) + expect(payload[:external_id]).to eq('12345') end end