From c3a54eb30fe034bda39e02aeda6b46b6d91e725d Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 4 Feb 2022 17:34:38 +0000 Subject: [PATCH] DEV: Use strings for :user_email job type argument Job arguments go via JSON, and so symbols will appear as strings in the Job's `#execute` method. The latest version of Sidekiq has started warning about this to reduce developer confusion. --- app/controllers/session_controller.rb | 2 +- app/controllers/users_controller.rb | 6 +++--- app/jobs/regular/suspicious_login.rb | 2 +- app/jobs/scheduled/enqueue_digest_emails.rb | 2 +- lib/email_updater.rb | 2 +- lib/tasks/admin.rake | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb index d24e3e9e03c..62264baa602 100644 --- a/app/controllers/session_controller.rb +++ b/app/controllers/session_controller.rb @@ -444,7 +444,7 @@ class SessionController < ApplicationController if user RateLimiter.new(nil, "forgot-password-login-day-#{user.username}", 6, 1.day).performed! email_token = user.email_tokens.create!(email: user.email, scope: EmailToken.scopes[:password_reset]) - Jobs.enqueue(:critical_user_email, type: :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) else RateLimiter.new(nil, "forgot-password-login-hour-#{normalized_login_param}", 5, 1.hour).performed! end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 25355a42600..b99ff91232c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -737,7 +737,7 @@ class UsersController < ApplicationController session["user_created_message"] = activation.success_message if existing_user = User.find_by_email(user.primary_email&.email) - Jobs.enqueue(:critical_user_email, type: :account_exists, user_id: existing_user.id) + Jobs.enqueue(:critical_user_email, type: "account_exists", user_id: existing_user.id) end render json: { @@ -932,7 +932,7 @@ class UsersController < ApplicationController if user = User.with_email(params[:email]).admins.human_users.first email_token = user.email_tokens.create!(email: user.email, scope: EmailToken.scopes[:email_login]) - Jobs.enqueue(:critical_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.errors.unknown_email_address") @@ -967,7 +967,7 @@ class UsersController < ApplicationController email_token = user.email_tokens.create!(email: user.email, scope: EmailToken.scopes[:email_login]) Jobs.enqueue(:critical_user_email, - type: :email_login, + type: "email_login", user_id: user.id, email_token: email_token.token ) diff --git a/app/jobs/regular/suspicious_login.rb b/app/jobs/regular/suspicious_login.rb index 2c08776c5d0..a45b820de01 100644 --- a/app/jobs/regular/suspicious_login.rb +++ b/app/jobs/regular/suspicious_login.rb @@ -13,7 +13,7 @@ module Jobs client_ip: args[:client_ip]) ::Jobs.enqueue(:critical_user_email, - type: :suspicious_login, + type: "suspicious_login", user_id: args[:user_id], client_ip: args[:client_ip], user_agent: args[:user_agent]) diff --git a/app/jobs/scheduled/enqueue_digest_emails.rb b/app/jobs/scheduled/enqueue_digest_emails.rb index 4496f2548b9..e76a60d97eb 100644 --- a/app/jobs/scheduled/enqueue_digest_emails.rb +++ b/app/jobs/scheduled/enqueue_digest_emails.rb @@ -10,7 +10,7 @@ module Jobs users = target_user_ids users.each do |user_id| - ::Jobs.enqueue(:user_email, type: :digest, user_id: user_id) + ::Jobs.enqueue(:user_email, type: "digest", user_id: user_id) end end diff --git a/lib/email_updater.rb b/lib/email_updater.rb index f5e41fc8127..08cd8ebd832 100644 --- a/lib/email_updater.rb +++ b/lib/email_updater.rb @@ -24,7 +24,7 @@ class EmailUpdater if existing_user = User.find_by_email(email) if SiteSetting.hide_email_address_taken - Jobs.enqueue(:critical_user_email, type: :account_exists, user_id: existing_user.id) + Jobs.enqueue(:critical_user_email, type: "account_exists", user_id: existing_user.id) else error_message = +'change_email.error' error_message << '_staged' if existing_user.staged? diff --git a/lib/tasks/admin.rake b/lib/tasks/admin.rake index 104b0429164..37ef651f2b0 100644 --- a/lib/tasks/admin.rake +++ b/lib/tasks/admin.rake @@ -28,7 +28,7 @@ task "admin:invite", [:email] => [:environment] do |_, args| puts "Sending email!" email_token = user.email_tokens.create!(email: user.email, scope: EmailToken.scopes[:password_reset]) - Jobs.enqueue(:user_email, type: :account_created, user_id: user.id, email_token: email_token.token) + Jobs.enqueue(:user_email, type: "account_created", user_id: user.id, email_token: email_token.token) end desc "Creates a forum administrator"