FIX: update 'posted' column on post owner change (#16367)

Fixes the issue where making a user x as owner of a post doesn't
cause the concerned topic to be listed in new owner's `My Posts`
top menu filter

per https://meta.discourse.org/t/199369
This commit is contained in:
Faizaan Gagan 2022-04-04 22:42:38 +05:30 committed by GitHub
parent 415c4fa72a
commit 1da4b9eeb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -28,7 +28,7 @@ class PostOwnerChanger
PostActionDestroyer.destroy(@new_owner, post, :like, skip_delete_check: true) PostActionDestroyer.destroy(@new_owner, post, :like, skip_delete_check: true)
level = post.is_first_post? ? :watching : :tracking level = post.is_first_post? ? :watching : :tracking
TopicUser.change(@new_owner.id, @topic.id, notification_level: NotificationLevels.topic_levels[level]) TopicUser.change(@new_owner.id, @topic.id, notification_level: NotificationLevels.topic_levels[level], posted: true)
if post == @topic.posts.order("post_number DESC").where("NOT hidden AND posts.deleted_at IS NULL").first if post == @topic.posts.order("post_number DESC").where("NOT hidden AND posts.deleted_at IS NULL").first
@topic.last_poster = @new_owner @topic.last_poster = @new_owner

View File

@ -85,6 +85,11 @@ describe PostOwnerChanger do
expect(p4.reload.user).to eq(user_a) expect(p4.reload.user).to eq(user_a)
end end
it "sets 'posted' for TopicUser to true" do
PostOwnerChanger.new(post_ids: [p1.id], topic_id: topic.id, new_owner: user_a, acting_user: editor).change_owner!
expect(TopicUser.find_by(topic_id: topic.id, user_id: user_a.id).posted).to eq(true)
end
context "sets topic notification level for the new owner" do context "sets topic notification level for the new owner" do
let(:p4) { create_post(post_number: 2, topic: topic) } let(:p4) { create_post(post_number: 2, topic: topic) }