Skip to content

Commit 7d2a027

Browse files
authored
FEATURE: Add modifier to update the assigned count and exclude solved topics (#312)
* FEATURE: Add modifier to update the assigned count and exclude solved topics * DEV: lint solved_spec.rb
1 parent 6900159 commit 7d2a027

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

app/lib/plugin_initializers/assigned_reminder_exclude_solved.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,14 @@ def apply_plugin_api
2727
end
2828
end
2929
end
30+
31+
class AssignedCountForUserQuery < PluginInitializer
32+
def apply_plugin_api
33+
plugin.register_modifier(:assigned_count_for_user_query) do |query, user|
34+
next query if !SiteSetting.ignore_solved_topics_in_assigned_reminder
35+
next query if SiteSetting.assignment_status_on_solve.blank?
36+
query.where.not(status: SiteSetting.assignment_status_on_solve)
37+
end
38+
end
39+
end
3040
end

plugin.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Engine < ::Rails::Engine
4747

4848
require_relative "app/lib/plugin_initializers/assigned_reminder_exclude_solved"
4949
DiscourseSolved::AssignsReminderForTopicsQuery.new(self).apply_plugin_api
50+
DiscourseSolved::AssignedCountForUserQuery.new(self).apply_plugin_api
5051
module ::DiscourseSolved
5152
def self.accept_answer!(post, acting_user, topic: nil)
5253
topic ||= post.topic

spec/integration/solved_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,27 @@
532532
expect(topics).to include(other_topic)
533533
end
534534
end
535+
536+
describe "assigned count for user" do
537+
it "does not count solved topics using assignment_status_on_solve status" do
538+
SiteSetting.ignore_solved_topics_in_assigned_reminder = true
539+
540+
other_topic = Fabricate(:topic, title: "Topic that should be there")
541+
post = Fabricate(:post, topic: other_topic, user: user)
542+
543+
other_topic2 = Fabricate(:topic, title: "Topic that should be there2")
544+
post2 = Fabricate(:post, topic: other_topic2, user: user)
545+
546+
Assigner.new(post.topic, user).assign(user)
547+
Assigner.new(post2.topic, user).assign(user)
548+
549+
reminder = PendingAssignsReminder.new
550+
expect(reminder.send(:assigned_count_for, user)).to eq(2)
551+
552+
DiscourseSolved.accept_answer!(post2, Discourse.system_user)
553+
expect(reminder.send(:assigned_count_for, user)).to eq(1)
554+
end
555+
end
535556
end
536557
end
537558

0 commit comments

Comments
 (0)