* Change from #after_save to #after_create * Update .babelrc * Update cloud_name for test * Update SlackBot's RssReader channel * Update helpful-hints.md * Create .gitdocs.json * Remove serve-docs script * Update docs/helpful-hints.md * Update approval * Revert "Change from #after_save to #after_create" This reverts commit 548ee0d2c0d56a1aa67316468f4106ac9f437662. * Create delayed_job.rb * Bump ancestry gem to 3.0.3 * Fix broken spec * Remove manual Delayed::Job config in test * Update spec_helper.rb * Fix broken specs * Mute SlackBot in test * Remove weekly-dgiest.yml * Create PodcastEpisodeDecorator
38 lines
1.1 KiB
Ruby
38 lines
1.1 KiB
Ruby
class RateLimitChecker
|
|
attr_accessor :user
|
|
def initialize(user = nil)
|
|
@user = user
|
|
end
|
|
|
|
def limit_by_situation(situation)
|
|
result = case situation
|
|
when "comment_creation"
|
|
user.comments.where("created_at > ?", 30.seconds.ago).size > 9
|
|
when "published_article_creation"
|
|
user.articles.
|
|
where(published: true).
|
|
where("created_at > ?", 30.seconds.ago).size > 9
|
|
else
|
|
false
|
|
end
|
|
ping_admins if result == true
|
|
result
|
|
end
|
|
|
|
def limit_by_email_recipient_address(address)
|
|
# This is related to the recipient, not the "user" initiator, like in situation.
|
|
EmailMessage.where(to: address).
|
|
where("sent_at > ?", 2.minutes.ago).size > 5
|
|
end
|
|
|
|
def ping_admins
|
|
return unless user && Rails.env.production?
|
|
SlackBot.ping(
|
|
"Rate limit exceeded. https://dev.to#{user.path}",
|
|
channel: "abuse-reports",
|
|
username: "rate_limit",
|
|
icon_emoji: ":hand:",
|
|
)
|
|
end
|
|
handle_asynchronously :ping_admins
|
|
end
|