mirror of
https://github.com/discourse/discourse.git
synced 2026-08-07 03:35:32 -05:00
FEATURE: when moving posts to a PM also add acting user (#36789)
Without acting user being allowed it can be very confusing, and the acting user can just remove themselves from the PM --------- Co-authored-by: Martin Brennan <martin@discourse.org>
This commit is contained in:
@@ -75,6 +75,7 @@ class PostMover
|
||||
def move_posts_to(topic)
|
||||
Guardian.new(user).ensure_can_see! topic
|
||||
@destination_topic = topic
|
||||
ensure_acting_user_is_allowed_in_destination
|
||||
|
||||
# when a topic contains some posts after moving posts to another topic we shouldn't close it
|
||||
# two types of posts should prevent a topic from closing:
|
||||
@@ -130,6 +131,16 @@ class PostMover
|
||||
destination_topic
|
||||
end
|
||||
|
||||
def ensure_acting_user_is_allowed_in_destination
|
||||
return if !@move_to_pm
|
||||
return if destination_topic.archetype != Archetype.private_message
|
||||
return if user.id.blank? || user.bot?
|
||||
return if destination_topic.topic_allowed_users.exists?(user_id: user.id)
|
||||
|
||||
destination_topic.topic_allowed_users.create!(user_id: user.id)
|
||||
destination_topic.notifier.watch!(user.id)
|
||||
end
|
||||
|
||||
def create_temp_table
|
||||
DB.exec("DROP TABLE IF EXISTS temp_moved_posts") if Rails.env.test?
|
||||
|
||||
|
||||
@@ -2958,6 +2958,7 @@ RSpec.describe PostMover do
|
||||
end
|
||||
|
||||
context "with freeze_original option" do
|
||||
fab!(:admin)
|
||||
fab!(:original_topic, :topic)
|
||||
fab!(:destination_topic, :topic)
|
||||
fab!(:op) { Fabricate(:post, topic: original_topic, raw: "op of original topic") }
|
||||
@@ -3210,6 +3211,22 @@ RSpec.describe PostMover do
|
||||
expect(pm.posts.map(&:raw)).to include(*moving_posts.map(&:raw))
|
||||
end
|
||||
|
||||
it "adds the acting user to the new PM" do
|
||||
moving_posts = [first_post, second_post]
|
||||
pm =
|
||||
PostMover.new(
|
||||
original_topic,
|
||||
admin,
|
||||
moving_posts.map(&:id),
|
||||
move_to_pm: true,
|
||||
options: {
|
||||
freeze_original: true,
|
||||
},
|
||||
).to_new_topic("Hi I'm a new PM, with a copy of the old posts")
|
||||
|
||||
expect(pm.topic_allowed_users.pluck(:user_id)).to include(admin.id)
|
||||
end
|
||||
|
||||
it "keep all posts when moving to an existing PM" do
|
||||
pm = Fabricate(:private_message_topic)
|
||||
pm_with_posts = Fabricate(:private_message_topic)
|
||||
|
||||
Reference in New Issue
Block a user