mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FEATURE: 🎁 rate limit invites for non-staff users
This commit is contained in:
parent
2ae3ebc88b
commit
5e751ce90a
5 changed files with 14 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue