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:
Blake Erickson 2019-10-21 16:24:41 -06:00 committed by GitHub
parent ceb74bef8f
commit ef0fe51e05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -3,6 +3,7 @@
class NotificationSerializer < ApplicationSerializer
attributes :id,
:user_id,
:notification_type,
:read,
:created_at,

View File

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