2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
class Invite < ActiveRecord::Base
|
2017-05-02 17:43:33 +08:00
|
|
|
class UserExists < StandardError; end
|
2015-01-20 02:50:01 +08:00
|
|
|
include RateLimiter::OnCreateRecord
|
2013-05-07 12:39:01 +08:00
|
|
|
include Trashable
|
2013-02-07 23:45:24 +08:00
|
|
|
|
2020-06-09 23:19:32 +08:00
|
|
|
# TODO(2021-05-22): remove
|
|
|
|
self.ignored_columns = %w{
|
|
|
|
user_id
|
|
|
|
redeemed_at
|
|
|
|
}
|
|
|
|
|
2019-07-19 13:59:12 +08:00
|
|
|
BULK_INVITE_EMAIL_LIMIT = 200
|
|
|
|
|
2015-01-20 02:50:01 +08:00
|
|
|
rate_limit :limit_invites_per_day
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
belongs_to :user
|
|
|
|
belongs_to :topic
|
2013-03-01 02:54:12 +08:00
|
|
|
belongs_to :invited_by, class_name: 'User'
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2020-06-09 23:19:32 +08:00
|
|
|
has_many :invited_users
|
|
|
|
has_many :users, through: :invited_users
|
2014-05-08 14:45:49 +08:00
|
|
|
has_many :invited_groups
|
|
|
|
has_many :groups, through: :invited_groups
|
2013-02-06 03:16:51 +08:00
|
|
|
has_many :topic_invites
|
2013-02-07 23:45:24 +08:00
|
|
|
has_many :topics, through: :topic_invites, source: :topic
|
2013-02-06 03:16:51 +08:00
|
|
|
validates_presence_of :invited_by_id
|
2020-06-03 10:13:25 +08:00
|
|
|
validates :email, email: true, allow_blank: true
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
before_create do
|
|
|
|
self.invite_key ||= SecureRandom.hex
|
2020-06-09 23:19:32 +08:00
|
|
|
self.expires_at ||= SiteSetting.invite_expiry_days.days.from_now
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2014-07-14 23:56:26 +08:00
|
|
|
before_validation do
|
|
|
|
self.email = Email.downcase(email) unless email.nil?
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2020-06-09 23:19:32 +08:00
|
|
|
validate :ensure_max_redemptions_allowed
|
2013-02-06 03:16:51 +08:00
|
|
|
validate :user_doesnt_already_exist
|
2021-02-04 02:01:23 +08:00
|
|
|
validate :ensure_no_invalid_email_invites
|
2013-02-06 03:16:51 +08:00
|
|
|
attr_accessor :email_already_exists
|
2013-02-07 23:45:24 +08:00
|
|
|
|
2020-06-09 23:19:32 +08:00
|
|
|
scope :single_use_invites, -> { where('invites.max_redemptions_allowed = 1') }
|
|
|
|
scope :multiple_use_invites, -> { where('invites.max_redemptions_allowed > 1') }
|
|
|
|
|
2019-07-19 13:59:12 +08:00
|
|
|
def self.emailed_status_types
|
|
|
|
@emailed_status_types ||= Enum.new(not_required: 0, pending: 1, bulk_pending: 2, sending: 3, sent: 4)
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
def user_doesnt_already_exist
|
|
|
|
@email_already_exists = false
|
|
|
|
return if email.blank?
|
2018-01-19 22:29:15 +08:00
|
|
|
user = Invite.find_user_by_email(email)
|
2017-04-27 02:47:36 +08:00
|
|
|
|
2020-06-09 23:19:32 +08:00
|
|
|
if user && user.id != self.invited_users&.first&.user_id
|
2013-02-06 03:16:51 +08:00
|
|
|
@email_already_exists = true
|
|
|
|
errors.add(:email)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-09 23:19:32 +08:00
|
|
|
def is_invite_link?
|
2021-01-20 16:50:02 +08:00
|
|
|
email.blank?
|
2020-06-09 23:19:32 +08:00
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
def redeemed?
|
2020-06-09 23:19:32 +08:00
|
|
|
if is_invite_link?
|
|
|
|
redemption_count >= max_redemptions_allowed
|
|
|
|
else
|
|
|
|
self.invited_users.count > 0
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def expired?
|
2020-06-09 23:19:32 +08:00
|
|
|
expires_at < Time.zone.now
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2014-01-22 05:53:46 +08:00
|
|
|
# link_valid? indicates whether the invite link can be used to log in to the site
|
|
|
|
def link_valid?
|
|
|
|
invalidated_at.nil?
|
|
|
|
end
|
|
|
|
|
2019-04-13 15:34:25 +08:00
|
|
|
def redeem(username: nil, name: nil, password: nil, user_custom_fields: nil, ip_address: nil)
|
2019-05-13 15:42:13 +08:00
|
|
|
if !expired? && !destroyed? && link_valid?
|
2020-06-09 23:19:32 +08:00
|
|
|
InviteRedeemer.new(invite: self, email: self.email, username: username, name: name, password: password, user_custom_fields: user_custom_fields, ip_address: ip_address).redeem
|
2019-05-13 15:42:13 +08:00
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2016-06-06 01:22:46 +08:00
|
|
|
def self.invite_by_email(email, invited_by, topic = nil, group_ids = nil, custom_message = nil)
|
2016-09-21 01:12:00 +08:00
|
|
|
create_invite_by_email(email, invited_by,
|
|
|
|
topic: topic,
|
|
|
|
group_ids: group_ids,
|
|
|
|
custom_message: custom_message,
|
2019-07-19 13:59:12 +08:00
|
|
|
emailed_status: emailed_status_types[:pending]
|
2016-09-21 01:12:00 +08:00
|
|
|
)
|
2015-08-31 22:06:13 +08:00
|
|
|
end
|
|
|
|
|
2020-06-09 23:19:32 +08:00
|
|
|
def self.generate_single_use_invite_link(email, invited_by, topic = nil, group_ids = nil)
|
2016-09-21 01:12:00 +08:00
|
|
|
invite = create_invite_by_email(email, invited_by,
|
|
|
|
topic: topic,
|
|
|
|
group_ids: group_ids,
|
2019-07-19 13:59:12 +08:00
|
|
|
emailed_status: emailed_status_types[:not_required]
|
2016-09-21 01:12:00 +08:00
|
|
|
)
|
2017-07-28 09:20:09 +08:00
|
|
|
|
2015-09-16 19:57:32 +08:00
|
|
|
"#{Discourse.base_url}/invites/#{invite.invite_key}" if invite
|
2015-08-31 22:06:13 +08:00
|
|
|
end
|
|
|
|
|
2013-11-07 01:56:26 +08:00
|
|
|
# Create an invite for a user, supplying an optional topic
|
|
|
|
#
|
|
|
|
# Return the previously existing invite if already exists. Returns nil if the invite can't be created.
|
2016-09-21 01:12:00 +08:00
|
|
|
def self.create_invite_by_email(email, invited_by, opts = nil)
|
|
|
|
opts ||= {}
|
|
|
|
|
|
|
|
topic = opts[:topic]
|
|
|
|
group_ids = opts[:group_ids]
|
|
|
|
custom_message = opts[:custom_message]
|
2019-07-19 13:59:12 +08:00
|
|
|
emailed_status = opts[:emailed_status] || emailed_status_types[:pending]
|
2013-11-07 01:56:26 +08:00
|
|
|
lower_email = Email.downcase(email)
|
2014-05-09 09:45:18 +08:00
|
|
|
|
2018-01-19 22:29:15 +08:00
|
|
|
if user = find_user_by_email(lower_email)
|
2018-12-05 23:43:07 +08:00
|
|
|
raise UserExists.new(I18n.t("invite.user_exists",
|
|
|
|
email: lower_email,
|
|
|
|
username: user.username,
|
|
|
|
base_path: Discourse.base_path
|
|
|
|
))
|
2014-05-09 09:45:18 +08:00
|
|
|
end
|
|
|
|
|
2014-01-22 04:13:55 +08:00
|
|
|
invite = Invite.with_deleted
|
2014-05-09 09:45:18 +08:00
|
|
|
.where(email: lower_email, invited_by_id: invited_by.id)
|
2014-01-22 04:13:55 +08:00
|
|
|
.order('created_at DESC')
|
|
|
|
.first
|
|
|
|
|
2014-05-09 09:45:18 +08:00
|
|
|
if invite && (invite.expired? || invite.deleted_at)
|
2014-01-22 04:13:55 +08:00
|
|
|
invite.destroy
|
|
|
|
invite = nil
|
|
|
|
end
|
2013-11-07 01:56:26 +08:00
|
|
|
|
2018-12-11 06:24:02 +08:00
|
|
|
if invite
|
2019-07-19 13:59:12 +08:00
|
|
|
if invite.emailed_status == Invite.emailed_status_types[:not_required]
|
|
|
|
emailed_status = invite.emailed_status
|
|
|
|
end
|
|
|
|
|
2018-12-11 06:24:02 +08:00
|
|
|
invite.update_columns(
|
|
|
|
created_at: Time.zone.now,
|
|
|
|
updated_at: Time.zone.now,
|
2020-06-09 23:19:32 +08:00
|
|
|
expires_at: SiteSetting.invite_expiry_days.days.from_now,
|
2019-07-19 13:59:12 +08:00
|
|
|
emailed_status: emailed_status
|
2018-12-11 06:24:02 +08:00
|
|
|
)
|
|
|
|
else
|
|
|
|
create_args = {
|
|
|
|
invited_by: invited_by,
|
|
|
|
email: lower_email,
|
2019-07-19 13:59:12 +08:00
|
|
|
emailed_status: emailed_status
|
2018-12-11 06:24:02 +08:00
|
|
|
}
|
2017-04-11 22:05:35 +08:00
|
|
|
|
2016-09-21 01:12:00 +08:00
|
|
|
create_args[:moderator] = true if opts[:moderator]
|
2017-06-30 18:39:37 +08:00
|
|
|
create_args[:custom_message] = custom_message if custom_message
|
2016-09-21 01:12:00 +08:00
|
|
|
invite = Invite.create!(create_args)
|
2013-11-07 01:56:26 +08:00
|
|
|
end
|
|
|
|
|
2014-05-09 09:45:18 +08:00
|
|
|
if topic && !invite.topic_invites.pluck(:topic_id).include?(topic.id)
|
|
|
|
invite.topic_invites.create!(invite_id: invite.id, topic_id: topic.id)
|
|
|
|
# to correct association
|
|
|
|
topic.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
if group_ids.present?
|
|
|
|
group_ids = group_ids - invite.invited_groups.pluck(:group_id)
|
2018-12-05 23:43:07 +08:00
|
|
|
|
2014-05-09 09:45:18 +08:00
|
|
|
group_ids.each do |group_id|
|
|
|
|
invite.invited_groups.create!(group_id: group_id)
|
|
|
|
end
|
|
|
|
end
|
2013-11-07 01:56:26 +08:00
|
|
|
|
2019-07-19 13:59:12 +08:00
|
|
|
if emailed_status == emailed_status_types[:pending]
|
|
|
|
invite.update_column(:emailed_status, Invite.emailed_status_types[:sending])
|
|
|
|
Jobs.enqueue(:invite_email, invite_id: invite.id)
|
|
|
|
end
|
2014-05-09 09:45:18 +08:00
|
|
|
|
|
|
|
invite.reload
|
2013-11-07 01:56:26 +08:00
|
|
|
invite
|
|
|
|
end
|
|
|
|
|
2020-06-09 23:19:32 +08:00
|
|
|
def self.generate_multiple_use_invite_link(invited_by:, max_redemptions_allowed: 5, expires_at: 1.month.from_now, group_ids: nil)
|
|
|
|
Invite.transaction do
|
|
|
|
create_args = {
|
|
|
|
invited_by: invited_by,
|
|
|
|
max_redemptions_allowed: max_redemptions_allowed.to_i,
|
|
|
|
expires_at: expires_at,
|
|
|
|
emailed_status: emailed_status_types[:not_required]
|
|
|
|
}
|
|
|
|
invite = Invite.create!(create_args)
|
|
|
|
|
|
|
|
if group_ids.present?
|
|
|
|
now = Time.zone.now
|
|
|
|
invited_groups = group_ids.map { |group_id| { group_id: group_id, invite_id: invite.id, created_at: now, updated_at: now } }
|
|
|
|
InvitedGroup.insert_all(invited_groups)
|
|
|
|
end
|
|
|
|
|
|
|
|
"#{Discourse.base_url}/invites/#{invite.invite_key}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# redeem multiple use invite link
|
|
|
|
def redeem_invite_link(email: nil, username: nil, name: nil, password: nil, user_custom_fields: nil, ip_address: nil)
|
|
|
|
DistributedMutex.synchronize("redeem_invite_link_#{self.id}") do
|
|
|
|
reload
|
|
|
|
if is_invite_link? && !expired? && !redeemed? && !destroyed? && link_valid?
|
|
|
|
raise UserExists.new I18n.t("invite_link.email_taken") if UserEmail.exists?(email: email)
|
|
|
|
InviteRedeemer.new(invite: self, email: email, username: username, name: name, password: password, user_custom_fields: user_custom_fields, ip_address: ip_address).redeem
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-19 22:29:15 +08:00
|
|
|
def self.find_user_by_email(email)
|
2019-10-30 14:08:47 +08:00
|
|
|
User.with_email(Email.downcase(email)).where(staged: false).first
|
2018-01-19 22:29:15 +08:00
|
|
|
end
|
|
|
|
|
2014-07-14 23:56:26 +08:00
|
|
|
def self.get_group_ids(group_names)
|
|
|
|
group_ids = []
|
|
|
|
if group_names
|
|
|
|
group_names = group_names.split(',')
|
|
|
|
group_names.each { |group_name|
|
|
|
|
group_detail = Group.find_by_name(group_name)
|
|
|
|
group_ids.push(group_detail.id) if group_detail
|
|
|
|
}
|
|
|
|
end
|
|
|
|
group_ids
|
|
|
|
end
|
|
|
|
|
2020-06-09 23:19:32 +08:00
|
|
|
def self.find_all_pending_invites_from(inviter, offset = 0, limit = SiteSetting.invites_per_page)
|
|
|
|
Invite.single_use_invites
|
|
|
|
.joins("LEFT JOIN invited_users ON invites.id = invited_users.invite_id")
|
|
|
|
.joins("LEFT JOIN users ON invited_users.user_id = users.id")
|
|
|
|
.where('invited_users.user_id IS NULL')
|
|
|
|
.where(invited_by_id: inviter.id)
|
2015-08-26 09:41:52 +08:00
|
|
|
.where('invites.email IS NOT NULL')
|
2020-06-09 23:19:32 +08:00
|
|
|
.order('invites.updated_at DESC')
|
2015-08-25 03:03:25 +08:00
|
|
|
.limit(limit)
|
2014-08-01 19:06:31 +08:00
|
|
|
.offset(offset)
|
2013-11-09 03:11:41 +08:00
|
|
|
end
|
|
|
|
|
2015-07-11 20:09:12 +08:00
|
|
|
def self.find_pending_invites_from(inviter, offset = 0)
|
2020-06-09 23:19:32 +08:00
|
|
|
find_all_pending_invites_from(inviter, offset)
|
2015-07-11 20:09:12 +08:00
|
|
|
end
|
|
|
|
|
2020-06-09 23:19:32 +08:00
|
|
|
def self.find_pending_invites_count(inviter)
|
|
|
|
find_all_pending_invites_from(inviter, 0, nil).reorder(nil).count
|
2013-11-09 03:11:41 +08:00
|
|
|
end
|
|
|
|
|
2020-06-09 23:19:32 +08:00
|
|
|
def self.find_all_redeemed_invites_from(inviter, offset = 0, limit = SiteSetting.invites_per_page)
|
|
|
|
InvitedUser.includes(:invite)
|
|
|
|
.includes(user: :user_stat)
|
|
|
|
.where('invited_users.user_id IS NOT NULL')
|
|
|
|
.where('invites.invited_by_id = ?', inviter.id)
|
|
|
|
.order('user_stats.time_read DESC, invited_users.redeemed_at DESC')
|
|
|
|
.limit(limit)
|
|
|
|
.offset(offset)
|
|
|
|
.references('invite')
|
|
|
|
.references('user')
|
|
|
|
.references('user_stat')
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.find_redeemed_invites_from(inviter, offset = 0)
|
|
|
|
find_all_redeemed_invites_from(inviter, offset)
|
2015-08-25 03:03:25 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.find_redeemed_invites_count(inviter)
|
2020-06-09 23:19:32 +08:00
|
|
|
find_all_redeemed_invites_from(inviter, 0, nil).reorder(nil).count
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.find_all_links_invites_from(inviter, offset = 0, limit = SiteSetting.invites_per_page)
|
|
|
|
Invite.multiple_use_invites
|
|
|
|
.includes(invited_groups: :group)
|
|
|
|
.where(invited_by_id: inviter.id)
|
|
|
|
.order('invites.updated_at DESC')
|
|
|
|
.limit(limit)
|
|
|
|
.offset(offset)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.find_links_invites_from(inviter, offset = 0)
|
|
|
|
find_all_links_invites_from(inviter, offset)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.find_links_invites_count(inviter)
|
|
|
|
find_all_links_invites_from(inviter, 0, nil).reorder(nil).count
|
2015-08-25 03:03:25 +08:00
|
|
|
end
|
|
|
|
|
2013-11-09 03:11:41 +08:00
|
|
|
def self.filter_by(email_or_username)
|
|
|
|
if email_or_username
|
|
|
|
where(
|
|
|
|
'(LOWER(invites.email) LIKE :filter) or (LOWER(users.username) LIKE :filter)',
|
|
|
|
filter: "%#{email_or_username.downcase}%"
|
|
|
|
)
|
|
|
|
else
|
2014-02-18 00:44:28 +08:00
|
|
|
all
|
2013-11-09 03:11:41 +08:00
|
|
|
end
|
|
|
|
end
|
2014-01-22 05:53:46 +08:00
|
|
|
|
|
|
|
def self.invalidate_for_email(email)
|
2014-05-06 21:41:59 +08:00
|
|
|
i = Invite.find_by(email: Email.downcase(email))
|
2014-01-22 05:53:46 +08:00
|
|
|
if i
|
|
|
|
i.invalidated_at = Time.zone.now
|
|
|
|
i.save
|
|
|
|
end
|
|
|
|
i
|
|
|
|
end
|
2014-05-28 04:14:37 +08:00
|
|
|
|
2014-07-04 04:06:49 +08:00
|
|
|
def self.redeem_from_email(email)
|
2020-06-09 23:19:32 +08:00
|
|
|
invite = Invite.single_use_invites.find_by(email: Email.downcase(email))
|
|
|
|
InviteRedeemer.new(invite: invite, email: invite.email).redeem if invite
|
2014-07-04 04:06:49 +08:00
|
|
|
invite
|
|
|
|
end
|
|
|
|
|
2014-10-07 02:48:56 +08:00
|
|
|
def resend_invite
|
2020-10-26 18:26:43 +08:00
|
|
|
self.update_columns(updated_at: Time.zone.now, invalidated_at: nil, expires_at: SiteSetting.invite_expiry_days.days.from_now)
|
2014-10-07 02:48:56 +08:00
|
|
|
Jobs.enqueue(:invite_email, invite_id: self.id)
|
|
|
|
end
|
|
|
|
|
2016-06-03 03:09:02 +08:00
|
|
|
def self.resend_all_invites_from(user_id)
|
2020-06-09 23:19:32 +08:00
|
|
|
Invite.single_use_invites
|
2020-07-08 18:19:46 +08:00
|
|
|
.left_outer_joins(:invited_users)
|
2020-06-09 23:19:32 +08:00
|
|
|
.where('invited_users.user_id IS NULL AND invites.email IS NOT NULL AND invited_by_id = ?', user_id)
|
2020-07-08 18:19:46 +08:00
|
|
|
.group('invites.id')
|
2020-06-09 23:19:32 +08:00
|
|
|
.find_each do |invite|
|
2017-07-02 00:20:34 +08:00
|
|
|
invite.resend_invite
|
2016-06-03 03:09:02 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-07 17:49:46 +08:00
|
|
|
def self.rescind_all_expired_invites_from(user)
|
2020-06-09 23:19:32 +08:00
|
|
|
Invite.single_use_invites
|
|
|
|
.includes(:invited_users)
|
|
|
|
.where('invited_users.user_id IS NULL AND invites.email IS NOT NULL AND invited_by_id = ? AND invites.expires_at < ?',
|
|
|
|
user.id, Time.zone.now)
|
|
|
|
.references('invited_users')
|
|
|
|
.find_each do |invite|
|
2017-07-02 00:20:34 +08:00
|
|
|
invite.trash!(user)
|
2017-06-29 22:32:07 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-20 02:50:01 +08:00
|
|
|
def limit_invites_per_day
|
2015-02-11 14:45:46 +08:00
|
|
|
RateLimiter.new(invited_by, "invites-per-day", SiteSetting.max_invites_per_day, 1.day.to_i)
|
2015-01-20 02:50:01 +08:00
|
|
|
end
|
|
|
|
|
2014-05-28 04:14:37 +08:00
|
|
|
def self.base_directory
|
2014-11-26 00:55:09 +08:00
|
|
|
File.join(Rails.root, "public", "uploads", "csv", RailsMultisite::ConnectionManagement.current_db)
|
2014-05-28 04:14:37 +08:00
|
|
|
end
|
2020-06-09 23:19:32 +08:00
|
|
|
|
|
|
|
def ensure_max_redemptions_allowed
|
|
|
|
if self.max_redemptions_allowed.nil? || self.max_redemptions_allowed == 1
|
|
|
|
self.max_redemptions_allowed ||= 1
|
|
|
|
else
|
|
|
|
if !self.max_redemptions_allowed.between?(2, SiteSetting.invite_link_max_redemptions_limit)
|
|
|
|
errors.add(:max_redemptions_allowed, I18n.t("invite_link.max_redemptions_limit", max_limit: SiteSetting.invite_link_max_redemptions_limit))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-02-04 02:01:23 +08:00
|
|
|
|
|
|
|
def ensure_no_invalid_email_invites
|
|
|
|
return if email.blank?
|
|
|
|
|
|
|
|
if SiteSetting.enable_sso?
|
2021-02-08 18:04:33 +08:00
|
|
|
errors.add(:email, I18n.t("invite.disabled_errors.discourse_connect_enabled"))
|
2021-02-04 02:01:23 +08:00
|
|
|
elsif !SiteSetting.enable_local_logins?
|
|
|
|
errors.add(:email, I18n.t("invite.disabled_errors.local_logins_disabled"))
|
|
|
|
end
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2013-05-24 10:48:32 +08:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: invites
|
|
|
|
#
|
2020-06-09 23:19:32 +08:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# invite_key :string(32) not null
|
|
|
|
# email :string
|
|
|
|
# invited_by_id :integer not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# deleted_at :datetime
|
|
|
|
# deleted_by_id :integer
|
|
|
|
# invalidated_at :datetime
|
|
|
|
# moderator :boolean default(FALSE), not null
|
|
|
|
# custom_message :text
|
|
|
|
# emailed_status :integer
|
|
|
|
# max_redemptions_allowed :integer default(1), not null
|
|
|
|
# redemption_count :integer default(0), not null
|
|
|
|
# expires_at :datetime not null
|
2013-05-24 10:48:32 +08:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
2014-07-30 01:57:08 +08:00
|
|
|
# index_invites_on_email_and_invited_by_id (email,invited_by_id)
|
2019-07-19 13:59:12 +08:00
|
|
|
# index_invites_on_emailed_status (emailed_status)
|
2013-05-24 10:48:32 +08:00
|
|
|
# index_invites_on_invite_key (invite_key) UNIQUE
|
2019-12-30 14:13:27 +08:00
|
|
|
# index_invites_on_invited_by_id (invited_by_id)
|
2013-05-24 10:48:32 +08:00
|
|
|
#
|