A platform for community discussion. Free, open, simple.
DEV: Add external_id to notification payload
Blake Ericksona900c99993aa
diff --git a/app/serializers/notification_serializer.rb b/app/serializers/notification_serializer.rbindex e01e639b457..18f0b9fcac4 100644--- a/app/serializers/notification_serializer.rb+++ b/app/serializers/notification_serializer.rb@@ -4,6 +4,7 @@ class NotificationSerializer < ApplicationSerializerattributes :id,:user_id,+ :external_id,:notification_type,:read,:created_at,@@ -38,4 +39,12 @@ class NotificationSerializer < ApplicationSerializerobject.data_hashend+ def external_id+ object.user&.single_sign_on_record&.external_id+ end++ def include_external_id?+ SiteSetting.enable_sso+ end+enddiff --git a/spec/serializers/notification_serializer_spec.rb b/spec/serializers/notification_serializer_spec.rbindex 63f305e00c4..afa03243a09 100644--- a/spec/serializers/notification_serializer_spec.rb+++ b/spec/serializers/notification_serializer_spec.rb@@ -13,5 +13,26 @@ describe NotificationSerializer doexpect(json[:notification][:user_id]).to eq(user.id)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")+ endendend