FIX: Assignments limit shouldn't prevent from reassigning a post (#556)

At the moment, it's possible to have maximum 5 assignments per topic 
(that includes topic and post assignments). When trying to assign more, 
a message "Limit of 5 assignments per topic has been reached" appears.

One possible edge case here is _reassigning_ a topic or a post. Reassignment 
doesn't lead to exceeding the limit, and therefore it should be possible. But 
at the moment we handle correctly only _topic_  reassignments, while when 
reassigning a _post_, we show the error message "the limit has been reached".

This commit makes post reassignments work correctly too.
This commit is contained in:
Andrei Prigorshnev 2024-03-29 11:50:02 +00:00 committed by GitHub
parent 08c2a4e0f3
commit 51920a99c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -547,8 +547,7 @@ class ::Assigner
end
def reassign?
return false if !@target.is_a?(Topic)
Assignment.exists?(topic_id: @target.id, target: @target, active: true)
Assignment.exists?(target: @target, active: true)
end
def no_assignee_change?(assignee)

View File

@ -264,6 +264,21 @@ RSpec.describe Assigner do
expect(second_assign[:success]).to eq(true)
end
it "reassigns a post even when at the assignments limit" do
posts =
(described_class::ASSIGNMENTS_PER_TOPIC_LIMIT).times.map do
Fabricate(:post, topic: topic)
end
posts.each do |post|
user = Fabricate(:moderator)
described_class.new(post, admin).assign(user)
end
status = described_class.new(posts.first, admin).assign(Fabricate(:moderator))
expect(status[:success]).to eq(true)
end
context "when 'allow_self_reassign' is false" do
subject(:assign) do
assigner.assign(moderator, note: other_note, allow_self_reassign: self_reassign)