mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +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)
|
||||
|
||||
unless params[:send_email] == '0' || params[:send_email] == 'false'
|
||||
Jobs.enqueue( :user_email,
|
||||
Jobs.enqueue( :critical_user_email,
|
||||
type: :account_created,
|
||||
user_id: user.id,
|
||||
email_token: email_token.token)
|
||||
|
|
|
@ -204,7 +204,7 @@ class SessionController < ApplicationController
|
|||
user_presence = user.present? && user.id != Discourse::SYSTEM_USER_ID && !user.staged
|
||||
if user_presence
|
||||
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
|
||||
|
||||
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
|
||||
if user
|
||||
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")
|
||||
else
|
||||
@message = I18n.t("admin_login.error")
|
||||
|
@ -516,7 +516,7 @@ class UsersController < ApplicationController
|
|||
|
||||
def enqueue_activation_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
|
||||
|
||||
def search_users
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
require_dependency "#{Rails.root}/app/jobs/regular/user_email.rb"
|
||||
|
||||
module Jobs
|
||||
class ForgotPassword < UserEmail
|
||||
class CriticalUserEmail < UserEmail
|
||||
|
||||
sidekiq_options queue: 'critical'
|
||||
|
||||
def execute(args)
|
||||
args[:type] = :forgot_password
|
||||
super(args)
|
||||
end
|
||||
end
|
|
@ -929,7 +929,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
def send_approval_email
|
||||
if SiteSetting.must_approve_users
|
||||
Jobs.enqueue(:user_email,
|
||||
Jobs.enqueue(:critical_user_email,
|
||||
type: :signup_after_approval,
|
||||
user_id: id,
|
||||
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.create(email: user.email) if email_token.nil?
|
||||
|
||||
Jobs.enqueue(:user_email,
|
||||
Jobs.enqueue(:critical_user_email,
|
||||
type: :signup,
|
||||
user_id: user.id,
|
||||
email_token: email_token.token
|
||||
|
|
|
@ -100,14 +100,14 @@ class EmailUpdater
|
|||
protected
|
||||
|
||||
def notify_old(old_email, new_email)
|
||||
Jobs.enqueue :user_email,
|
||||
Jobs.enqueue :critical_user_email,
|
||||
to_address: old_email,
|
||||
type: :notify_old_email,
|
||||
user_id: @user.id
|
||||
end
|
||||
|
||||
def send_email(type, email_token)
|
||||
Jobs.enqueue :user_email,
|
||||
Jobs.enqueue :critical_user_email,
|
||||
to_address: email_token.email,
|
||||
type: type,
|
||||
user_id: @user.id,
|
||||
|
|
|
@ -21,7 +21,7 @@ describe EmailUpdater do
|
|||
let(:updater) { EmailUpdater.new(user.guardian, user) }
|
||||
|
||||
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)
|
||||
@change_req = user.email_change_requests.first
|
||||
end
|
||||
|
@ -48,7 +48,7 @@ describe EmailUpdater do
|
|||
|
||||
context 'confirming a valid token' 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)
|
||||
expect(updater.errors).to be_blank
|
||||
expect(user.reload.email).to eq(new_email)
|
||||
|
@ -65,7 +65,7 @@ describe EmailUpdater do
|
|||
let(:updater) { EmailUpdater.new(user.guardian, user) }
|
||||
|
||||
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)
|
||||
@change_req = user.email_change_requests.first
|
||||
end
|
||||
|
@ -92,7 +92,7 @@ describe EmailUpdater do
|
|||
|
||||
context 'confirming a valid token' 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)
|
||||
@change_req.reload
|
||||
end
|
||||
|
@ -117,7 +117,7 @@ describe EmailUpdater do
|
|||
|
||||
context "completing the new update process" 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)
|
||||
end
|
||||
|
||||
|
|
|
@ -486,7 +486,7 @@ describe Admin::UsersController do
|
|||
|
||||
context ".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'
|
||||
expect(response).to be_success
|
||||
|
||||
|
|
|
@ -210,7 +210,7 @@ describe SessionController do
|
|||
end
|
||||
|
||||
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.external_id = '666' # the number of the beast
|
||||
sso.email = 'bob@bob.com'
|
||||
|
@ -632,7 +632,7 @@ describe SessionController do
|
|||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -321,7 +321,7 @@ describe UsersController do
|
|||
|
||||
context 'enqueues mail' 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
|
||||
end
|
||||
end
|
||||
|
@ -417,7 +417,7 @@ describe UsersController do
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
post_user
|
||||
|
@ -1297,7 +1297,7 @@ describe UsersController do
|
|||
|
||||
context 'with a valid email_token' 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
|
||||
end
|
||||
end
|
||||
|
@ -1315,7 +1315,7 @@ describe UsersController do
|
|||
end
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,7 +47,7 @@ describe User do
|
|||
it "enqueues a 'signup after approval' email if must_approve_users is true" do
|
||||
SiteSetting.stubs(:must_approve_users).returns(true)
|
||||
Jobs.expects(:enqueue).with(
|
||||
:user_email, has_entries(type: :signup_after_approval)
|
||||
:critical_user_email, has_entries(type: :signup_after_approval)
|
||||
)
|
||||
user.approve(admin)
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ describe UserActivator do
|
|||
user = Fabricate(:user)
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -20,8 +20,8 @@ describe UserActivator do
|
|||
email_token.update_column(:created_at, 48.hours.ago)
|
||||
activator = EmailActivator.new(user, nil, nil, nil)
|
||||
|
||||
Jobs.expects(:enqueue).with(: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))
|
||||
Jobs.expects(:enqueue).with(:critical_user_email, has_entries(type: :signup, email_token: email_token.token)).never
|
||||
activator.activate
|
||||
|
||||
user.reload
|
||||
|
|
Loading…
Reference in New Issue
Block a user