The personal finance app for everyone (by everyone)
Ruby
fix(impersonation): guard Sidekiq jobs link (#2678)
Sure Admin (bot)7554463f938e
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 369cb9df91..324d96b550 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -149,6 +149,11 @@ module ApplicationHelpercookies[:admin] == "true"end+ def sidekiq_web_available?+ named_routes = Rails.application.routes.named_routes+ named_routes.route_defined?(:sidekiq_web_path) || named_routes.route_defined?(:sidekiq_web_url)+ end+def assistant_icontype = ENV["ASSISTANT_TYPE"].presence || Current.family&.assistant_type.presence || "builtin"type == "external" ? "claw" : "ai"diff --git a/app/views/impersonation_sessions/_super_admin_bar.html.erb b/app/views/impersonation_sessions/_super_admin_bar.html.erbindex 718471b674..a401e3871e 100644--- a/app/views/impersonation_sessions/_super_admin_bar.html.erb+++ b/app/views/impersonation_sessions/_super_admin_bar.html.erb@@ -3,9 +3,11 @@<%= icon "alert-triangle", size: "lg", color: "current", class: "mr-2" %><span class="text-inverse font-semibold uppercase"><%= t(".super_admin") %></span></div>- <div>- <%= link_to t(".jobs"), sidekiq_web_url, class: "text-white underline hover:text-gray-100" %>- </div>+ <% if sidekiq_web_available? %>+ <div>+ <%= link_to t(".jobs"), sidekiq_web_url, class: "text-inverse underline hover:text-subdued" %>+ </div>+ <% end %><div class="flex items-center space-x-2 px-2 py-2 text-white"><% if Current.session.active_impersonator_session.present? %>diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rbindex 434735449c..e4ea15064d 100644--- a/test/helpers/application_helper_test.rb+++ b/test/helpers/application_helper_test.rb@@ -44,6 +44,42 @@ class ApplicationHelperTest < ActionView::TestCaseassert_equal "Test Header Title", content_for(:header_title)end+ test "#sidekiq_web_available? returns true when the route is mounted" do+ named_routes = Struct.new(:defined) do+ def route_defined?(name)+ defined.fetch(name)+ end+ end++ Rails.application.routes.stub(:named_routes, named_routes.new({ sidekiq_web_path: true })) do+ assert sidekiq_web_available?+ end+ end++ test "#sidekiq_web_available? returns false when the route is unavailable" do+ named_routes = Struct.new(:defined) do+ def route_defined?(name)+ defined.fetch(name, false)+ end+ end++ Rails.application.routes.stub(:named_routes, named_routes.new({})) do+ assert_not sidekiq_web_available?+ end+ end++ test "#sidekiq_web_available? returns true when only the url helper is defined" do+ named_routes = Struct.new(:defined) do+ def route_defined?(name)+ defined.fetch(name, false)+ end+ end++ Rails.application.routes.stub(:named_routes, named_routes.new({ sidekiq_web_url: true })) do+ assert sidekiq_web_available?+ end+ end+def setup@account1 = Account.new(currency: "USD", balance: 1)@account2 = Account.new(currency: "USD", balance: 2)