FIX: Include deleted topics in the post serializer
This commit is contained in:
parent
b16471edfb
commit
1446753fd2
|
@ -82,7 +82,7 @@ class PostSerializer < BasicPostSerializer
|
|||
end
|
||||
|
||||
def topic_slug
|
||||
object.topic && object.topic.slug
|
||||
topic&.slug
|
||||
end
|
||||
|
||||
def include_topic_title?
|
||||
|
@ -98,15 +98,15 @@ class PostSerializer < BasicPostSerializer
|
|||
end
|
||||
|
||||
def topic_title
|
||||
object.topic.title
|
||||
topic&.title
|
||||
end
|
||||
|
||||
def topic_html_title
|
||||
object.topic.fancy_title
|
||||
topic&.fancy_title
|
||||
end
|
||||
|
||||
def category_id
|
||||
object.topic.category_id
|
||||
topic&.category_id
|
||||
end
|
||||
|
||||
def moderator?
|
||||
|
@ -376,6 +376,12 @@ class PostSerializer < BasicPostSerializer
|
|||
|
||||
private
|
||||
|
||||
def topic
|
||||
@topic = object.topic
|
||||
@topic ||= Topic.with_deleted.find(object.topic_id) if scope.is_staff?
|
||||
@topic
|
||||
end
|
||||
|
||||
def post_actions
|
||||
@post_actions ||= (@topic_view&.all_post_actions || {})[object.id]
|
||||
end
|
||||
|
|
|
@ -3,10 +3,13 @@ require 'rails_helper'
|
|||
RSpec.describe WebHookPostSerializer do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:serializer) { WebHookPostSerializer.new(post, scope: Guardian.new(admin), root: false) }
|
||||
|
||||
def serialized_for_user(u)
|
||||
WebHookPostSerializer.new(post, scope: Guardian.new(u), root: false).as_json
|
||||
end
|
||||
|
||||
it 'should only include the required keys' do
|
||||
count = serializer.as_json.keys.count
|
||||
count = serialized_for_user(admin).keys.count
|
||||
difference = count - 41
|
||||
|
||||
expect(difference).to eq(0), lambda {
|
||||
|
@ -21,4 +24,18 @@ RSpec.describe WebHookPostSerializer do
|
|||
message << "\nPlease verify if those key(s) are required as part of the web hook's payload."
|
||||
}
|
||||
end
|
||||
|
||||
it 'should only include deleted topic title for staffs' do
|
||||
topic = post.topic
|
||||
PostDestroyer.new(Discourse.system_user, post).destroy
|
||||
post.reload
|
||||
|
||||
[nil, post.user, Fabricate(:user)].each do |user|
|
||||
expect(serialized_for_user(user)[:topic_title]).to eq(nil)
|
||||
end
|
||||
|
||||
[Fabricate(:moderator), admin].each do |user|
|
||||
expect(serialized_for_user(user)[:topic_title]).to eq(topic.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue