DEV: Add modifier to SuggestedTopicsBuilder#add_results (#29164)

This commit is contained in:
Mark VanLandingham 2024-10-10 10:03:26 -05:00 committed by GitHub
parent 8105b545c3
commit 882c2da29e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View File

@ -36,6 +36,7 @@ class SuggestedTopicsBuilder
end end
end end
results = DiscoursePluginRegistry.apply_modifier(:suggested_topics_add_results, results)
splice_results(results, priority) splice_results(results, priority)
end end
end end

View File

@ -98,5 +98,30 @@ RSpec.describe SuggestedTopicsBuilder do
expect(builder).not_to be_full expect(builder).not_to be_full
end end
end end
context "with suggested_topics_add_results modifier registered" do
fab!(:included_topic) { Fabricate(:topic) }
fab!(:excluded_topic) { Fabricate(:topic) }
let(:modifier_block) do
Proc.new { |results| results.filter { |topic| topic.id != excluded_topic.id } }
end
it "Allows modifications to added results" do
plugin_instance = Plugin::Instance.new
plugin_instance.register_modifier(:suggested_topics_add_results, &modifier_block)
builder.add_results(Topic.where(id: [included_topic.id, excluded_topic.id]))
expect(builder.results).to include(included_topic)
expect(builder.results).not_to include(excluded_topic)
ensure
DiscoursePluginRegistry.unregister_modifier(
plugin_instance,
:suggested_topics_add_results,
&modifier_block
)
end
end
end end
end end