FEATURE: Account for `ignored_users` when merging two users (#7142)

* FEATURE: Account for `ignored_users` when merging two users

## Why?

This is part of the [Ability to ignore a user feature](https://meta.discourse.org/t/ability-to-ignore-a-user/110254/8).
When we merge two users, we need to account for merging their list of `ignored_users` too.
This commit is contained in:
Tarek Khalil 2019-03-11 13:53:59 +00:00 committed by GitHub
parent ceec11a153
commit d6eb892b04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -260,6 +260,9 @@ class UserMerger
update_user_id(:muted_users, conditions: "x.muted_user_id = y.muted_user_id")
update_user_id(:muted_users, user_id_column_name: "muted_user_id", conditions: "x.user_id = y.user_id")
update_user_id(:ignored_users, conditions: "x.ignored_user_id = y.ignored_user_id")
update_user_id(:ignored_users, user_id_column_name: "ignored_user_id", conditions: "x.user_id = y.user_id")
Notification.where(user_id: @source_user.id).update_all(user_id: @target_user.id)
update_user_id(:post_actions, conditions: ["x.post_id = y.post_id",
@ -365,6 +368,7 @@ class UserMerger
DraftSequence.where(user_id: @source_user.id).delete_all
GivenDailyLike.where(user_id: @source_user.id).delete_all
MutedUser.where(user_id: @source_user.id).or(MutedUser.where(muted_user_id: @source_user.id)).delete_all
IgnoredUser.where(user_id: @source_user.id).or(IgnoredUser.where(ignored_user_id: @source_user.id)).delete_all
UserAuthTokenLog.where(user_id: @source_user.id).delete_all
UserAvatar.where(user_id: @source_user.id).delete_all
UserAction.where(acting_user_id: @source_user.id).delete_all

View File

@ -290,6 +290,32 @@ describe UserMerger do
expect(MutedUser.where(muted_user_id: source_user.id).count).to eq(0)
end
it "merges ignored users" do
ignored1 = Fabricate(:user)
ignored2 = Fabricate(:user)
ignored3 = Fabricate(:user)
coding_horror = Fabricate(:coding_horror)
IgnoredUser.create!(user_id: source_user.id, ignored_user_id: ignored1.id)
IgnoredUser.create!(user_id: source_user.id, ignored_user_id: ignored2.id)
IgnoredUser.create!(user_id: target_user.id, ignored_user_id: ignored2.id)
IgnoredUser.create!(user_id: target_user.id, ignored_user_id: ignored3.id)
IgnoredUser.create!(user_id: walter.id, ignored_user_id: source_user.id)
IgnoredUser.create!(user_id: coding_horror.id, ignored_user_id: source_user.id)
IgnoredUser.create!(user_id: coding_horror.id, ignored_user_id: target_user.id)
merge_users!
[ignored1, ignored2, ignored3].each do |m|
expect(IgnoredUser.where(user_id: target_user.id, ignored_user_id: m.id).count).to eq(1)
end
expect(IgnoredUser.where(user_id: source_user.id).count).to eq(0)
expect(IgnoredUser.where(user_id: walter.id, ignored_user_id: target_user.id).count).to eq(1)
expect(IgnoredUser.where(user_id: coding_horror.id, ignored_user_id: target_user.id).count).to eq(1)
expect(IgnoredUser.where(ignored_user_id: source_user.id).count).to eq(0)
end
context "notifications" do
it "updates notifications" do
Fabricate(:notification, user: source_user)