From: Tom Hughes Date: Thu, 7 Nov 2024 18:49:45 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/4464' X-Git-Tag: live~208 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/afa3a3728d4b7b4b8b560cbf3ad248388d474467?hp=9d47ad5fe5aa20d674d13c7ac028a46eb3cd4a5e Merge remote-tracking branch 'upstream/pull/4464' --- diff --git a/app/models/user.rb b/app/models/user.rb index d8e8771d8..917faca21 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -423,8 +423,8 @@ class User < ApplicationRecord if moderator? Settings.moderator_changeset_comments_per_hour else - previous_comments = changeset_comments.limit(200).count - max_comments = previous_comments / 200.0 * Settings.max_changeset_comments_per_hour + previous_comments = changeset_comments.limit(Settings.comments_to_max_changeset_comments).count + max_comments = previous_comments / Settings.comments_to_max_changeset_comments.to_f * Settings.max_changeset_comments_per_hour max_comments = max_comments.floor.clamp(Settings.initial_changeset_comments_per_hour, Settings.max_changeset_comments_per_hour) max_comments /= 2**active_reports max_comments.floor.clamp(Settings.min_changeset_comments_per_hour, Settings.max_changeset_comments_per_hour) diff --git a/config/settings.yml b/config/settings.yml index b5a565b13..db871775e 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -69,6 +69,7 @@ max_friends_per_hour: 60 min_changeset_comments_per_hour: 1 initial_changeset_comments_per_hour: 6 max_changeset_comments_per_hour: 60 +comments_to_max_changeset_comments: 200 moderator_changeset_comments_per_hour: 36000 # Rate limit for changes min_changes_per_hour: 100 diff --git a/config/settings/test.yml b/config/settings/test.yml index fe5aa5d89..b0e2f4613 100644 --- a/config/settings/test.yml +++ b/config/settings/test.yml @@ -21,6 +21,7 @@ trace_image_storage: "test" trace_icon_storage: "test" # Lower some rate limits for testing max_changeset_comments_per_hour: 10 +comments_to_max_changeset_comments: 20 moderator_changeset_comments_per_hour: 15 # Private key for signing id_tokens doorkeeper_signing_key: | diff --git a/test/controllers/api/changeset_comments_controller_test.rb b/test/controllers/api/changeset_comments_controller_test.rb index 35e45e8c8..21f30714c 100644 --- a/test/controllers/api/changeset_comments_controller_test.rb +++ b/test/controllers/api/changeset_comments_controller_test.rb @@ -158,7 +158,7 @@ module Api def test_create_comment_experienced_user_rate_limit changeset = create(:changeset, :closed) user = create(:user) - create_list(:changeset_comment, 200, :author_id => user.id, :created_at => Time.now.utc - 1.day) + create_list(:changeset_comment, Settings.comments_to_max_changeset_comments, :author_id => user.id, :created_at => Time.now.utc - 1.day) auth_header = bearer_authorization_header user