Replace MAX_USER_MENTIONS with Settings::RateLimit.mention_creation (#13736)
* Replace MAX_USER_MENTIONS with Settings::RateLimit.mention_creation * Remove Vaidehi-specific TODOs * Remove unnecessary constant stubs * Remove rate_limit_mention_creation from SiteConfig
This commit is contained in:
parent
8f0c24c167
commit
5e6aad98e3
12 changed files with 37 additions and 27 deletions
|
|
@ -68,6 +68,12 @@ module RateLimitCheckerHelper
|
|||
title: "Limit number of comments created by a new member",
|
||||
description: new_user_message("comments")
|
||||
},
|
||||
mention_creation: {
|
||||
min: 0,
|
||||
placeholder: 7,
|
||||
title: "Limit number of @-mentions in a post or comment",
|
||||
description: "How many times can someone @-mention other users in a post or comment?"
|
||||
},
|
||||
listing_creation: {
|
||||
min: 1,
|
||||
placeholder: 1,
|
||||
|
|
|
|||
|
|
@ -25,9 +25,6 @@ class Article < ApplicationRecord
|
|||
counter_culture :user
|
||||
counter_culture :organization
|
||||
|
||||
# TODO: Vaidehi Joshi - Extract this into a constant or SiteConfig variable
|
||||
# after https://github.com/forem/rfcs/pull/22 has been completed?
|
||||
MAX_USER_MENTIONS = 7 # Explicitly set to 7 to accommodate DEV Top 7 Posts
|
||||
# The date that we began limiting the number of user mentions in an article.
|
||||
MAX_USER_MENTION_LIVE_AT = Time.utc(2021, 4, 7).freeze
|
||||
|
||||
|
|
@ -690,9 +687,9 @@ class Article < ApplicationRecord
|
|||
|
||||
# The "mentioned-user" css is added by Html::Parser#user_link_if_exists
|
||||
mentions_count = Nokogiri::HTML(processed_html).css(".mentioned-user").size
|
||||
return if mentions_count <= MAX_USER_MENTIONS
|
||||
return if mentions_count <= Settings::RateLimit.mention_creation
|
||||
|
||||
errors.add(:base, "You cannot mention more than #{MAX_USER_MENTIONS} users in a post!")
|
||||
errors.add(:base, "You cannot mention more than #{Settings::RateLimit.mention_creation} users in a post!")
|
||||
end
|
||||
|
||||
def create_slug
|
||||
|
|
|
|||
|
|
@ -12,9 +12,6 @@ class Comment < ApplicationRecord
|
|||
TITLE_DELETED = "[deleted]".freeze
|
||||
TITLE_HIDDEN = "[hidden by post author]".freeze
|
||||
|
||||
# TODO: Vaidehi Joshi - Extract this into a constant or SiteConfig variable
|
||||
# after https://github.com/forem/rfcs/pull/22 has been completed?
|
||||
MAX_USER_MENTIONS = 7 # Explicitly set to 7 to accommodate DEV Top 7 Posts
|
||||
# The date that we began limiting the number of user mentions in a comment.
|
||||
MAX_USER_MENTION_LIVE_AT = Time.utc(2021, 3, 12).freeze
|
||||
|
||||
|
|
@ -323,9 +320,9 @@ class Comment < ApplicationRecord
|
|||
|
||||
# The "mentioned-user" css is added by Html::Parser#user_link_if_exists
|
||||
mentions_count = Nokogiri::HTML(processed_html).css(".mentioned-user").size
|
||||
return if mentions_count <= MAX_USER_MENTIONS
|
||||
return if mentions_count <= Settings::RateLimit.mention_creation
|
||||
|
||||
errors.add(:base, "You cannot mention more than #{MAX_USER_MENTIONS} users in a comment!")
|
||||
errors.add(:base, "You cannot mention more than #{Settings::RateLimit.mention_creation} users in a comment!")
|
||||
end
|
||||
|
||||
def record_field_test_event
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ module Settings
|
|||
|
||||
field :article_update, type: :integer, default: 30
|
||||
field :comment_antispam_creation, type: :integer, default: 1
|
||||
# Explicitly defaults to 7 to accommodate DEV Top 7 Posts
|
||||
field :mention_creation, type: :integer, default: 7
|
||||
field :comment_creation, type: :integer, default: 9
|
||||
field :email_recipient, type: :integer, default: 5
|
||||
field :feedback_message_creation, type: :integer, default: 5
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ module EdgeCache
|
|||
end
|
||||
|
||||
def self.nginx_available?
|
||||
# TODO: (Vaidehi Joshi) - Right now, we are checking that nginx is
|
||||
# TODO: Right now, we are checking that nginx is
|
||||
# available on every purge request/call to this bust service. If we are going
|
||||
# to bust multiple paths, we should be able to check that nginx is
|
||||
# available just once, and persist it on the class with @provider_available?.
|
||||
|
|
|
|||
|
|
@ -87,13 +87,13 @@ class RateLimitChecker
|
|||
end
|
||||
|
||||
def check_published_article_creation_limit
|
||||
# TODO: Vaidehi Joshi - We should make this time frame configurable.
|
||||
# TODO: We should make this time frame configurable.
|
||||
user.articles.published.where("created_at > ?", 30.seconds.ago).size >
|
||||
Settings::RateLimit.published_article_creation
|
||||
end
|
||||
|
||||
def check_published_article_antispam_creation_limit
|
||||
# TODO: Vaidehi Joshi - We should make this time frame configurable.
|
||||
# TODO: We should make this time frame configurable.
|
||||
user.articles.published.where("created_at > ?", 5.minutes.ago).size >
|
||||
Settings::RateLimit.published_article_antispam_creation
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<% elsif forem_creator_flow_enabled? %>
|
||||
<%= render "shared/authentication/forem_creator_signup" %>
|
||||
<% elsif waiting_on_first_user? %>
|
||||
<%# TODO: Vaidehi Joshi - Delete this view once forem creator onboarding is shipped %>
|
||||
<%# TODO: Delete this view once forem creator onboarding is shipped %>
|
||||
<%= render "shared/authentication/initial_account_wizard" %>
|
||||
<% else %>
|
||||
<%= render "devise/shared/authorization_error" %>
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<% elsif forem_creator_flow_enabled? %>
|
||||
<%# TODO: Vaidehi Joshi - Extract this into its own form %>
|
||||
<%# TODO: Extract this into its own form %>
|
||||
<div class="align-center">
|
||||
<p class="pb-4 fw-bold">Almost there!</p>
|
||||
<p class="registration__description">Let's create an admin account for your community.</p>
|
||||
|
|
@ -109,7 +109,7 @@
|
|||
<% end %>
|
||||
|
||||
<% if forem_creator_flow_enabled? %>
|
||||
<%# TODO: Vaidehi Joshi - Extract this into its own form %>
|
||||
<%# TODO: Extract this into its own form %>
|
||||
<div class="flex flex-col pt-3">
|
||||
<%= f.submit "Create admin account", class: "crayons-btn" %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1220,7 +1220,6 @@ RSpec.describe Article, type: :model do
|
|||
|
||||
describe "#user_mentions_in_markdown" do
|
||||
before do
|
||||
stub_const("Article::MAX_USER_MENTIONS", 7)
|
||||
stub_const("Article::MAX_USER_MENTION_LIVE_AT", 1.day.ago) # Set live_at date to a time in the past
|
||||
end
|
||||
|
||||
|
|
@ -1228,20 +1227,20 @@ RSpec.describe Article, type: :model do
|
|||
# Explicitly set created_at date to a time before MAX_USER_MENTION_LIVE_AT
|
||||
article = create(:article, created_at: 3.days.ago)
|
||||
|
||||
article.body_markdown = "hi @#{user.username}! " * (Article::MAX_USER_MENTIONS + 1)
|
||||
article.body_markdown = "hi @#{user.username}! " * (Settings::RateLimit.mention_creation + 1)
|
||||
expect(article).to be_valid
|
||||
end
|
||||
|
||||
it "is valid with seven or fewer mentions if created after MAX_USER_MENTION_LIVE_AT date" do
|
||||
article.body_markdown = "hi @#{user.username}! " * Article::MAX_USER_MENTIONS
|
||||
article.body_markdown = "hi @#{user.username}! " * Settings::RateLimit.mention_creation
|
||||
expect(article).to be_valid
|
||||
end
|
||||
|
||||
it "is invalid with more than seven mentions if created after MAX_USER_MENTION_LIVE_AT date" do
|
||||
article.body_markdown = "hi @#{user.username}! " * (Article::MAX_USER_MENTIONS + 1)
|
||||
article.body_markdown = "hi @#{user.username}! " * (Settings::RateLimit.mention_creation + 1)
|
||||
expect(article).not_to be_valid
|
||||
expect(article.errors[:base])
|
||||
.to include("You cannot mention more than #{Article::MAX_USER_MENTIONS} users in a post!")
|
||||
.to include("You cannot mention more than #{Settings::RateLimit.mention_creation} users in a post!")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -87,7 +87,6 @@ RSpec.describe Comment, type: :model do
|
|||
|
||||
describe "#user_mentions_in_markdown" do
|
||||
before do
|
||||
stub_const("Comment::MAX_USER_MENTIONS", 7)
|
||||
stub_const("Comment::MAX_USER_MENTION_LIVE_AT", 1.day.ago) # Set live_at date to a time in the past
|
||||
end
|
||||
|
||||
|
|
@ -96,24 +95,24 @@ RSpec.describe Comment, type: :model do
|
|||
subject.created_at = 3.days.ago
|
||||
subject.commentable_type = "Article"
|
||||
|
||||
subject.body_markdown = "hi @#{user.username}! " * (Comment::MAX_USER_MENTIONS + 1)
|
||||
subject.body_markdown = "hi @#{user.username}! " * (Settings::RateLimit.mention_creation + 1)
|
||||
expect(subject).to be_valid
|
||||
end
|
||||
|
||||
it "is valid with seven or fewer mentions if created after MAX_USER_MENTION_LIVE_AT date" do
|
||||
subject.commentable_type = "Article"
|
||||
|
||||
subject.body_markdown = "hi @#{user.username}! " * Comment::MAX_USER_MENTIONS
|
||||
subject.body_markdown = "hi @#{user.username}! " * Settings::RateLimit.mention_creation
|
||||
expect(subject).to be_valid
|
||||
end
|
||||
|
||||
it "is invalid with more than seven mentions if created after MAX_USER_MENTION_LIVE_AT date" do
|
||||
subject.commentable_type = "Article"
|
||||
|
||||
subject.body_markdown = "hi @#{user.username}! " * (Comment::MAX_USER_MENTIONS + 1)
|
||||
subject.body_markdown = "hi @#{user.username}! " * (Settings::RateLimit.mention_creation + 1)
|
||||
expect(subject).not_to be_valid
|
||||
expect(subject.errors[:base])
|
||||
.to include("You cannot mention more than #{Comment::MAX_USER_MENTIONS} users in a comment!")
|
||||
.to include("You cannot mention more than #{Settings::RateLimit.mention_creation} users in a comment!")
|
||||
end
|
||||
end
|
||||
# rubocop:enable RSpec/NamedSubject
|
||||
|
|
|
|||
|
|
@ -588,6 +588,16 @@ RSpec.describe "/admin/customization/config", type: :request do
|
|||
end.to change(Settings::RateLimit, :comment_creation).from(default_value).to(3)
|
||||
end
|
||||
|
||||
it "updates mention_creation" do
|
||||
default_value = Settings::RateLimit.get_default(:mention_creation)
|
||||
expect do
|
||||
post admin_settings_rate_limits_path, params: {
|
||||
settings_rate_limit: { mention_creation: 10 },
|
||||
confirmation: confirmation_message
|
||||
}
|
||||
end.to change(Settings::RateLimit, :mention_creation).from(default_value).to(10)
|
||||
end
|
||||
|
||||
it "updates published_article_creation" do
|
||||
default_value = Settings::RateLimit.get_default(:published_article_creation)
|
||||
expect do
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ RSpec.describe "Completing Onboarding", type: :system, js: true do
|
|||
end
|
||||
end
|
||||
|
||||
# TODO: Vaidehi Joshi - Extract this into a reusable helper
|
||||
# TODO: Extract this into a reusable helper
|
||||
def log_in_user(user)
|
||||
fill_in("user_email", with: user.email)
|
||||
fill_in("user_password", with: user.password)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue