DEV: add modifier to reminder assigned topics query (#565)
* FEATURE: Prevents assign notification Relates to this [topic](https://meta.discourse.org/t/assign-plugin-for-informatica/256974/94) * DEV: Add tests to assigns_reminder_assigned_topics_query modifier * DEV: lint pending_assigns_reminder_spec.rb * DEV: Address review feedback Remove puts from test.
This commit is contained in:
parent
62563bfcea
commit
c8f669d76b
|
@ -67,6 +67,7 @@ class PendingAssignsReminder
|
||||||
secure =
|
secure =
|
||||||
Topic.listable_topics.secured(Guardian.new(user)).or(Topic.private_messages_for_user(user))
|
Topic.listable_topics.secured(Guardian.new(user)).or(Topic.private_messages_for_user(user))
|
||||||
|
|
||||||
|
topics =
|
||||||
Topic
|
Topic
|
||||||
.joins(:assignment)
|
.joins(:assignment)
|
||||||
.select(:slug, :id, :title, :fancy_title, "assignments.created_at AS assigned_at")
|
.select(:slug, :id, :title, :fancy_title, "assignments.created_at AS assigned_at")
|
||||||
|
@ -74,9 +75,8 @@ class PendingAssignsReminder
|
||||||
"assignments.assigned_to_id = ? AND assignments.assigned_to_type = 'User' AND assignments.active",
|
"assignments.assigned_to_id = ? AND assignments.assigned_to_type = 'User' AND assignments.active",
|
||||||
user.id,
|
user.id,
|
||||||
)
|
)
|
||||||
.merge(secure)
|
topics = DiscoursePluginRegistry.apply_modifier(:assigns_reminder_assigned_topics_query, topics)
|
||||||
.order("assignments.created_at #{order}")
|
topics.merge(secure).order("assignments.created_at #{order}").limit(3)
|
||||||
.limit(3)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def reminder_body(user, assigned_topics_count, first_three_topics, last_three_topics)
|
def reminder_body(user, assigned_topics_count, first_three_topics, last_three_topics)
|
||||||
|
|
|
@ -142,5 +142,21 @@ RSpec.describe PendingAssignsReminder do
|
||||||
|
|
||||||
expect(topic.title).to eq(I18n.t("pending_assigns_reminder.title", pending_assignments: 3))
|
expect(topic.title).to eq(I18n.t("pending_assigns_reminder.title", pending_assignments: 3))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with assigns_reminder_assigned_topics_query" do
|
||||||
|
let(:modifier_block) { Proc.new { |query| query.where.not(id: @post1.topic_id) } }
|
||||||
|
it "doesn't remind if topic is solved" 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)
|
||||||
|
expect(topics).not_to include(@post1.topic)
|
||||||
|
ensure
|
||||||
|
DiscoursePluginRegistry.unregister_modifier(
|
||||||
|
plugin_instance,
|
||||||
|
:assigns_reminder_assigned_topics_query,
|
||||||
|
&modifier_block
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue