Skip to content

A platform for community discussion. Free, open, simple.

DEV: remove assign entrypoint from solved plugin (#38060)

David Battersby58af64e217ce
diff --git a/plugins/discourse-assign/config/locales/server.en.yml b/plugins/discourse-assign/config/locales/server.en.yml
index 6d0ac6fb512..1f2f47baa7c 100644
--- a/plugins/discourse-assign/config/locales/server.en.yml
+++ b/plugins/discourse-assign/config/locales/server.en.yml
@@ -19,6 +19,9 @@ en:
assign_allowed_on_groups: "Users in these groups are allowed to assign topics and can be assigned topics."
enable_assign_status: "Add a customizable status field to every assignment."
assign_statuses: "List of statuses available to each assignment. The first status is the default status applied to every new assignment."
+ ignore_solved_topics_in_assigned_reminder: "Prevent reminders for assignments from including solved topics. Only relevant when using the discourse-solved plugin."
+ assignment_status_on_solve: "When a topic is solved update all assignments to this status"
+ assignment_status_on_unsolve: "When a topic is unsolved update all assignments to this status"
errors:
assign_statuses:
too_few: "There must be at least two different statuses available."
diff --git a/plugins/discourse-assign/config/settings.yml b/plugins/discourse-assign/config/settings.yml
index 795e0f0f2ab..f6f5c529409 100644
--- a/plugins/discourse-assign/config/settings.yml
+++ b/plugins/discourse-assign/config/settings.yml
@@ -47,3 +47,11 @@ discourse_assign:
default: "New|In Progress|Done"
allow_any: true
validator: AssignStatusesValidator
+ ignore_solved_topics_in_assigned_reminder:
+ default: false
+ assignment_status_on_solve:
+ type: string
+ default: ""
+ assignment_status_on_unsolve:
+ type: string
+ default: ""
diff --git a/plugins/discourse-assign/plugin.rb b/plugins/discourse-assign/plugin.rb
index 6abee802201..41f93012c9e 100644
--- a/plugins/discourse-assign/plugin.rb
+++ b/plugins/discourse-assign/plugin.rb
@@ -1012,4 +1012,41 @@ after_initialize do
end
end
end
+
+ if defined?(DiscourseSolved)
+ register_modifier(:assigns_reminder_assigned_topics_query) do |query|
+ next query if !SiteSetting.ignore_solved_topics_in_assigned_reminder
+ query.where.not(id: DiscourseSolved::SolvedTopic.select(:topic_id))
+ end
+
+ register_modifier(:assigned_count_for_user_query) do |query, user|
+ next query if !SiteSetting.ignore_solved_topics_in_assigned_reminder
+ next query if SiteSetting.assignment_status_on_solve.blank?
+ query.where.not(status: SiteSetting.assignment_status_on_solve)
+ end
+
+ on(:accepted_solution) do |post|
+ next if SiteSetting.assignment_status_on_solve.blank?
+ assignments = Assignment.includes(:target).where(topic: post.topic)
+ assignments.each do |assignment|
+ assigned_user = User.find_by(id: assignment.assigned_to_id)
+ Assigner.new(assignment.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?
+ assignments = Assignment.includes(:target).where(topic: post.topic)
+ assignments.each do |assignment|
+ assigned_user = User.find_by(id: assignment.assigned_to_id)
+ Assigner.new(assignment.target, assigned_user).assign(
+ assigned_user,
+ status: SiteSetting.assignment_status_on_unsolve,
+ )
+ end
+ end
+ end
end
diff --git a/plugins/discourse-assign/spec/integration/solved_integration_spec.rb b/plugins/discourse-assign/spec/integration/solved_integration_spec.rb
new file mode 100644
index 00000000000..fec9c9e9478
--- /dev/null
+++ b/plugins/discourse-assign/spec/integration/solved_integration_spec.rb
@@ -0,0 +1,127 @@
+# frozen_string_literal: true
+
+RSpec.describe "Solved integration", if: defined?(DiscourseSolved) do
+ fab!(:topic)
+ fab!(:post) { Fabricate(:post, topic: topic) }
+ fab!(:user)
+ fab!(:group)
+
+ before do
+ SiteSetting.solved_enabled = true
+ SiteSetting.assign_enabled = true
+ SiteSetting.enable_assign_status = true
+ SiteSetting.assign_allowed_on_groups = "#{group.id}"
+ SiteSetting.assigns_public = true
+ SiteSetting.assignment_status_on_solve = "Done"
+ SiteSetting.assignment_status_on_unsolve = "New"
+ SiteSetting.ignore_solved_topics_in_assigned_reminder = false
+ group.add(post.acting_user)
+ group.add(user)
+ end
+
+ describe "updating assignment status on solve" do
+ it "updates all assignments to assignment_status_on_solve status when a post is accepted" do
+ assigner = Assigner.new(topic, user)
+ result = assigner.assign(user)
+ expect(result[:success]).to eq(true)
+
+ expect(topic.assignment.status).to eq("New")
+ DiscourseSolved.accept_answer!(post, user)
+ topic.reload
+
+ expect(topic.solved.answer_post_id).to eq(post.id)
+ expect(topic.assignment.reload.status).to eq("Done")
+ end
+
+ it "updates all assignments to assignment_status_on_unsolve status when a post is unaccepted" do
+ assigner = Assigner.new(topic, user)
+ result = assigner.assign(user)
+ expect(result[:success]).to eq(true)
+
+ DiscourseSolved.accept_answer!(post, user)
+
+ expect(topic.assignment.reload.status).to eq("Done")
+
+ DiscourseSolved.unaccept_answer!(post)
+
+ expect(topic.assignment.reload.status).to eq("New")
+ end
+
+ it "does not update the assignee when a post is accepted" do
+ user_2 = Fabricate(:user)
+ user_3 = Fabricate(:user)
+ group.add(user)
+ group.add(user_2)
+ group.add(user_3)
+
+ topic_question = Fabricate(:topic, user: user)
+
+ Fabricate(:post, topic: topic_question, user: user)
+ Fabricate(:post, topic: topic_question, user: user_2)
+
+ result = Assigner.new(topic_question, user_2).assign(user_2)
+ 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)
+
+ 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" do
+ it "excludes solved topics when ignore_solved_topics_in_assigned_reminder is true" do
+ other_topic = Fabricate(:topic, title: "Topic that should be there")
+ other_post = Fabricate(:post, topic: other_topic, user: user)
+
+ other_topic2 = Fabricate(:topic, title: "Topic that should be there2")
+ other_post2 = Fabricate(:post, topic: other_topic2, user: user)
+
+ Assigner.new(other_topic, user).assign(user)
+ Assigner.new(other_topic2, user).assign(user)
+
+ reminder = PendingAssignsReminder.new
+ topics = reminder.send(:assigned_topics, user, order: :asc)
+ expect(topics.to_a.length).to eq(2)
+
+ DiscourseSolved.accept_answer!(other_post2, Discourse.system_user)
+ topics = reminder.send(:assigned_topics, user, order: :asc)
+ expect(topics.to_a.length).to eq(2)
+ expect(topics).to include(other_topic2)
+
+ SiteSetting.ignore_solved_topics_in_assigned_reminder = true
+ topics = reminder.send(:assigned_topics, user, order: :asc)
+ expect(topics.to_a.length).to eq(1)
+ expect(topics).not_to include(other_topic2)
+ expect(topics).to include(other_topic)
+ end
+ end
+
+ describe "assigned count for user" do
+ it "does not count solved topics using assignment_status_on_solve status" do
+ SiteSetting.ignore_solved_topics_in_assigned_reminder = true
+
+ other_topic = Fabricate(:topic, title: "Topic that should be there")
+ other_post = Fabricate(:post, topic: other_topic, user: user)
+
+ other_topic2 = Fabricate(:topic, title: "Topic that should be there2")
+ other_post2 = Fabricate(:post, topic: other_topic2, user: user)
+
+ Assigner.new(other_topic, user).assign(user)
+ Assigner.new(other_topic2, user).assign(user)
+
+ reminder = PendingAssignsReminder.new
+ expect(reminder.send(:assigned_count_for, user)).to eq(2)
+
+ DiscourseSolved.accept_answer!(other_post2, Discourse.system_user)
+ expect(reminder.send(:assigned_count_for, user)).to eq(1)
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-solved/config/locales/server.en.yml b/plugins/discourse-solved/config/locales/server.en.yml
index 54b6a34e24d..f6861bc42fb 100644
--- a/plugins/discourse-solved/config/locales/server.en.yml
+++ b/plugins/discourse-solved/config/locales/server.en.yml
@@ -23,9 +23,6 @@ en:
solved_topics_auto_close_hours: "Auto close topic (n) hours after the last reply once the topic has been marked as solved. Set to 0 to disable auto closing."
show_filter_by_solved_status: "Show a dropdown to filter a topic list by solved status."
notify_on_staff_accept_solved: "Send notification to the topic creator when a post is marked as solution by a staff."
- ignore_solved_topics_in_assigned_reminder: "Prevent reminders for assignments from including solved topics. Only relevant when using the discourse-assign plugin."
- assignment_status_on_solve: "When a topic is solved update all assignments to this status"
- assignment_status_on_unsolve: "When a topic is unsolved update all assignments to this status"
disable_solved_education_message: "Disable education message for solved topics."
accept_solutions_topic_author: "Allow the topic author to accept a solution."
solved_add_schema_markup: "Add QAPage schema markup to HTML."
diff --git a/plugins/discourse-solved/config/settings.yml b/plugins/discourse-solved/config/settings.yml
index 5a63ee11734..c328bdfa821 100644
--- a/plugins/discourse-solved/config/settings.yml
+++ b/plugins/discourse-solved/config/settings.yml
@@ -41,14 +41,6 @@ discourse_solved:
client: true
notify_on_staff_accept_solved:
default: false
- ignore_solved_topics_in_assigned_reminder:
- default: false
- assignment_status_on_solve:
- type: string
- default: ""
- assignment_status_on_unsolve:
- type: string
- default: ""
disable_solved_education_message:
default: false
accept_solutions_topic_author:
diff --git a/plugins/discourse-solved/lib/discourse_assign/entry_point.rb b/plugins/discourse-solved/lib/discourse_assign/entry_point.rb
deleted file mode 100644
index 12821f6aa6f..00000000000
--- a/plugins/discourse-solved/lib/discourse_assign/entry_point.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-# frozen_string_literal: true
-
-module DiscourseAssign
- class EntryPoint
- # TODO: These four plugin api usages should ideally be in the assign plugin, not the solved plugin.
- # They have been moved here from plugin.rb as part of the custom fields migration.
-
- def self.inject(plugin)
- plugin.register_modifier(:assigns_reminder_assigned_topics_query) do |query|
- next query if !SiteSetting.ignore_solved_topics_in_assigned_reminder
- query.where.not(id: DiscourseSolved::SolvedTopic.select(:topic_id))
- end
-
- plugin.register_modifier(:assigned_count_for_user_query) do |query, user|
- next query if !SiteSetting.ignore_solved_topics_in_assigned_reminder
- next query if SiteSetting.assignment_status_on_solve.blank?
- query.where.not(status: SiteSetting.assignment_status_on_solve)
- end
-
- plugin.on(:accepted_solution) do |post|
- next if SiteSetting.assignment_status_on_solve.blank?
- assignments = Assignment.includes(:target).where(topic: post.topic)
- assignments.each do |assignment|
- assigned_user = User.find_by(id: assignment.assigned_to_id)
- Assigner.new(assignment.target, assigned_user).assign(
- assigned_user,
- status: SiteSetting.assignment_status_on_solve,
- )
- end
- end
-
- plugin.on(:unaccepted_solution) do |post|
- next if SiteSetting.assignment_status_on_unsolve.blank?
- assignments = Assignment.includes(:target).where(topic: post.topic)
- assignments.each do |assignment|
- assigned_user = User.find_by(id: assignment.assigned_to_id)
- Assigner.new(assignment.target, assigned_user).assign(
- assigned_user,
- status: SiteSetting.assignment_status_on_unsolve,
- )
- end
- end
- end
- end
-end
diff --git a/plugins/discourse-solved/plugin.rb b/plugins/discourse-solved/plugin.rb
index d6041eb918c..15e4f7506c6 100644
--- a/plugins/discourse-solved/plugin.rb
+++ b/plugins/discourse-solved/plugin.rb
@@ -388,5 +388,4 @@ after_initialize do
DiscourseDev::DiscourseSolved.populate(self)
DiscourseAutomation::EntryPoint.inject(self) if defined?(DiscourseAutomation)
- DiscourseAssign::EntryPoint.inject(self) if defined?(DiscourseAssign)
end
diff --git a/plugins/discourse-solved/spec/integration/solved_spec.rb b/plugins/discourse-solved/spec/integration/solved_spec.rb
index 5ecd0dd4e6f..4161a706667 100644
--- a/plugins/discourse-solved/spec/integration/solved_spec.rb
+++ b/plugins/discourse-solved/spec/integration/solved_spec.rb
@@ -482,132 +482,6 @@ RSpec.describe "Managing Posts solved status" do
end
end
- context "with discourse-assign installed", if: defined?(DiscourseAssign) do
- let(:admin) { Fabricate(:admin) }
- fab!(:group)
- before do
- SiteSetting.solved_enabled = true
- SiteSetting.assign_enabled = true
- SiteSetting.enable_assign_status = true
- SiteSetting.assign_allowed_on_groups = "#{group.id}"
- SiteSetting.assigns_public = true
- SiteSetting.assignment_status_on_solve = "Done"
- SiteSetting.assignment_status_on_unsolve = "New"
- SiteSetting.ignore_solved_topics_in_assigned_reminder = false
- group.add(p1.acting_user)
- group.add(user)
-
- sign_in(user)
- end
-
- describe "updating assignment status on solve when assignment_status_on_solve is set" do
- it "update all assignments to this status when a post is accepted" do
- assigner = Assigner.new(p1.topic, user)
- result = assigner.assign(user)
- expect(result[:success]).to eq(true)
-
- expect(p1.topic.assignment.status).to eq("New")
- DiscourseSolved.accept_answer!(p1, user)
- topic.reload
-
- expect(topic.solved.answer_post_id).to eq(p1.id)
- expect(p1.topic.assignment.reload.status).to eq("Done")
- end
-
- it "update all assignments to this status when a post is unaccepted" do
- assigner = Assigner.new(p1.topic, user)
- result = assigner.assign(user)
- expect(result[:success]).to eq(true)
-
- DiscourseSolved.accept_answer!(p1, user)
-
- expect(p1.reload.topic.assignment.reload.status).to eq("Done")
-
- DiscourseSolved.unaccept_answer!(p1)
-
- expect(p1.reload.topic.assignment.reload.status).to eq("New")
- end
-
- it "does not update the assignee when a post is accepted" do
- user = Fabricate(:user)
- user_2 = Fabricate(:user)
- user_3 = Fabricate(:user)
- group.add(user)
- group.add(user_2)
- group.add(user_3)
-
- topic_question = Fabricate(:topic, user: user)
-
- Fabricate(:post, topic: topic_question, user: user)
- Fabricate(:post, topic: topic_question, user: user_2)
-
- result = Assigner.new(topic_question, user_2).assign(user_2)
- 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)
-
- 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" do
- it "excludes solved topics when ignore_solved_topics_in_assigned_reminder is false" do
- other_topic = Fabricate(:topic, title: "Topic that should be there")
- post = Fabricate(:post, topic: other_topic, user: user)
-
- other_topic2 = Fabricate(:topic, title: "Topic that should be there2")
- post2 = Fabricate(:post, topic: other_topic2, user: user)
-
- Assigner.new(post.topic, user).assign(user)
- Assigner.new(post2.topic, user).assign(user)
-
- reminder = PendingAssignsReminder.new
- topics = reminder.send(:assigned_topics, user, order: :asc)
- expect(topics.to_a.length).to eq(2)
-
- DiscourseSolved.accept_answer!(post2, Discourse.system_user)
- topics = reminder.send(:assigned_topics, user, order: :asc)
- expect(topics.to_a.length).to eq(2)
- expect(topics).to include(other_topic2)
-
- SiteSetting.ignore_solved_topics_in_assigned_reminder = true
- topics = reminder.send(:assigned_topics, user, order: :asc)
- expect(topics.to_a.length).to eq(1)
- expect(topics).not_to include(other_topic2)
- expect(topics).to include(other_topic)
- end
- end
-
- describe "assigned count for user" do
- it "does not count solved topics using assignment_status_on_solve status" do
- SiteSetting.ignore_solved_topics_in_assigned_reminder = true
-
- other_topic = Fabricate(:topic, title: "Topic that should be there")
- post = Fabricate(:post, topic: other_topic, user: user)
-
- other_topic2 = Fabricate(:topic, title: "Topic that should be there2")
- post2 = Fabricate(:post, topic: other_topic2, user: user)
-
- Assigner.new(post.topic, user).assign(user)
- Assigner.new(post2.topic, user).assign(user)
-
- reminder = PendingAssignsReminder.new
- expect(reminder.send(:assigned_count_for, user)).to eq(2)
-
- DiscourseSolved.accept_answer!(post2, Discourse.system_user)
- expect(reminder.send(:assigned_count_for, user)).to eq(1)
- end
- end
- end
- end
-
describe "#unaccept_answer!" do
it "works even when the topic has been deleted" do
user = Fabricate(:user, trust_level: 1)