FIX: inviting a user again after the first invite expires will create a new invite
This commit is contained in:
parent
e2c361f353
commit
1dbc1c56b4
|
@ -41,6 +41,9 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<td>{{unbound email}}</td>
|
<td>{{unbound email}}</td>
|
||||||
<td colspan='6'>
|
<td colspan='6'>
|
||||||
|
{{#if expired}}
|
||||||
|
{{i18n user.invited.expired}}
|
||||||
|
{{/if}}
|
||||||
{{#if rescinded}}
|
{{#if rescinded}}
|
||||||
{{i18n user.invited.rescinded}}
|
{{i18n user.invited.rescinded}}
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
|
@ -50,7 +50,15 @@ class Invite < ActiveRecord::Base
|
||||||
# Return the previously existing invite if already exists. Returns nil if the invite can't be created.
|
# Return the previously existing invite if already exists. Returns nil if the invite can't be created.
|
||||||
def self.invite_by_email(email, invited_by, topic=nil)
|
def self.invite_by_email(email, invited_by, topic=nil)
|
||||||
lower_email = Email.downcase(email)
|
lower_email = Email.downcase(email)
|
||||||
invite = Invite.with_deleted.where('invited_by_id = ? and email = ?', invited_by.id, lower_email).first
|
invite = Invite.with_deleted
|
||||||
|
.where('invited_by_id = ? and email = ?', invited_by.id, lower_email)
|
||||||
|
.order('created_at DESC')
|
||||||
|
.first
|
||||||
|
|
||||||
|
if invite && invite.expired?
|
||||||
|
invite.destroy
|
||||||
|
invite = nil
|
||||||
|
end
|
||||||
|
|
||||||
if invite.blank?
|
if invite.blank?
|
||||||
invite = Invite.create(invited_by: invited_by, email: lower_email)
|
invite = Invite.create(invited_by: invited_by, email: lower_email)
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
class InviteSerializer < ApplicationSerializer
|
class InviteSerializer < ApplicationSerializer
|
||||||
|
|
||||||
attributes :email, :created_at, :redeemed_at
|
attributes :email, :created_at, :redeemed_at, :expired
|
||||||
has_one :user, embed: :objects, serializer: InvitedUserSerializer
|
has_one :user, embed: :objects, serializer: InvitedUserSerializer
|
||||||
|
|
||||||
def include_email?
|
def include_email?
|
||||||
!object.redeemed?
|
!object.redeemed?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expired
|
||||||
|
object.expired?
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -356,6 +356,7 @@ en:
|
||||||
pending: "Pending Invites"
|
pending: "Pending Invites"
|
||||||
topics_entered: "Topics Viewed"
|
topics_entered: "Topics Viewed"
|
||||||
posts_read_count: "Posts Read"
|
posts_read_count: "Posts Read"
|
||||||
|
expired: "This invite has expired."
|
||||||
rescind: "Remove Invitation"
|
rescind: "Remove Invitation"
|
||||||
rescinded: "Invite removed"
|
rescinded: "Invite removed"
|
||||||
time_read: "Read Time"
|
time_read: "Read Time"
|
||||||
|
|
|
@ -100,6 +100,15 @@ describe Invite do
|
||||||
it 'matches case sensitively for the local part' do
|
it 'matches case sensitively for the local part' do
|
||||||
topic.invite_by_email(inviter, 'ICEKING@adventuretime.ooo').should_not == @invite
|
topic.invite_by_email(inviter, 'ICEKING@adventuretime.ooo').should_not == @invite
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns a new invite if the other has expired' do
|
||||||
|
SiteSetting.stubs(:invite_expiry_days).returns(1)
|
||||||
|
@invite.created_at = 2.days.ago
|
||||||
|
@invite.save
|
||||||
|
new_invite = topic.invite_by_email(inviter, 'iceking@adventuretime.ooo')
|
||||||
|
new_invite.should_not == @invite
|
||||||
|
new_invite.should_not be_expired
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when adding to another topic' do
|
context 'when adding to another topic' do
|
||||||
|
|
Loading…
Reference in New Issue