Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

FEATURE: Add modifier to update the assigned count and exclude solved topics #312

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/lib/plugin_initializers/assigned_reminder_exclude_solved.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ def apply_plugin_api
end
end
end

class AssignedCountForUserQuery < PluginInitializer
def apply_plugin_api
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
end
end
end
1 change: 1 addition & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Engine < ::Rails::Engine

require_relative "app/lib/plugin_initializers/assigned_reminder_exclude_solved"
DiscourseSolved::AssignsReminderForTopicsQuery.new(self).apply_plugin_api
DiscourseSolved::AssignedCountForUserQuery.new(self).apply_plugin_api
module ::DiscourseSolved
def self.accept_answer!(post, acting_user, topic: nil)
topic ||= post.topic
Expand Down
21 changes: 21 additions & 0 deletions spec/integration/solved_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,27 @@
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

Expand Down