mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Merge pull request #2501 from techAPJ/bulk-invite-5
FEATURE: redeem Invite when user sign up
This commit is contained in:
commit
ee3f7362e6
4 changed files with 34 additions and 0 deletions
|
@ -57,6 +57,8 @@ class EmailToken < ActiveRecord::Base
|
|||
user.save!
|
||||
end
|
||||
end
|
||||
# redeem invite, if available
|
||||
Invite.redeem_from_email(user.email)
|
||||
user
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
# If the user's email is already taken, just return nil (failure)
|
||||
|
|
|
@ -130,6 +130,14 @@ class Invite < ActiveRecord::Base
|
|||
i
|
||||
end
|
||||
|
||||
def self.redeem_from_email(email)
|
||||
invite = Invite.find_by(email: Email.downcase(email))
|
||||
if invite
|
||||
InviteRedeemer.new(invite).redeem
|
||||
end
|
||||
invite
|
||||
end
|
||||
|
||||
def self.base_directory
|
||||
File.join(Rails.root, "public", "csv", RailsMultisite::ConnectionManagement.current_db)
|
||||
end
|
||||
|
|
|
@ -19,6 +19,10 @@ InviteRedeemer = Struct.new(:invite) do
|
|||
|
||||
# extracted from User cause it is very specific to invites
|
||||
def self.create_user_from_invite(invite)
|
||||
|
||||
user_exists = User.find_by_email(invite.email)
|
||||
return user if user_exists
|
||||
|
||||
username = UserNameSuggester.suggest(invite.email)
|
||||
|
||||
DiscourseHub.username_operation do
|
||||
|
|
|
@ -349,4 +349,24 @@ describe Invite do
|
|||
result.should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe '.redeem_from_email' do
|
||||
let(:inviter) { Fabricate(:user) }
|
||||
let(:invite) { Fabricate(:invite, invited_by: inviter, email: 'test@example.com', user_id: nil) }
|
||||
let(:user) { Fabricate(:user, email: invite.email) }
|
||||
|
||||
it 'redeems the invite from email' do
|
||||
result = Invite.redeem_from_email(user.email)
|
||||
invite.reload
|
||||
invite.should be_redeemed
|
||||
end
|
||||
|
||||
it 'does not redeem the invite if email does not match' do
|
||||
result = Invite.redeem_from_email('test24@example.com')
|
||||
invite.reload
|
||||
invite.should_not be_redeemed
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue