FIX: Only active assigns should be included in reminders (#281)

* FIX: Only active assigns should be included in reminders

* Update lib/pending_assigns_reminder.rb

Co-authored-by: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
jbrw 2022-01-14 15:23:29 -05:00 committed by GitHub
parent a52da2396c
commit 7a04569c0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View File

@ -54,7 +54,7 @@ class PendingAssignsReminder
end end
def assigned_count_for(user) def assigned_count_for(user)
Assignment.joins_with_topics.where(assigned_to_id: user.id, assigned_to_type: 'User').count Assignment.joins_with_topics.where(assigned_to_id: user.id, assigned_to_type: 'User', active: true).count
end end
def assigned_topics(user, order:) def assigned_topics(user, order:)
@ -63,7 +63,7 @@ class PendingAssignsReminder
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')
.where("assignments.assigned_to_id = ? AND assignments.assigned_to_type = 'User'", user.id) .where("assignments.assigned_to_id = ? AND assignments.assigned_to_type = 'User' AND assignments.active", user.id)
.merge(secure) .merge(secure)
.order("assignments.created_at #{order}") .order("assignments.created_at #{order}")
.limit(3) .limit(3)

View File

@ -112,5 +112,36 @@ RSpec.describe PendingAssignsReminder do
expect(reminders_count).to eq(2) expect(reminders_count).to eq(2)
end end
it "closed topics aren't included as active assigns" do
SiteSetting.unassign_on_close = true
@post5 = Fabricate(:post)
Assigner.new(@post5.topic, user).assign(user)
subject.remind(user)
post = Post.last
topic = post.topic
expect(topic.title).to eq(I18n.t(
'pending_assigns_reminder.title',
pending_assignments: 4
))
@post5.topic.update_status("closed", true, Discourse.system_user)
expect(@post5.topic.closed).to eq(true)
subject.remind(user)
post = Post.last
topic = post.topic
expect(topic.title).to eq(I18n.t(
'pending_assigns_reminder.title',
pending_assignments: 3
))
end
end end
end end