forked from External/greenlight
Added the ability to invite multiple users at once (#778)
This commit is contained in:
parent
843d42a1d8
commit
201a394813
|
@ -90,17 +90,19 @@ class AdminsController < ApplicationController
|
|||
|
||||
# POST /admins/invite
|
||||
def invite
|
||||
email = params[:invite_user][:email]
|
||||
emails = params[:invite_user][:email].split(",")
|
||||
|
||||
begin
|
||||
invitation = create_or_update_invite(email)
|
||||
emails.each do |email|
|
||||
invitation = create_or_update_invite(email)
|
||||
|
||||
send_invitation_email(current_user.name, email, invitation.invite_token)
|
||||
send_invitation_email(current_user.name, email, invitation.invite_token)
|
||||
end
|
||||
rescue => e
|
||||
logger.error "Support: Error in email delivery: #{e}"
|
||||
flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error"))
|
||||
else
|
||||
flash[:success] = I18n.t("administrator.flash.invite", email: email)
|
||||
flash[:success] = I18n.t("administrator.flash.invite", email: emails.join(', '))
|
||||
end
|
||||
|
||||
redirect_to admins_path
|
||||
|
|
|
@ -316,7 +316,7 @@ en:
|
|||
warning: You will <b>not</b> be able to recover this room
|
||||
recording_warning: or any of its %{recordings_num} associated recordings.
|
||||
invite_user:
|
||||
email_placeholder: Enter the user's email
|
||||
email_placeholder: Enter the users' emails (seperated by commas)
|
||||
footer: The user will receive an email with instructions on how to sign up
|
||||
send: Send Invite
|
||||
title: Invite User
|
||||
|
|
|
@ -114,6 +114,35 @@ describe AdminsController, type: :controller do
|
|||
params = { invite_user: { email: email } }
|
||||
expect { post :invite, params: params }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
|
||||
it "invites multiple users" do
|
||||
@request.session[:user_id] = @admin.id
|
||||
email = "#{Faker::Internet.email},#{Faker::Internet.email},#{Faker::Internet.email},#{Faker::Internet.email}"
|
||||
post :invite, params: { invite_user: { email: email } }
|
||||
|
||||
invite = Invitation.find_by(email: email.split(",")[0], provider: "provider1")
|
||||
expect(invite.present?).to eq(true)
|
||||
|
||||
invite1 = Invitation.find_by(email: email.split(",")[1], provider: "provider1")
|
||||
expect(invite1.present?).to eq(true)
|
||||
|
||||
invite2 = Invitation.find_by(email: email.split(",")[2], provider: "provider1")
|
||||
expect(invite2.present?).to eq(true)
|
||||
|
||||
invite3 = Invitation.find_by(email: email.split(",")[3], provider: "provider1")
|
||||
expect(invite3.present?).to eq(true)
|
||||
|
||||
expect(flash[:success]).to be_present
|
||||
expect(response).to redirect_to(admins_path)
|
||||
end
|
||||
|
||||
it "sends multiple invitation emails" do
|
||||
@request.session[:user_id] = @admin.id
|
||||
email = "#{Faker::Internet.email},#{Faker::Internet.email},#{Faker::Internet.email},#{Faker::Internet.email}"
|
||||
|
||||
params = { invite_user: { email: email } }
|
||||
expect { post :invite, params: params }.to change { ActionMailer::Base.deliveries.count }.by(4)
|
||||
end
|
||||
end
|
||||
|
||||
context "POST #approve" do
|
||||
|
|
Loading…
Reference in New Issue