From 44dd73e15177ae6d2313f809a952a641c73ad6d1 Mon Sep 17 00:00:00 2001 From: jbrw Date: Mon, 31 Jan 2022 15:26:58 -0500 Subject: [PATCH] FIX: Exclude inactive assigns from assigned_total count (#288) If `SiteSetting.unassign_on_close` is enabled, an Assignment record can still exist, but be set to inactive, when a Topic is closed. Inactivement Assignments should be ignored when comparing to the maximum number of assigned topics. --- lib/assigner.rb | 2 +- spec/lib/assigner_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/assigner.rb b/lib/assigner.rb index 17e5afe..73b9838 100644 --- a/lib/assigner.rb +++ b/lib/assigner.rb @@ -138,7 +138,7 @@ class ::Assigner assigned_total = Assignment .joins_with_topics .where(topics: { deleted_at: nil }) - .where(assigned_to_id: assign_to.id) + .where(assigned_to_id: assign_to.id, active: true) .count assigned_total < SiteSetting.max_assigned_topics diff --git a/spec/lib/assigner_spec.rb b/spec/lib/assigner_spec.rb index a2269a6..427f0ea 100644 --- a/spec/lib/assigner_spec.rb +++ b/spec/lib/assigner_spec.rb @@ -160,6 +160,20 @@ RSpec.describe Assigner do expect(third_assign[:success]).to eq(true) end + it "doesn't count inactive assigns when enforcing the limit" do + SiteSetting.max_assigned_topics = 1 + SiteSetting.unassign_on_close = true + another_post = Fabricate(:post) + + first_assign = assigner.assign(moderator) + topic.update_status("closed", true, Discourse.system_user) + + second_assign = described_class.new(another_post.topic, moderator_2).assign(moderator) + + expect(first_assign[:success]).to eq(true) + expect(second_assign[:success]).to eq(true) + end + fab!(:admin) { Fabricate(:admin) } it 'fails to assign when the assigned user cannot view the pm' do