mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add external_id to notification payload
If sso is enabled the notification payload will now include the external_id for the user. This was requested on meta: https://meta.discourse.org/t/-/129052/10
This commit is contained in:
parent
33554e5cbc
commit
a900c99993
@ -4,6 +4,7 @@ class NotificationSerializer < ApplicationSerializer
|
|||||||
|
|
||||||
attributes :id,
|
attributes :id,
|
||||||
:user_id,
|
:user_id,
|
||||||
|
:external_id,
|
||||||
:notification_type,
|
:notification_type,
|
||||||
:read,
|
:read,
|
||||||
:created_at,
|
:created_at,
|
||||||
@ -38,4 +39,12 @@ class NotificationSerializer < ApplicationSerializer
|
|||||||
object.data_hash
|
object.data_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def external_id
|
||||||
|
object.user&.single_sign_on_record&.external_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def include_external_id?
|
||||||
|
SiteSetting.enable_sso
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -13,5 +13,26 @@ describe NotificationSerializer do
|
|||||||
expect(json[:notification][:user_id]).to eq(user.id)
|
expect(json[:notification][:user_id]).to eq(user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not include external_id when sso is disabled" do
|
||||||
|
expect(json[:notification].key?(:external_id)).to eq(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#sso_enabled' do
|
||||||
|
let :user do
|
||||||
|
user = Fabricate(:user)
|
||||||
|
SingleSignOnRecord.create!(user_id: user.id, external_id: '12345', last_payload: '')
|
||||||
|
user
|
||||||
|
end
|
||||||
|
let(:notification) { Fabricate(:notification, user: user) }
|
||||||
|
let(:serializer) { NotificationSerializer.new(notification) }
|
||||||
|
let(:json) { serializer.as_json }
|
||||||
|
|
||||||
|
it "should include the external_id" do
|
||||||
|
SiteSetting.sso_url = "http://example.com/discourse_sso"
|
||||||
|
SiteSetting.sso_secret = "12345678910"
|
||||||
|
SiteSetting.enable_sso = true
|
||||||
|
expect(json[:notification][:external_id]).to eq("12345")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user