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.

Move oAuth admin UI to legacy_api_v2 gem

Damian Legawieca2bf45b64073
diff --git a/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb b/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb
index 88dc4fab3d..298347ecdf 100644
--- a/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb
+++ b/admin/app/views/spree/admin/shared/sidebar/_store_nav.html.erb
@@ -65,7 +65,7 @@
<% end %>
<% end %>
- <% if can?(:manage, Spree::OauthApplication) %>
+ <% if defined?(Spree::OauthApplication) && can?(:manage, Spree::OauthApplication) %>
<%= nav_item(Spree.t(:developers), spree.admin_oauth_applications_path, icon: 'terminal', active: %w[oauth_applications webhooks_subscribers].include?(controller_name)) %>
<% end %>
diff --git a/admin/config/routes.rb b/admin/config/routes.rb
index f00c3ba7a1..48b63e502c 100644
--- a/admin/config/routes.rb
+++ b/admin/config/routes.rb
@@ -266,7 +266,6 @@ Spree::Core::Engine.add_routes do
end
# developer tools
- resources :oauth_applications
resources :api_keys, except: :destroy do
member do
put :revoke
diff --git a/admin/spec/features/spree/admin/settings/api_keys_spec.rb b/admin/spec/features/spree/admin/settings/api_keys_spec.rb
deleted file mode 100644
index 424892a4f5..0000000000
--- a/admin/spec/features/spree/admin/settings/api_keys_spec.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-require 'spec_helper'
-
-describe 'API keys', type: :feature do
- stub_authorization!
-
- let!(:oauth_application) { create(:oauth_application, name: 'Test app') }
-
- it 'renders a list of applications' do
- visit '/admin/oauth_applications'
-
- expect(page).to have_content('Test app')
- end
-
- it 'can create a new app', js: true do
- visit '/admin/oauth_applications/new'
-
- fill_in 'Name', with: 'My app'
- select 'Read & Write', from: 'Scopes'
- click_button 'Create'
-
- expect(page).to have_content('Client ID')
- expect(page).to have_content('Client Secret')
-
- oauth_application = Spree::OauthApplication.last
- expect(page).to have_field('Client ID', with: oauth_application.uid, readonly: true)
- end
-
- it 'can modify existing app' do
- visit "/admin/oauth_applications/#{oauth_application.id}/edit"
-
- fill_in 'Name', with: 'New name'
- within('#page-header') { click_button 'Update' }
-
- expect(page).to have_content('successfully updated!')
- expect(page).to have_content('New name')
- end
-end
diff --git a/docs/developer/admin/extending-ui.mdx b/docs/developer/admin/extending-ui.mdx
index eb60676300..cdecc50ed0 100644
--- a/docs/developer/admin/extending-ui.mdx
+++ b/docs/developer/admin/extending-ui.mdx
@@ -780,32 +780,6 @@ Here's a list of all places you can inject your custom code:
</Accordion>
</AccordionGroup>
-### OAuth Applications
-
-<AccordionGroup>
- <Accordion title="OAuth Applications Actions">
- `oauth_applications_actions`
-
- Injects code into the page actions area for the OAuth applications list page.
-
- ```erb
- <%= link_to "Security Audit", oauth_security_audit_path, class: "btn btn-secondary" %>
- ```
- </Accordion>
-
- <Accordion title="OAuth Applications Header">
- `oauth_applications_header`
-
- Injects code between the page header and the main content area for the OAuth applications list page.
-
- ```erb
- <div class="alert alert-warning">
- <strong>Security:</strong> Review OAuth applications regularly.
- </div>
- ```
- </Accordion>
-</AccordionGroup>
-
### Option Types
<AccordionGroup>
diff --git a/admin/app/controllers/spree/admin/oauth_applications_controller.rb b/legacy_api_v2/app/controllers/spree/admin/oauth_applications_controller.rb
similarity index 100%
rename from admin/app/controllers/spree/admin/oauth_applications_controller.rb
rename to legacy_api_v2/app/controllers/spree/admin/oauth_applications_controller.rb
diff --git a/admin/app/views/spree/admin/oauth_applications/_form.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/_form.html.erb
similarity index 100%
rename from admin/app/views/spree/admin/oauth_applications/_form.html.erb
rename to legacy_api_v2/app/views/spree/admin/oauth_applications/_form.html.erb
diff --git a/admin/app/views/spree/admin/oauth_applications/_table_header.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/_table_header.html.erb
similarity index 100%
rename from admin/app/views/spree/admin/oauth_applications/_table_header.html.erb
rename to legacy_api_v2/app/views/spree/admin/oauth_applications/_table_header.html.erb
diff --git a/admin/app/views/spree/admin/oauth_applications/_table_row.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/_table_row.html.erb
similarity index 100%
rename from admin/app/views/spree/admin/oauth_applications/_table_row.html.erb
rename to legacy_api_v2/app/views/spree/admin/oauth_applications/_table_row.html.erb
diff --git a/admin/app/views/spree/admin/oauth_applications/create.turbo_stream.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/create.turbo_stream.erb
similarity index 100%
rename from admin/app/views/spree/admin/oauth_applications/create.turbo_stream.erb
rename to legacy_api_v2/app/views/spree/admin/oauth_applications/create.turbo_stream.erb
diff --git a/admin/app/views/spree/admin/oauth_applications/edit.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/edit.html.erb
similarity index 100%
rename from admin/app/views/spree/admin/oauth_applications/edit.html.erb
rename to legacy_api_v2/app/views/spree/admin/oauth_applications/edit.html.erb
diff --git a/admin/app/views/spree/admin/oauth_applications/index.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/index.html.erb
similarity index 100%
rename from admin/app/views/spree/admin/oauth_applications/index.html.erb
rename to legacy_api_v2/app/views/spree/admin/oauth_applications/index.html.erb
diff --git a/admin/app/views/spree/admin/oauth_applications/new.html.erb b/legacy_api_v2/app/views/spree/admin/oauth_applications/new.html.erb
similarity index 100%
rename from admin/app/views/spree/admin/oauth_applications/new.html.erb
rename to legacy_api_v2/app/views/spree/admin/oauth_applications/new.html.erb
diff --git a/legacy_api_v2/config/routes.rb b/legacy_api_v2/config/routes.rb
index 62e0e9a356..927b48c4da 100644
--- a/legacy_api_v2/config/routes.rb
+++ b/legacy_api_v2/config/routes.rb
@@ -7,6 +7,11 @@ Rails.application.routes.draw do
end
Spree::Core::Engine.add_routes do
+ # Admin UI to manage OAuth applications
+ namespace :admin do
+ resources :oauth_applications
+ end
+
namespace :api, defaults: { format: 'json' } do
namespace :v2 do
namespace :storefront do
diff --git a/admin/spec/controllers/spree/admin/oauth_applications_controller_spec.rb b/legacy_api_v2/spec/controllers/spree/admin/oauth_applications_controller_spec.rb
similarity index 100%
rename from admin/spec/controllers/spree/admin/oauth_applications_controller_spec.rb
rename to legacy_api_v2/spec/controllers/spree/admin/oauth_applications_controller_spec.rb