mirror of
https://github.com/discourse/discourse.git
synced 2026-09-05 04:40:41 -05:00
FIX: Suggested topic links to nested replies topics (#40302)
Fixes bug reported here -> https://meta.discourse.org/t/link-to-nested-topic-in-my-suggested-topics-doesnt-work/403743?u=markvanlan
This commit is contained in:
@@ -16,6 +16,7 @@ class SuggestedTopicSerializer < ListableTopicSerializer
|
||||
:category_id,
|
||||
:featured_link,
|
||||
:featured_link_root_domain,
|
||||
:is_nested_view,
|
||||
:op_like_count
|
||||
has_many :posters, serializer: SuggestedPosterSerializer, embed: :objects
|
||||
|
||||
@@ -38,4 +39,12 @@ class SuggestedTopicSerializer < ListableTopicSerializer
|
||||
def include_featured_link_root_domain?
|
||||
SiteSetting.topic_featured_link_enabled && object.featured_link
|
||||
end
|
||||
|
||||
def is_nested_view
|
||||
true
|
||||
end
|
||||
|
||||
def include_is_nested_view?
|
||||
object.nested_view?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,6 +22,7 @@ class SuggestedTopicsBuilder
|
||||
results = results.where(category_id: @category_id)
|
||||
end
|
||||
|
||||
results = results.includes(:nested_topic) if SiteSetting.nested_replies_enabled
|
||||
results = results.to_a
|
||||
results.reject! { |topic| @category_topic_ids.include?(topic.id) }
|
||||
|
||||
|
||||
@@ -77,4 +77,23 @@ RSpec.describe SuggestedTopicSerializer do
|
||||
expect(json[:op_like_count]).to eq(5)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#is_nested_view" do
|
||||
before { SiteSetting.nested_replies_enabled = true }
|
||||
|
||||
it "returns true when the topic uses nested replies" do
|
||||
topic = Fabricate(:topic)
|
||||
Fabricate(:nested_topic, topic: topic)
|
||||
|
||||
json = SuggestedTopicSerializer.new(topic, scope: Guardian.new(user), root: false).as_json
|
||||
expect(json[:is_nested_view]).to eq(true)
|
||||
end
|
||||
|
||||
it "omits the attribute when the topic uses the flat view" do
|
||||
topic = Fabricate(:topic)
|
||||
|
||||
json = SuggestedTopicSerializer.new(topic, scope: Guardian.new(user), root: false).as_json
|
||||
expect(json).not_to have_key(:is_nested_view)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user