FEATURE: Invite admin api has an optional param send_email which can prevent sending an email to the invited user. The api will return the password reset url so that the caller can send an email with it instead.

This commit is contained in:
Neil Lalonde 2015-01-02 15:48:34 -05:00
parent 7182767349
commit 4c166942ad
2 changed files with 14 additions and 2 deletions

View File

@ -320,12 +320,15 @@ class Admin::UsersController < Admin::AdminController
user.email_tokens.update_all confirmed: true
email_token = user.email_tokens.create(email: user.email)
Jobs.enqueue(:user_email,
unless params[:send_email] == '0' || params[:send_email] == 'false'
Jobs.enqueue( :user_email,
type: :account_created,
user_id: user.id,
email_token: email_token.token)
end
render json: success_json
render json: success_json.merge!(password_url: "#{Discourse.base_url}/users/password-reset/#{email_token.token}")
end

View File

@ -460,6 +460,7 @@ describe Admin::UsersController do
context ".invite_admin" do
it 'should invite admin' do
Jobs.expects(:enqueue).with(:user_email, anything).returns(true)
xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com'
response.should be_success
@ -468,6 +469,14 @@ describe Admin::UsersController do
u.username.should == "bill22"
u.admin.should == true
end
it "doesn't send the email with send_email falsy" do
Jobs.expects(:enqueue).with(:user_email, anything).never
xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com', send_email: '0'
response.should be_success
json = ::JSON.parse(response.body)
json["password_url"].should be_present
end
end
end