FIX: Rate limiting when moving posts with freeze option (#30041)

before this commit, when moving posts with freeze option, the rate limit was being applied leading to errors. This commit fixes that.

and also adds tests for the scenarios of moving posts with freeze option.
This commit is contained in:
Gabriel Grubba 2024-12-02 15:48:13 -03:00 committed by GitHub
parent 7750441c43
commit 706987ce76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 70 additions and 0 deletions

View File

@ -299,6 +299,7 @@ class PostMover
end
moved_post.attributes = update
moved_post.disable_rate_limits! if @options[:freeze_original]
moved_post.save(validate: false)
DiscourseEvent.trigger(:post_moved, moved_post, original_topic.id)

View File

@ -2789,6 +2789,75 @@ RSpec.describe PostMover do
expect(pm_with_posts.posts.map(&:raw)).to include(*moving_posts.map(&:raw))
expect(pm.posts.map(&:raw)).to include(*moving_posts.map(&:raw))
end
context "with rate limit" do
before do
RateLimiter.enable
Fabricate.times(20, :post, topic: original_topic)
end
it "does not rate limit when moving to a new topic" do
begin
PostMover.new(
original_topic,
Discourse.system_user,
original_topic.posts.map(&:id),
options: {
freeze_original: true,
},
).to_new_topic("Hi I'm a new topic, with a copy of the old posts")
rescue RateLimiter::LimitExceeded
fail "Rate limit exceeded"
end
end
it "does not rate limit when moving to an existing topic" do
begin
PostMover.new(
original_topic,
Discourse.system_user,
original_topic.posts.map(&:id),
options: {
freeze_original: true,
},
).to_topic(destination_topic.id)
rescue RateLimiter::LimitExceeded
fail "Rate limit exceeded"
end
end
it "does not rate limit when moving to a new PM" do
begin
PostMover.new(
original_topic,
Discourse.system_user,
original_topic.posts.map(&:id),
move_to_pm: true,
options: {
freeze_original: true,
},
).to_new_topic("Hi I'm a new PM, with a copy of the old posts")
rescue RateLimiter::LimitExceeded
fail "Rate limit exceeded"
end
end
it "does not rate limit when moving to an existing PM" do
begin
PostMover.new(
original_topic,
Discourse.system_user,
original_topic.posts.map(&:id),
move_to_pm: true,
options: {
freeze_original: true,
},
).to_topic(destination_topic.id)
rescue RateLimiter::LimitExceeded
fail "Rate limit exceeded"
end
end
end
end
end
end