DEV: Update change status on solve implementation
Update tests to verify that the change status on solve feature is working as expected. Change the implementation to loop throught the topic assignments and update the status.
This commit is contained in:
parent
b4b6f8da65
commit
14e04c51ca
48
plugin.rb
48
plugin.rb
|
@ -591,19 +591,47 @@ after_initialize do
|
|||
if defined?(DiscourseAssign)
|
||||
on(:accepted_solution) do |post|
|
||||
next if SiteSetting.assignment_status_on_solve.blank?
|
||||
assigned_user = User.find_by(id: post.topic.assignment.assigned_to_id)
|
||||
Assigner.new(post.topic, assigned_user).assign(
|
||||
assigned_user,
|
||||
status: SiteSetting.assignment_status_on_solve,
|
||||
)
|
||||
assignements = Assignment.where(topic: post.topic)
|
||||
assignements.each do |assignment|
|
||||
assigned_user = User.find_by(id: assignment.assigned_to_id)
|
||||
target_id = assignment.target_id
|
||||
|
||||
target =
|
||||
case assignment.target_type
|
||||
when "Post"
|
||||
Post.find_by(id: target_id)
|
||||
when "Topic"
|
||||
Topic.find_by(id: target_id)
|
||||
else
|
||||
post.topic
|
||||
end
|
||||
|
||||
Assigner.new(target, assigned_user).assign(
|
||||
assigned_user,
|
||||
status: SiteSetting.assignment_status_on_solve,
|
||||
)
|
||||
end
|
||||
end
|
||||
on(:unaccepted_solution) do |post|
|
||||
next if SiteSetting.assignment_status_on_unsolve.blank?
|
||||
assigned_user = User.find_by(id: post.topic.assignment.assigned_to_id)
|
||||
Assigner.new(post.topic, assigned_user).assign(
|
||||
assigned_user,
|
||||
status: SiteSetting.assignment_status_on_unsolve,
|
||||
)
|
||||
assignements = Assignment.where(topic: post.topic)
|
||||
assignements.each do |assignment|
|
||||
assigned_user = User.find_by(id: assignment.assigned_to_id)
|
||||
target_id = assignment.target_id
|
||||
target =
|
||||
case assignment.target_type
|
||||
when "Post"
|
||||
Post.find_by(id: target_id)
|
||||
when "Topic"
|
||||
Topic.find_by(id: target_id)
|
||||
else
|
||||
post.topic
|
||||
end
|
||||
Assigner.new(target, assigned_user).assign(
|
||||
assigned_user,
|
||||
status: SiteSetting.assignment_status_on_unsolve,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -466,7 +466,7 @@ RSpec.describe "Managing Posts solved status" do
|
|||
|
||||
DiscourseSolved.accept_answer!(p1, user)
|
||||
|
||||
expect(p1.topic.assignment.status).to eq("Done")
|
||||
expect(p1.reload.topic.assignment.reload.status).to eq("Done")
|
||||
|
||||
DiscourseSolved.unaccept_answer!(p1)
|
||||
|
||||
|
@ -491,14 +491,16 @@ RSpec.describe "Managing Posts solved status" do
|
|||
expect(result[:success]).to eq(true)
|
||||
|
||||
post_response = Fabricate(:post, topic: topic_question, user: user_3)
|
||||
Assigner.new(post_response, user_3).assign(user_3)
|
||||
|
||||
DiscourseSolved.accept_answer!(post_response, user_1)
|
||||
|
||||
expect(topic_question.assignment.assigned_to_id).to eq(user_2.id)
|
||||
|
||||
expect(post_response.assignment.assigned_to_id).to eq(user_3.id)
|
||||
DiscourseSolved.unaccept_answer!(post_response)
|
||||
|
||||
expect(topic_question.assignment.assigned_to_id).to eq(user_2.id)
|
||||
expect(post_response.assignment.assigned_to_id).to eq(user_3.id)
|
||||
end
|
||||
|
||||
describe "assigned topic reminder"
|
||||
|
|
Loading…
Reference in New Issue