From 2d8feb6d79af2e96d83cf67ca0771116c9c0f11a Mon Sep 17 00:00:00 2001 From: gobinathal Date: Mon, 8 Jan 2024 22:29:34 +0530 Subject: [PATCH] Remove hardcoded rate limit value Name is chosen to match the equivalent setting in the configuration of the rate limits for edits. Fixes #4427. --- app/models/user.rb | 4 ++-- config/settings.yml | 1 + config/settings/test.yml | 1 + test/controllers/api/changeset_comments_controller_test.rb | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) 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 -- 2.39.5