Remove hardcoded rate limit value
Name is chosen to match the equivalent setting in the configuration of the rate limits for edits. Fixes #4427.
This commit is contained in:
parent
9d47ad5fe5
commit
2d8feb6d79
4 changed files with 5 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: |
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue