Skip to content

A platform for community discussion. Free, open, simple.

DEV: allow tracking opts on post_revisor (#38525)

Sam077f81c5a46b
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index 9d957f7f2aa..ddebab0fe38 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -84,7 +84,8 @@ class PostRevisor
POST_TRACKED_FIELDS = %w[raw cooked edit_reason user_id wiki post_type locale]
- attr_reader :category_changed, :post_revision
+ # Extensions can inspect revision options via the `:post_edited` event payload.
+ attr_reader :category_changed, :post_revision, :opts
def initialize(post, topic = post.topic)
@post = post
diff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rb
index c6d0ef34551..4918e0bc7a1 100644
--- a/spec/lib/post_revisor_spec.rb
+++ b/spec/lib/post_revisor_spec.rb
@@ -1000,6 +1000,19 @@ describe PostRevisor do
expect(events).to include(event_name: :before_edit_post, params: [post, params])
end
end
+
+ context "when editing the post_edited event signature for extensibility" do
+ it "exposes revise opts via the PostRevisor payload" do
+ params = { raw: "body (edited)" }
+ opts = { suggested_edit: true }
+
+ events = DiscourseEvent.track_events { post_revisor.revise!(user, params, opts) }
+ event = events.find { |e| e[:event_name] == :post_edited }
+
+ expect(event[:params].third).to be_kind_of(PostRevisor)
+ expect(event[:params].third.opts).to include(suggested_edit: true)
+ end
+ end
end
describe "topic excerpt" do