mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 05:13:39 +08:00
FEATURE: move more urgent emails notifications to critical queue
Move signup, admin login and password change email notifications to critical queue
This commit is contained in:
parent
2ecff60af2
commit
a130cb8305
|
@ -336,7 +336,7 @@ class Admin::UsersController < Admin::AdminController
|
||||||
email_token = user.email_tokens.create(email: user.email)
|
email_token = user.email_tokens.create(email: user.email)
|
||||||
|
|
||||||
unless params[:send_email] == '0' || params[:send_email] == 'false'
|
unless params[:send_email] == '0' || params[:send_email] == 'false'
|
||||||
Jobs.enqueue( :user_email,
|
Jobs.enqueue( :critical_user_email,
|
||||||
type: :account_created,
|
type: :account_created,
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
email_token: email_token.token)
|
email_token: email_token.token)
|
||||||
|
|
|
@ -204,7 +204,7 @@ class SessionController < ApplicationController
|
||||||
user_presence = user.present? && user.id != Discourse::SYSTEM_USER_ID && !user.staged
|
user_presence = user.present? && user.id != Discourse::SYSTEM_USER_ID && !user.staged
|
||||||
if user_presence
|
if user_presence
|
||||||
email_token = user.email_tokens.create(email: user.email)
|
email_token = user.email_tokens.create(email: user.email)
|
||||||
Jobs.enqueue(:forgot_password, user_id: user.id, email_token: email_token.token)
|
Jobs.enqueue(:critical_user_email, type: :forgot_password, user_id: user.id, email_token: email_token.token)
|
||||||
end
|
end
|
||||||
|
|
||||||
json = { result: "ok" }
|
json = { result: "ok" }
|
||||||
|
|
|
@ -431,7 +431,7 @@ class UsersController < ApplicationController
|
||||||
user = User.where(email: params[:email], admin: true).where.not(id: Discourse::SYSTEM_USER_ID).first
|
user = User.where(email: params[:email], admin: true).where.not(id: Discourse::SYSTEM_USER_ID).first
|
||||||
if user
|
if user
|
||||||
email_token = user.email_tokens.create(email: user.email)
|
email_token = user.email_tokens.create(email: user.email)
|
||||||
Jobs.enqueue(:user_email, type: :admin_login, user_id: user.id, email_token: email_token.token)
|
Jobs.enqueue(:critical_user_email, type: :admin_login, user_id: user.id, email_token: email_token.token)
|
||||||
@message = I18n.t("admin_login.success")
|
@message = I18n.t("admin_login.success")
|
||||||
else
|
else
|
||||||
@message = I18n.t("admin_login.error")
|
@message = I18n.t("admin_login.error")
|
||||||
|
@ -516,7 +516,7 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
def enqueue_activation_email
|
def enqueue_activation_email
|
||||||
@email_token ||= @user.email_tokens.create(email: @user.email)
|
@email_token ||= @user.email_tokens.create(email: @user.email)
|
||||||
Jobs.enqueue(:user_email, type: :signup, user_id: @user.id, email_token: @email_token.token)
|
Jobs.enqueue(:critical_user_email, type: :signup, user_id: @user.id, email_token: @email_token.token)
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_users
|
def search_users
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
require_dependency "#{Rails.root}/app/jobs/regular/user_email.rb"
|
require_dependency "#{Rails.root}/app/jobs/regular/user_email.rb"
|
||||||
|
|
||||||
module Jobs
|
module Jobs
|
||||||
class ForgotPassword < UserEmail
|
class CriticalUserEmail < UserEmail
|
||||||
|
|
||||||
sidekiq_options queue: 'critical'
|
sidekiq_options queue: 'critical'
|
||||||
|
|
||||||
def execute(args)
|
def execute(args)
|
||||||
args[:type] = :forgot_password
|
|
||||||
super(args)
|
super(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -929,7 +929,7 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
def send_approval_email
|
def send_approval_email
|
||||||
if SiteSetting.must_approve_users
|
if SiteSetting.must_approve_users
|
||||||
Jobs.enqueue(:user_email,
|
Jobs.enqueue(:critical_user_email,
|
||||||
type: :signup_after_approval,
|
type: :signup_after_approval,
|
||||||
user_id: id,
|
user_id: id,
|
||||||
email_token: email_tokens.first.token
|
email_token: email_tokens.first.token
|
||||||
|
|
|
@ -46,7 +46,7 @@ class EmailActivator < UserActivator
|
||||||
email_token = user.email_tokens.unconfirmed.active.first
|
email_token = user.email_tokens.unconfirmed.active.first
|
||||||
email_token = user.email_tokens.create(email: user.email) if email_token.nil?
|
email_token = user.email_tokens.create(email: user.email) if email_token.nil?
|
||||||
|
|
||||||
Jobs.enqueue(:user_email,
|
Jobs.enqueue(:critical_user_email,
|
||||||
type: :signup,
|
type: :signup,
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
email_token: email_token.token
|
email_token: email_token.token
|
||||||
|
|
|
@ -100,14 +100,14 @@ class EmailUpdater
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def notify_old(old_email, new_email)
|
def notify_old(old_email, new_email)
|
||||||
Jobs.enqueue :user_email,
|
Jobs.enqueue :critical_user_email,
|
||||||
to_address: old_email,
|
to_address: old_email,
|
||||||
type: :notify_old_email,
|
type: :notify_old_email,
|
||||||
user_id: @user.id
|
user_id: @user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_email(type, email_token)
|
def send_email(type, email_token)
|
||||||
Jobs.enqueue :user_email,
|
Jobs.enqueue :critical_user_email,
|
||||||
to_address: email_token.email,
|
to_address: email_token.email,
|
||||||
type: type,
|
type: type,
|
||||||
user_id: @user.id,
|
user_id: @user.id,
|
||||||
|
|
|
@ -21,7 +21,7 @@ describe EmailUpdater do
|
||||||
let(:updater) { EmailUpdater.new(user.guardian, user) }
|
let(:updater) { EmailUpdater.new(user.guardian, user) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Jobs.expects(:enqueue).once.with(:user_email, has_entries(type: :confirm_new_email, to_address: new_email))
|
Jobs.expects(:enqueue).once.with(:critical_user_email, has_entries(type: :confirm_new_email, to_address: new_email))
|
||||||
updater.change_to(new_email)
|
updater.change_to(new_email)
|
||||||
@change_req = user.email_change_requests.first
|
@change_req = user.email_change_requests.first
|
||||||
end
|
end
|
||||||
|
@ -48,7 +48,7 @@ describe EmailUpdater do
|
||||||
|
|
||||||
context 'confirming a valid token' do
|
context 'confirming a valid token' do
|
||||||
it "updates the user's email" do
|
it "updates the user's email" do
|
||||||
Jobs.expects(:enqueue).once.with(:user_email, has_entries(type: :notify_old_email, to_address: old_email))
|
Jobs.expects(:enqueue).once.with(:critical_user_email, has_entries(type: :notify_old_email, to_address: old_email))
|
||||||
updater.confirm(@change_req.new_email_token.token)
|
updater.confirm(@change_req.new_email_token.token)
|
||||||
expect(updater.errors).to be_blank
|
expect(updater.errors).to be_blank
|
||||||
expect(user.reload.email).to eq(new_email)
|
expect(user.reload.email).to eq(new_email)
|
||||||
|
@ -65,7 +65,7 @@ describe EmailUpdater do
|
||||||
let(:updater) { EmailUpdater.new(user.guardian, user) }
|
let(:updater) { EmailUpdater.new(user.guardian, user) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Jobs.expects(:enqueue).once.with(:user_email, has_entries(type: :confirm_old_email, to_address: old_email))
|
Jobs.expects(:enqueue).once.with(:critical_user_email, has_entries(type: :confirm_old_email, to_address: old_email))
|
||||||
updater.change_to(new_email)
|
updater.change_to(new_email)
|
||||||
@change_req = user.email_change_requests.first
|
@change_req = user.email_change_requests.first
|
||||||
end
|
end
|
||||||
|
@ -92,7 +92,7 @@ describe EmailUpdater do
|
||||||
|
|
||||||
context 'confirming a valid token' do
|
context 'confirming a valid token' do
|
||||||
before do
|
before do
|
||||||
Jobs.expects(:enqueue).once.with(:user_email, has_entries(type: :confirm_new_email, to_address: new_email))
|
Jobs.expects(:enqueue).once.with(:critical_user_email, has_entries(type: :confirm_new_email, to_address: new_email))
|
||||||
updater.confirm(@change_req.old_email_token.token)
|
updater.confirm(@change_req.old_email_token.token)
|
||||||
@change_req.reload
|
@change_req.reload
|
||||||
end
|
end
|
||||||
|
@ -117,7 +117,7 @@ describe EmailUpdater do
|
||||||
|
|
||||||
context "completing the new update process" do
|
context "completing the new update process" do
|
||||||
before do
|
before do
|
||||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :notify_old_email, to_address: old_email)).never
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :notify_old_email, to_address: old_email)).never
|
||||||
updater.confirm(@change_req.new_email_token.token)
|
updater.confirm(@change_req.new_email_token.token)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -486,7 +486,7 @@ describe Admin::UsersController do
|
||||||
|
|
||||||
context ".invite_admin" do
|
context ".invite_admin" do
|
||||||
it 'should invite admin' do
|
it 'should invite admin' do
|
||||||
Jobs.expects(:enqueue).with(:user_email, anything).returns(true)
|
Jobs.expects(:enqueue).with(:critical_user_email, anything).returns(true)
|
||||||
xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com'
|
xhr :post, :invite_admin, name: 'Bill', username: 'bill22', email: 'bill@bill.com'
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ describe SessionController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sends an activation email' do
|
it 'sends an activation email' do
|
||||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :signup))
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup))
|
||||||
sso = get_sso('/a/')
|
sso = get_sso('/a/')
|
||||||
sso.external_id = '666' # the number of the beast
|
sso.external_id = '666' # the number of the beast
|
||||||
sso.email = 'bob@bob.com'
|
sso.email = 'bob@bob.com'
|
||||||
|
@ -632,7 +632,7 @@ describe SessionController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "enqueues an email" do
|
it "enqueues an email" do
|
||||||
Jobs.expects(:enqueue).with(:forgot_password, has_entries(user_id: user.id))
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :forgot_password, user_id: user.id))
|
||||||
xhr :post, :forgot_password, login: user.username
|
xhr :post, :forgot_password, login: user.username
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -321,7 +321,7 @@ describe UsersController do
|
||||||
|
|
||||||
context 'enqueues mail' do
|
context 'enqueues mail' do
|
||||||
it 'enqueues mail with admin email and sso enabled' do
|
it 'enqueues mail with admin email and sso enabled' do
|
||||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :admin_login, user_id: admin.id))
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :admin_login, user_id: admin.id))
|
||||||
put :admin_login, email: admin.email
|
put :admin_login, email: admin.email
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -417,7 +417,7 @@ describe UsersController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a user correctly' do
|
it 'creates a user correctly' do
|
||||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :signup))
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup))
|
||||||
User.any_instance.expects(:enqueue_welcome_message).with('welcome_user').never
|
User.any_instance.expects(:enqueue_welcome_message).with('welcome_user').never
|
||||||
|
|
||||||
post_user
|
post_user
|
||||||
|
@ -1297,7 +1297,7 @@ describe UsersController do
|
||||||
|
|
||||||
context 'with a valid email_token' do
|
context 'with a valid email_token' do
|
||||||
it 'should send the activation email' do
|
it 'should send the activation email' do
|
||||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :signup))
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup))
|
||||||
xhr :post, :send_activation_email, username: user.username
|
xhr :post, :send_activation_email, username: user.username
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1315,7 +1315,7 @@ describe UsersController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should send an email' do
|
it 'should send an email' do
|
||||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :signup))
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup))
|
||||||
xhr :post, :send_activation_email, username: user.username
|
xhr :post, :send_activation_email, username: user.username
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,7 +47,7 @@ describe User do
|
||||||
it "enqueues a 'signup after approval' email if must_approve_users is true" do
|
it "enqueues a 'signup after approval' email if must_approve_users is true" do
|
||||||
SiteSetting.stubs(:must_approve_users).returns(true)
|
SiteSetting.stubs(:must_approve_users).returns(true)
|
||||||
Jobs.expects(:enqueue).with(
|
Jobs.expects(:enqueue).with(
|
||||||
:user_email, has_entries(type: :signup_after_approval)
|
:critical_user_email, has_entries(type: :signup_after_approval)
|
||||||
)
|
)
|
||||||
user.approve(admin)
|
user.approve(admin)
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe UserActivator do
|
||||||
user = Fabricate(:user)
|
user = Fabricate(:user)
|
||||||
activator = EmailActivator.new(user, nil, nil, nil)
|
activator = EmailActivator.new(user, nil, nil, nil)
|
||||||
|
|
||||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :signup, email_token: user.email_tokens.first.token))
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup, email_token: user.email_tokens.first.token))
|
||||||
activator.activate
|
activator.activate
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ describe UserActivator do
|
||||||
email_token.update_column(:created_at, 48.hours.ago)
|
email_token.update_column(:created_at, 48.hours.ago)
|
||||||
activator = EmailActivator.new(user, nil, nil, nil)
|
activator = EmailActivator.new(user, nil, nil, nil)
|
||||||
|
|
||||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :signup))
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup))
|
||||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :signup, email_token: email_token.token)).never
|
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup, email_token: email_token.token)).never
|
||||||
activator.activate
|
activator.activate
|
||||||
|
|
||||||
user.reload
|
user.reload
|
||||||
|
|
Loading…
Reference in New Issue
Block a user