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

Commit 057496c

Browse files
committed
FEATURE: Add modifier to assigned count
1 parent 525dbcd commit 057496c

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

lib/pending_assigns_reminder.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,15 @@ def delete_previous_reminders(user)
5656
end
5757

5858
def assigned_count_for(user)
59-
Assignment
60-
.joins_with_topics
61-
.where(assigned_to_id: user.id, assigned_to_type: "User", active: true)
62-
.count
59+
assignments =
60+
Assignment.joins_with_topics.where(
61+
assigned_to_id: user.id,
62+
assigned_to_type: "User",
63+
active: true,
64+
)
65+
assignments =
66+
DiscoursePluginRegistry.apply_modifier(:assigned_count_for_user_query, assignments, user)
67+
assignments.count
6368
end
6469

6570
def assigned_topics(user, order:)

spec/lib/pending_assigns_reminder_spec.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ def assert_reminder_not_created
143143
expect(topic.title).to eq(I18n.t("pending_assigns_reminder.title", pending_assignments: 3))
144144
end
145145

146-
context "with assigns_reminder_assigned_topics_query" do
146+
context "with assigns_reminder_assigned_topics_query modifier" do
147147
let(:modifier_block) { Proc.new { |query| query.where.not(id: @post1.topic_id) } }
148-
it "doesn't remind if topic is solved" do
148+
it "updates the query correctly" do
149149
plugin_instance = Plugin::Instance.new
150150
plugin_instance.register_modifier(:assigns_reminder_assigned_topics_query, &modifier_block)
151151
topics = reminder.send(:assigned_topics, user, order: :asc)
@@ -158,5 +158,22 @@ def assert_reminder_not_created
158158
)
159159
end
160160
end
161+
162+
context "with assigned_count_for_user_query modifier" do
163+
let(:modifier_block) { Proc.new { |query, user| query.where.not(assigned_to_id: user.id) } }
164+
it "updates the query correctly" do
165+
expect(reminder.send(:assigned_count_for, user)).to eq(3)
166+
167+
plugin_instance = Plugin::Instance.new
168+
plugin_instance.register_modifier(:assigned_count_for_user_query, &modifier_block)
169+
expect(reminder.send(:assigned_count_for, user)).to eq(0)
170+
ensure
171+
DiscoursePluginRegistry.unregister_modifier(
172+
plugin_instance,
173+
:assigned_count_for_user_query,
174+
&modifier_block
175+
)
176+
end
177+
end
161178
end
162179
end

0 commit comments

Comments
 (0)