* Refactoring Spam Handler There's considerable repeated logic between checking spam for an article and spam for a comment and user. This attempts to send things through channels that are similar and close in organization. * Fixing broken spec * Fixing spec around recent user * Update app/models/reaction.rb Co-authored-by: Michael Kohl <citizen428@forem.com> * Update app/models/reaction.rb Co-authored-by: Michael Kohl <citizen428@forem.com> * Consolidating new user query logic Prior to this commit there were two separate queries around new user logic. With this commit, we're changing the logic to repurpose a site wide setting. * Generalizing a previously specific message * Fixing method name As part of a recommended refactor, I extracted a method, then renamed it. I failed to account for that renaming. This commit fixes that. Co-authored-by: Michael Kohl <citizen428@forem.com>
52 lines
2.1 KiB
Ruby
52 lines
2.1 KiB
Ruby
module Settings
|
|
class RateLimit < Base
|
|
self.table_name = :settings_rate_limits
|
|
|
|
setting :article_update, type: :integer, default: 30
|
|
setting :comment_antispam_creation, type: :integer, default: 1
|
|
# Explicitly defaults to 7 to accommodate DEV Top 7 Posts
|
|
setting :mention_creation, type: :integer, default: 7
|
|
setting :comment_creation, type: :integer, default: 9
|
|
setting :email_recipient, type: :integer, default: 5
|
|
setting :feedback_message_creation, type: :integer, default: 5
|
|
setting :follow_count_daily, type: :integer, default: 500
|
|
setting :image_upload, type: :integer, default: 9
|
|
setting :listing_creation, type: :integer, default: 1
|
|
setting :organization_creation, type: :integer, default: 1
|
|
setting :published_article_antispam_creation, type: :integer, default: 1
|
|
setting :published_article_creation, type: :integer, default: 9
|
|
setting :reaction_creation, type: :integer, default: 10
|
|
setting :send_email_confirmation, type: :integer, default: 2
|
|
setting :spam_trigger_terms, type: :array, default: []
|
|
setting :user_considered_new_days, type: :integer, default: 3
|
|
setting :user_subscription_creation, type: :integer, default: 3
|
|
setting :user_update, type: :integer, default: 15
|
|
|
|
# A helper function to determine if we should consider the user a "new" user.
|
|
#
|
|
# @note A "new" user is more likely to start spamming than an "old" user.
|
|
#
|
|
# @param user [User, UserDecorator]
|
|
#
|
|
# @return [Boolean]
|
|
def self.user_considered_new?(user:)
|
|
return true unless user
|
|
return false unless user_considered_new_days.positive?
|
|
|
|
user.created_at.after?(user_considered_new_days.days.ago)
|
|
end
|
|
|
|
# A helper function to determine if text is spammy.
|
|
#
|
|
# @param text [String] text to check for "spamminess"
|
|
#
|
|
# @return [TrueClass] if this is spammy
|
|
# @return [FalseClass] if this isn't spammy
|
|
def self.trigger_spam_for?(text:)
|
|
return false if spam_trigger_terms.empty?
|
|
|
|
regexp = Regexp.new("(#{spam_trigger_terms.join('|')})", true)
|
|
regexp.match?(text)
|
|
end
|
|
end
|
|
end
|