From de656ace98657c76bdb7bcf16848085f601563de Mon Sep 17 00:00:00 2001 From: Andrew White Date: Thu, 23 May 2024 07:35:45 +0100 Subject: [PATCH 1/2] Remove the current_user method from Delayed::Web The method already exists from the Devise helpers and is public. --- config/initializers/delayed_web.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/initializers/delayed_web.rb b/config/initializers/delayed_web.rb index d0ace5844..ec58ef646 100644 --- a/config/initializers/delayed_web.rb +++ b/config/initializers/delayed_web.rb @@ -18,10 +18,6 @@ def admin_login_url main_app.admin_login_url end - def current_user - @current_user ||= warden.authenticate(scope: :user) - end - def require_admin unless current_user redirect_to admin_login_url, alert: :admin_required From 2704d1c324dc0ee2faa50bbf512ed6228e747ed8 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Thu, 23 May 2024 08:04:23 +0100 Subject: [PATCH 2/2] Capture job not found errors and redirect --- config/initializers/delayed_web.rb | 4 ++++ config/locales/delayed_web.en-GB.yml | 2 ++ 2 files changed, 6 insertions(+) diff --git a/config/initializers/delayed_web.rb b/config/initializers/delayed_web.rb index ec58ef646..9150860a1 100644 --- a/config/initializers/delayed_web.rb +++ b/config/initializers/delayed_web.rb @@ -6,6 +6,10 @@ Delayed::Web::ApplicationController.class_eval do include FlashI18n + rescue_from ActiveRecord::RecordNotFound do + redirect_to root_url, notice: t(:notice, scope: 'delayed/web.flashes.jobs.not_found') + end + before_action :require_admin def admin_request? diff --git a/config/locales/delayed_web.en-GB.yml b/config/locales/delayed_web.en-GB.yml index d00192284..50d43dba4 100644 --- a/config/locales/delayed_web.en-GB.yml +++ b/config/locales/delayed_web.en-GB.yml @@ -34,3 +34,5 @@ en-GB: destroyed: alert: 'Job cannot be deleted because it is already %{status}' notice: 'Job destroyed' + not_found: + notice: 'Job not found'