Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Add modifier to assigned count #598

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
13 changes: 9 additions & 4 deletions lib/pending_assigns_reminder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ def delete_previous_reminders(user)
end

def assigned_count_for(user)
Assignment
.joins_with_topics
.where(assigned_to_id: user.id, assigned_to_type: "User", active: true)
.count
assignments =
Assignment.joins_with_topics.where(
assigned_to_id: user.id,
assigned_to_type: "User",
active: true,
)
assignments =
DiscoursePluginRegistry.apply_modifier(:assigned_count_for_user_query, assignments, user)
assignments.count
end

def assigned_topics(user, order:)
Expand Down
21 changes: 19 additions & 2 deletions spec/lib/pending_assigns_reminder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def assert_reminder_not_created
expect(topic.title).to eq(I18n.t("pending_assigns_reminder.title", pending_assignments: 3))
end

context "with assigns_reminder_assigned_topics_query" do
context "with assigns_reminder_assigned_topics_query modifier" do
let(:modifier_block) { Proc.new { |query| query.where.not(id: @post1.topic_id) } }
it "doesn't remind if topic is solved" do
it "updates the query correctly" do
plugin_instance = Plugin::Instance.new
plugin_instance.register_modifier(:assigns_reminder_assigned_topics_query, &modifier_block)
topics = reminder.send(:assigned_topics, user, order: :asc)
Expand All @@ -158,5 +158,22 @@ def assert_reminder_not_created
)
end
end

context "with assigned_count_for_user_query modifier" do
let(:modifier_block) { Proc.new { |query, user| query.where.not(assigned_to_id: user.id) } }
it "updates the query correctly" do
expect(reminder.send(:assigned_count_for, user)).to eq(3)

plugin_instance = Plugin::Instance.new
plugin_instance.register_modifier(:assigned_count_for_user_query, &modifier_block)
expect(reminder.send(:assigned_count_for, user)).to eq(0)
ensure
DiscoursePluginRegistry.unregister_modifier(
plugin_instance,
:assigned_count_for_user_query,
&modifier_block
)
end
end
end
end