Merge pull request #3568 from techAPJ/patch-1

FIX: mark user as approved if an invite is already present
This commit is contained in:
Robin Ward 2015-06-25 17:12:23 -04:00
commit 2eb551e10a
3 changed files with 37 additions and 3 deletions

View File

@ -60,7 +60,7 @@ class EmailToken < ActiveRecord::Base
end end
end end
# redeem invite, if available # redeem invite, if available
Invite.redeem_from_email(user.email) return User.find_by(email: Email.downcase(user.email)) if Invite.redeem_from_email(user.email).present?
user user
rescue ActiveRecord::RecordInvalid rescue ActiveRecord::RecordInvalid
# If the user's email is already taken, just return nil (failure) # If the user's email is already taken, just return nil (failure)

View File

@ -23,7 +23,8 @@ class UserActivator
end end
def factory def factory
if SiteSetting.must_approve_users? invite = Invite.find_by(email: Email.downcase(@user.email))
if SiteSetting.must_approve_users? && !(invite.present? && !invite.expired? && !invite.destroyed? && invite.link_valid?)
ApprovalActivator ApprovalActivator
elsif !user.active? elsif !user.active?
EmailActivator EmailActivator

View File

@ -130,7 +130,40 @@ describe EmailToken do
expect(EmailToken.confirm(email_token.token)).to be_blank expect(EmailToken.confirm(email_token.token)).to be_blank
end end
end end
context 'confirms the token and redeems invite' do
before do
SiteSetting.must_approve_users = true
end
let(:invite) { Fabricate(:invite, email: 'test@example.com', user_id: nil) }
let(:invited_user) { Fabricate(:user, active: false, email: invite.email) }
let(:user_email_token) { invited_user.email_tokens.first }
let!(:confirmed_invited_user) { EmailToken.confirm(user_email_token.token) }
it "returns the correct user" do
expect(confirmed_invited_user).to eq invited_user
end
it 'marks the user as active' do
confirmed_invited_user.reload
expect(confirmed_invited_user).to be_active
end
it 'marks the token as confirmed' do
user_email_token.reload
expect(user_email_token).to be_confirmed
end
it 'redeems invite' do
invite.reload
expect(invite).to be_redeemed
end
it 'marks the user as approved' do
expect(confirmed_invited_user).to be_approved
end
end
end end
end end