FIX: Include user id in notification webhook (#8195)
The payload when receiving a notification webhook is pointless without knowing which user the notification is for. This fix adds the user_id to the notification serializer so that when you receive a notification webhook you can properly identify which user the notification is for. See https://meta.discourse.org/t/getting-the-target-user-for-notification-webhook-events/129052?u=blake for more details.
This commit is contained in:
parent
ceb74bef8f
commit
ef0fe51e05
|
@ -3,6 +3,7 @@
|
||||||
class NotificationSerializer < ApplicationSerializer
|
class NotificationSerializer < ApplicationSerializer
|
||||||
|
|
||||||
attributes :id,
|
attributes :id,
|
||||||
|
:user_id,
|
||||||
:notification_type,
|
:notification_type,
|
||||||
:read,
|
:read,
|
||||||
:created_at,
|
:created_at,
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe NotificationSerializer do
|
||||||
|
describe '#as_json' do
|
||||||
|
fab!(:user) { Fabricate(:user) }
|
||||||
|
let(:notification) { Fabricate(:notification, user: user) }
|
||||||
|
let(:serializer) { NotificationSerializer.new(notification) }
|
||||||
|
let(:json) { serializer.as_json }
|
||||||
|
|
||||||
|
it "returns the user_id" do
|
||||||
|
expect(json[:notification][:user_id]).to eq(user.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue