mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +08:00
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:
parent
ceec11a153
commit
d6eb892b04
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user