Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Generate Admin Logout link if available

Damian Legawiec070113fa6068
diff --git a/backend/app/helpers/spree/admin/base_helper.rb b/backend/app/helpers/spree/admin/base_helper.rb
index 5633f90d08..ace0bd9e20 100644
--- a/backend/app/helpers/spree/admin/base_helper.rb
+++ b/backend/app/helpers/spree/admin/base_helper.rb
@@ -201,6 +201,14 @@ module Spree
class: 'btn-outline-secondary', icon: 'view.svg', id: 'admin_preview_taxon', target: :blank
)
end
+
+ def admin_logout_link
+ if defined?(admin_logout_path)
+ admin_logout_path
+ elsif defined?(spree_logout_path)
+ spree_logout_path
+ end
+ end
end
end
end
diff --git a/backend/app/views/spree/admin/shared/_account_nav.html.erb b/backend/app/views/spree/admin/shared/_account_nav.html.erb
index a0ed4478e1..6ca180bbba 100644
--- a/backend/app/views/spree/admin/shared/_account_nav.html.erb
+++ b/backend/app/views/spree/admin/shared/_account_nav.html.erb
@@ -27,8 +27,8 @@
<% end %>
<% end %>
- <% if defined?(spree_logout_path) %>
- <%= link_to spree_logout_path, class: 'd-block text-dark py-3 px-4 dropdown-item' do %>
+ <% if admin_logout_link %>
+ <%= link_to admin_logout_link, class: 'd-block text-dark py-3 px-4 dropdown-item' do %>
<%= svg_icon name: "exit.svg", width: '18', height: '18' %>
&nbsp;
<%= Spree.t(:logout) %>
diff --git a/backend/spec/helpers/spree/admin/base_helper_spec.rb b/backend/spec/helpers/spree/admin/base_helper_spec.rb
index 1cab0ac100..2719dc3d10 100644
--- a/backend/spec/helpers/spree/admin/base_helper_spec.rb
+++ b/backend/spec/helpers/spree/admin/base_helper_spec.rb
@@ -32,4 +32,25 @@ describe Spree::Admin::BaseHelper, type: :helper do
expect(order_time(nil)).to eq ''
end
end
+
+ describe '#admin_logout_link' do
+ it 'returns nil if no logout route is defined' do
+ expect(helper.admin_logout_link).to be_nil
+ end
+
+ context 'returns spree_logout_path if defined' do
+ before { allow(helper).to receive(:spree_logout_path).and_return('/logout') }
+
+ it { expect(helper.admin_logout_link).to eq('/logout') }
+ end
+
+ context 'spree.admin_logout_path if defined' do
+ before do
+ allow(helper).to receive(:spree_logout_path).and_return('/logout')
+ allow(helper).to receive(:admin_logout_path).and_return('/admin/logout')
+ end
+
+ it { expect(helper.admin_logout_link).to eq('/admin/logout') }
+ end
+ end
end