Skip to content

Commit

Permalink
DEV: add modifier to reminder assigned topics query (#565)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Grubba27 committed Apr 26, 2024
1 parent 62563bf commit c8f669d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/pending_assigns_reminder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ def assigned_topics(user, order:)
secure =
Topic.listable_topics.secured(Guardian.new(user)).or(Topic.private_messages_for_user(user))

Topic
.joins(:assignment)
.select(:slug, :id, :title, :fancy_title, "assignments.created_at AS assigned_at")
.where(
"assignments.assigned_to_id = ? AND assignments.assigned_to_type = 'User' AND assignments.active",
user.id,
)
.merge(secure)
.order("assignments.created_at #{order}")
.limit(3)
topics =
Topic
.joins(:assignment)
.select(:slug, :id, :title, :fancy_title, "assignments.created_at AS assigned_at")
.where(
"assignments.assigned_to_id = ? AND assignments.assigned_to_type = 'User' AND assignments.active",
user.id,
)
topics = DiscoursePluginRegistry.apply_modifier(:assigns_reminder_assigned_topics_query, topics)
topics.merge(secure).order("assignments.created_at #{order}").limit(3)
end

def reminder_body(user, assigned_topics_count, first_three_topics, last_three_topics)
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/pending_assigns_reminder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,21 @@ 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
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

0 comments on commit c8f669d

Please sign in to comment.