FIX: move post assignment when move post (#229)
When an assigned post is moved to the new topic, it becomes topic assignment. When an assigned post is moved to an existing topic it stays post assignment
This commit is contained in:
parent
a4b1847eff
commit
fcd4532c76
10
plugin.rb
10
plugin.rb
|
@ -737,6 +737,16 @@ after_initialize do
|
|||
end
|
||||
end
|
||||
|
||||
on(:post_moved) do |post, original_topic_id|
|
||||
assignment = Assignment.where(topic_id: original_topic_id, target_type: "Post", target_id: post.id).first
|
||||
next if !assignment
|
||||
if post.is_first_post?
|
||||
assignment.update!(topic_id: post.topic_id, target_type: "Topic", target_id: post.topic_id)
|
||||
else
|
||||
assignment.update!(topic_id: post.topic_id)
|
||||
end
|
||||
end
|
||||
|
||||
class ::WebHook
|
||||
def self.enqueue_assign_hooks(event, payload)
|
||||
if active_web_hooks('assign').exists?
|
||||
|
|
|
@ -145,4 +145,30 @@ describe 'integration tests' do
|
|||
expect(payload["unassigned_to_id"]).to eq(user2.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'move post' do
|
||||
fab!(:old_topic) { Fabricate(:topic) }
|
||||
fab!(:post) { Fabricate(:post, topic: old_topic) }
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:assignment) { Assignment.create!(target_id: post.id, target_type: "Post", topic_id: old_topic.id, assigned_by_user: user, assigned_to: user) }
|
||||
let(:new_topic) { Fabricate(:topic) }
|
||||
|
||||
it 'assignment becomes topic assignment when new topic' do
|
||||
post.update!(topic: new_topic)
|
||||
DiscourseEvent.trigger(:post_moved, post, old_topic.id)
|
||||
assignment.reload
|
||||
expect(assignment.topic_id).to eq(new_topic.id)
|
||||
expect(assignment.target_type).to eq("Topic")
|
||||
expect(assignment.target_id).to eq(new_topic.id)
|
||||
end
|
||||
|
||||
it 'assigment is still post assignment when not first post' do
|
||||
post.update!(topic: new_topic, post_number: "3")
|
||||
DiscourseEvent.trigger(:post_moved, post, old_topic.id)
|
||||
assignment.reload
|
||||
expect(assignment.topic_id).to eq(new_topic.id)
|
||||
expect(assignment.target_type).to eq("Post")
|
||||
expect(assignment.target_id).to eq(post.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue