Skip to content

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

FIX: Notify subscribers of custom flags created after boot

Régis Hanol995c593aba14
diff --git a/lib/post_action_creator.rb b/lib/post_action_creator.rb
index ab5dcdffed3..80632b3f4cc 100644
--- a/lib/post_action_creator.rb
+++ b/lib/post_action_creator.rb
@@ -200,15 +200,11 @@ class PostActionCreator
likes_count: @post.like_count + 1,
user_id: @created_by.id,
}
- elsif self.class.notify_types.include?(@post_action_name)
+ elsif flagging_post?
@post.publish_change_to_clients! :acted
end
end
- def self.notify_types
- @notify_types ||= PostActionType.notify_flag_types.keys
- end
-
def enforce_rules
auto_close_if_threshold_reached
auto_hide_if_needed
diff --git a/lib/post_action_destroyer.rb b/lib/post_action_destroyer.rb
index f9b4476f1d6..e987485f60f 100644
--- a/lib/post_action_destroyer.rb
+++ b/lib/post_action_destroyer.rb
@@ -81,10 +81,6 @@ class PostActionDestroyer
protected
- def self.notify_types
- @notify_types ||= PostActionType.notify_flag_types.keys
- end
-
def notify_subscribers
name = post_action_type_view.types[@post_action_type_id]
if name == :like
@@ -92,7 +88,7 @@ class PostActionDestroyer
:unliked,
{ likes_count: @post.like_count, user_id: @destroyed_by.id },
)
- elsif self.class.notify_types.include?(name)
+ elsif post_action_type_view.notify_flag_type_ids.include?(@post_action_type_id)
@post.publish_change_to_clients!(:acted)
end
end
diff --git a/spec/lib/post_action_creator_spec.rb b/spec/lib/post_action_creator_spec.rb
index 80118dd314c..01a871d13ac 100644
--- a/spec/lib/post_action_creator_spec.rb
+++ b/spec/lib/post_action_creator_spec.rb
@@ -68,6 +68,22 @@ RSpec.describe PostActionCreator do
expect(post_action.related_post).to be_present
expect(post_action.related_post.raw).to include("another special message")
end
+
+ context "with a custom flag created after an earlier flag" do
+ after { Flag.reset_flag_settings! }
+
+ it "notifies subscribers" do
+ PostActionCreator.spam(admin, Fabricate(:post))
+ flag = Fabricate(:flag, name: "custom flag", notify_type: true)
+
+ messages =
+ MessageBus.track_publish("/topic/#{post.topic_id}") do
+ PostActionCreator.new(user, post, flag.id).perform
+ end
+
+ expect(messages.map { |message| message.data[:type] }).to include(:acted)
+ end
+ end
end
describe "perform" do
diff --git a/spec/lib/post_action_destroyer_spec.rb b/spec/lib/post_action_destroyer_spec.rb
index 03328470e85..b6d80567c29 100644
--- a/spec/lib/post_action_destroyer_spec.rb
+++ b/spec/lib/post_action_destroyer_spec.rb
@@ -94,5 +94,24 @@ RSpec.describe PostActionDestroyer do
expect(messages.last.data[:type]).to eq(:acted)
end
end
+
+ context "with a custom flag created after an earlier flag" do
+ after { Flag.reset_flag_settings! }
+
+ it "notifies subscribers" do
+ other_post = Fabricate(:post)
+ PostActionCreator.spam(admin, other_post)
+ PostActionDestroyer.destroy(admin, other_post, :spam)
+ flag = Fabricate(:flag, name: "custom flag", notify_type: true)
+ PostActionCreator.new(user, post, flag.id).perform
+
+ messages =
+ MessageBus.track_publish("/topic/#{post.topic_id}") do
+ PostActionDestroyer.new(user, post, flag.id).perform
+ end
+
+ expect(messages.map { |message| message.data[:type] }).to include(:acted)
+ end
+ end
end
end