FEATURE: 🎁 rate limit invites for non-staff users

This commit is contained in:
Arpit Jalan 2015-01-20 00:20:01 +05:30
parent 2ae3ebc88b
commit 5e751ce90a
5 changed files with 14 additions and 1 deletions

View file

@ -1,6 +1,11 @@
require_dependency 'rate_limiter'
class Invite < ActiveRecord::Base
include RateLimiter::OnCreateRecord
include Trashable
rate_limit :limit_invites_per_day
belongs_to :user
belongs_to :topic
belongs_to :invited_by, class_name: 'User'
@ -184,6 +189,10 @@ class Invite < ActiveRecord::Base
Jobs.enqueue(:invite_email, invite_id: self.id)
end
def limit_invites_per_day
RateLimiter.new(invited_by, "invites-per-day:#{Date.today}", SiteSetting.max_invites_per_day, 1.day.to_i)
end
def self.base_directory
File.join(Rails.root, "public", "uploads", "csv", RailsMultisite::ConnectionManagement.current_db)
end

View file

@ -1018,7 +1018,7 @@ en:
email_placeholder: 'name@example.com'
success: "We mailed out an invitation to <b>{{email}}</b>. We'll notify you when the invitation is redeemed. Check the invitations tab on your user page to keep track of your invites."
error: "Sorry, we couldn't invite that person. Perhaps they are already a user?"
error: "Sorry, we couldn't invite that person. Perhaps they are already a user? (Invites are rate limited)"
login_reply: 'Log In to Reply'

View file

@ -831,6 +831,7 @@ en:
max_edits_per_day: "Maximum number of edits per user per day."
max_topics_per_day: "Maximum number of topics a user can create per day."
max_private_messages_per_day: "Maximum number of private messages users can create per day."
max_invites_per_day: "Maximum number of invites a user can send per day."
suggested_topics: "Number of suggested topics shown at the bottom of a topic."
limit_suggested_to_category: "Only show topics from the current category in suggested topics."

View file

@ -611,6 +611,7 @@ rate_limits:
max_bookmarks_per_day: 20
max_flags_per_day: 20
max_edits_per_day: 30
max_invites_per_day: 10
max_topics_in_first_day: 5
max_replies_in_first_day: 10

View file

@ -4,6 +4,8 @@ describe Invite do
it { is_expected.to validate_presence_of :invited_by_id }
it { is_expected.to rate_limit }
let(:iceking) { 'iceking@adventuretime.ooo' }
context 'user validators' do