Skip to content

Commit

Permalink
FIX: Only active assigns should be included in reminders (#281)
Browse files Browse the repository at this point in the history
* FIX: Only active assigns should be included in reminders

* Update lib/pending_assigns_reminder.rb

Co-authored-by: Robin Ward <robin.ward@gmail.com>
  • Loading branch information
jbrw and eviltrout committed Jan 14, 2022
1 parent a52da23 commit 7a04569
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/pending_assigns_reminder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ 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').count
Assignment.joins_with_topics.where(assigned_to_id: user.id, assigned_to_type: 'User', active: true).count
end

def assigned_topics(user, order:)
Expand All @@ -63,7 +63,7 @@ def assigned_topics(user, order:)
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'", user.id)
.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)
Expand Down
31 changes: 31 additions & 0 deletions spec/lib/pending_assigns_reminder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,36 @@ def assert_reminder_not_created

expect(reminders_count).to eq(2)
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

0 comments on commit 7a04569

Please sign in to comment.