Skip to content

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

FIX: blocks post action merge for duplicated flags (#36265)

Amanda Alves Branquinho2c863c62323f
diff --git a/app/services/user_merger.rb b/app/services/user_merger.rb
index a9dd145e433..8c3212868db 100644
--- a/app/services/user_merger.rb
+++ b/app/services/user_merger.rb
@@ -380,8 +380,8 @@ class UserMerger
:post_actions,
conditions: [
"x.post_id = y.post_id",
- "x.post_action_type_id = y.post_action_type_id",
"x.targets_topic = y.targets_topic",
+ "x.post_action_type_id = y.post_action_type_id OR (x.post_action_type_id IN (3,4,7,8) AND y.post_action_type_id IN (3,4,7,8))",
],
)
diff --git a/spec/services/user_merger_spec.rb b/spec/services/user_merger_spec.rb
index e14bffaca56..814e5734d69 100644
--- a/spec/services/user_merger_spec.rb
+++ b/spec/services/user_merger_spec.rb
@@ -361,6 +361,23 @@ RSpec.describe UserMerger do
expect(PostAction.where(user_id: source_user.id).count).to eq(0)
end
+ it "does not migrate source user's flag when target user has a different flag type on same post" do
+ PostActionCreator.create(source_user, p1, :off_topic)
+ PostActionCreator.create(target_user, p1, :spam)
+ PostActionCreator.create(source_user, p2, :inappropriate)
+
+ merge_users!
+
+ expect(PostAction.where(user_id: target_user.id, post_id: p1.id).count).to eq(1)
+ expect(
+ PostAction.where(user_id: target_user.id, post_id: p1.id).pluck(:post_action_type_id),
+ ).to contain_exactly(PostActionType.types[:spam])
+ expect(PostAction.where(user_id: target_user.id, post_id: p2.id).count).to eq(1)
+ expect(
+ PostAction.where(user_id: target_user.id, post_id: p2.id).pluck(:post_action_type_id),
+ ).to contain_exactly(PostActionType.types[:inappropriate])
+ end
+
it "updates post actions" do
action1 = PostActionCreator.create(source_user, p1, :off_topic).post_action
action1.update_attribute(:deleted_by_id, source_user.id)