mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
FEATURE: emit external_id field with user webhook
This commit is contained in:
parent
fc36f095a7
commit
47058b29d3
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user