FIX: enqueue activation email for invited user that has password set

This commit is contained in:
Arpit Jalan 2017-03-17 01:10:14 +05:30
parent 1d4993a185
commit 521c88fe58
3 changed files with 11 additions and 1 deletions

View File

@ -62,6 +62,7 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password) do
send_welcome_message
notify_invitee
send_password_instructions
enqueue_activation_mail
delete_duplicate_invites
end
@ -126,6 +127,13 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password) do
end
end
def enqueue_activation_mail
if invited_user.has_password?
email_token = invited_user.email_tokens.create(email: invited_user.email)
Jobs.enqueue(:critical_user_email, type: :signup, user_id: invited_user.id, email_token: email_token.token)
end
end
def notify_invitee
if inviter = invite.invited_by
inviter.notifications.create(notification_type: Notification.types[:invitee_accepted],

View File

@ -81,7 +81,7 @@ module Email
topic = Topic.find_by(id: topic_id)
first_post = topic.ordered_posts.first
topic_message_id = first_post.incoming_email&.message_id.present? ?
topic_message_id = first_post.incoming_email&.message_id.present? ?
"<#{first_post.incoming_email.message_id}>" :
"<topic/#{topic_id}@#{host}>"

View File

@ -43,6 +43,7 @@ describe InviteRedeemer do
SiteSetting.must_approve_users = true
inviter = invite.invited_by
inviter.admin = true
Jobs.expects(:enqueue).with(:invite_password_instructions_email, has_entries(username: username))
user = invite_redeemer.redeem
expect(user.name).to eq(name)
@ -88,6 +89,7 @@ describe InviteRedeemer do
it "can set password" do
inviter = invite.invited_by
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup))
user = InviteRedeemer.new(invite, username, name, password).redeem
expect(user).to have_password
expect(user.confirm_password?(password)).to eq(true)