diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 8197b89a456..e62999fe019 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -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 diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 31271da27c6..5ad68e9bb31 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -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