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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fix: took the custom field parent from the route only
Damian Legawiecaddcb39a69e5
diff --git a/spree/api/app/controllers/spree/api/v3/admin/custom_fields_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/custom_fields_controller.rbindex aa59fedc44..b0dc78955d 100644--- a/spree/api/app/controllers/spree/api/v3/admin/custom_fields_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/custom_fields_controller.rb@@ -109,17 +109,22 @@ module Spreeend.merge('customer' => Spree.customer_class.name, 'category' => 'Spree::Category')end- # Returns the first segment whose `<segment>_id` is present in params,+ # Returns the first segment whose `<segment>_id` is in the route,# paired with its class and the raw id value, or nil. Memoized — read# by both `set_parent` and `scoped_resource_name`.+ #+ # Read from the path only: a `store_id` or `refund_id` added to the+ # query string or body must not switch the parent to a type that is+ # never routed here and has no store scope to narrow it.def parent_lookupreturn @parent_lookup if defined?(@parent_lookup)- match = parent_route_map.find { |segment, _| params[:"#{segment}_id"].present? }+ route_params = request.path_parameters+ match = parent_route_map.find { |segment, _| route_params[:"#{segment}_id"].present? }@parent_lookup =if matchsegment, klass_name = match- ParentLookup.new(klass_name.constantize, params[:"#{segment}_id"], segment)+ ParentLookup.new(klass_name.constantize, route_params[:"#{segment}_id"], segment)endendenddiff --git a/spree/api/spec/controllers/spree/api/v3/admin/custom_fields_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/custom_fields_controller_spec.rbindex 4bc5b227cb..ea9d454f09 100644--- a/spree/api/spec/controllers/spree/api/v3/admin/custom_fields_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/admin/custom_fields_controller_spec.rb@@ -207,6 +207,25 @@ RSpec.describe Spree::Api::V3::Admin::CustomFieldsController, type: :controllerendend+ # The parent comes from the route: a `store_id` in the query string must not+ # switch it to a store, which has no store scope to narrow it.+ describe 'a parent named outside the route' do+ let(:category) { create(:category) }+ let(:category_definition) { create(:custom_field_definition, :short_text_field, resource_type: 'Spree::Category') }++ it 'keeps the routed parent' do+ post :create,+ params: {+ category_id: category.prefixed_id, store_id: create(:store).prefixed_id,+ custom_field_definition_id: category_definition.prefixed_id, value: 'summer'+ },+ as: :json++ expect(response).to have_http_status(:created)+ expect(category.custom_fields.pluck(:value)).to eq(['summer'])+ end+ end+describe 'API key scope enforcement' dolet(:api_key) { create(:api_key, :secret, store: store, scopes: [granted_scope]) }let(:api_key_headers) { { 'x-spree-api-key' => api_key.plaintext_token } }