FEATURE: emit external_id field with user webhook

This commit is contained in:
Sam 2018-01-22 10:09:26 +11:00
parent fc36f095a7
commit 47058b29d3
4 changed files with 24 additions and 7 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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