spree_api 5.6.0.rc4 → 5.6.0.rc5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca50a0fac8c0d346157c3d42a2969414d5f4e8a392aae87176cb02069c828e21
4
- data.tar.gz: dc56eff71e891ef304710a9a2f2bfc7c72be17a50d0a24ba1335b137ea817057
3
+ metadata.gz: eee15468ad97bc5af5ed27d4e0ed4f4149c8b325efe81d9ef05d91af84094a27
4
+ data.tar.gz: c5d97420fb0bf65903f944487e102a57f957babdb7119dc2406307c0d45b2634
5
5
  SHA512:
6
- metadata.gz: e1097d160a66eac8cee1e1b9169f06781c4105ddb01fce2bf560bcf0c94aeb7e0f947bd36675e17e7b6532af02c47999d242f23fb8359abaa866d3257775afd0
7
- data.tar.gz: a48b3317819fd03b05d71b016a7856b5c1a8da5d238080964dd9980b0eef328f2a712aed8a903efffde9a86ee1c902903495aee339d01e4a5e216fae0886ffb7
6
+ metadata.gz: e7783e8de7f1681b747863d5f9d161e1c5b8d05e1c087b5454332868fa81caaf7900e421fb60dabcca24b1d8ffbb99abf68338b0e85f13d6f456708e8c35e40f
7
+ data.tar.gz: 30aad9e4cc778ae8d11b1527053cf1f96f4fc75846ee48422152939a050a2506537824c1ffbeafc0b53dd8bd7c9c927ff39f5014ef462b9581c2f66a177d6ee7
@@ -86,10 +86,15 @@ module Spree
86
86
  self.class._scoped_resource
87
87
  end
88
88
 
89
- # Override in controllers with non-REST custom actions (e.g. dashboard
90
- # `analytics` should map to a read).
89
+ # Maps the action to the scope kind. Consults the controller's
90
+ # `read_actions` (ResourceController's overridable list) when defined,
91
+ # so declaring a custom read-only action once — e.g. `types` — fixes
92
+ # both the CanCanCan action mapping and the required scope kind.
93
+ # Controllers outside the ResourceController hierarchy can still
94
+ # override `action_kind` directly (e.g. dashboard `analytics`).
91
95
  def action_kind
92
- READ_ACTIONS.include?(action_name) ? 'read' : 'write'
96
+ read = respond_to?(:read_actions, true) ? read_actions : READ_ACTIONS
97
+ read.include?(action_name) ? 'read' : 'write'
93
98
  end
94
99
 
95
100
  # True when authorization derives from the API key's scopes rather
@@ -0,0 +1,65 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ module Admin
5
+ # CRUD for `Spree::OrderRoutingRule` STI subclasses, nested under the
6
+ # owning channel. Same shape as PromotionRulesController — the registry
7
+ # is `Spree.order_routing.rules` and the parent is a Channel.
8
+ class OrderRoutingRulesController < ResourceController
9
+ include Spree::Api::V3::Admin::SubclassedResource
10
+
11
+ scoped_resource :settings
12
+
13
+ subclassed_via -> { Spree.order_routing.rules },
14
+ unknown_type_error: 'unknown_order_routing_rule_type'
15
+
16
+ def types
17
+ authorize! :read, model_class
18
+
19
+ render json: { data: model_class.subclasses_with_preference_schema }
20
+ end
21
+
22
+ protected
23
+
24
+ def model_class
25
+ Spree::OrderRoutingRule
26
+ end
27
+
28
+ def serializer_class
29
+ Spree.api.admin_order_routing_rule_serializer
30
+ end
31
+
32
+ def permitted_params
33
+ params.permit(:type, :active, :position, preferences: {})
34
+ end
35
+
36
+ # `types` is read-only discovery — maps to the read scope + :show ability.
37
+ def read_actions
38
+ super + %w[types]
39
+ end
40
+
41
+ def scope
42
+ super.ordered
43
+ end
44
+
45
+ def set_parent
46
+ return if action_name == 'types'
47
+
48
+ @parent = current_store.channels.accessible_by(current_ability, parent_ability_action)
49
+ .find_by_prefix_id!(params[:channel_id])
50
+ end
51
+
52
+ def parent_association
53
+ :order_routing_rules
54
+ end
55
+
56
+ private
57
+
58
+ def build_subclassed_resource(klass, attrs)
59
+ klass.new(attrs.merge(channel: @parent, store: @parent.store))
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -51,6 +51,11 @@ module Spree
51
51
  params.permit(:name, :description, :active, :storefront_visible, :auto_capture, :position, metadata: {}, preferences: {})
52
52
  end
53
53
 
54
+ # `types` is read-only discovery — maps to the read scope + :show ability.
55
+ def read_actions
56
+ super + %w[types]
57
+ end
58
+
54
59
  private
55
60
 
56
61
  # New payment methods are created through the current store.
@@ -55,6 +55,11 @@ module Spree
55
55
  params.permit(:type, preferences: {})
56
56
  end
57
57
 
58
+ # `types`/`calculators` are read-only discovery — read scope + :show ability.
59
+ def read_actions
60
+ super + %w[types calculators]
61
+ end
62
+
58
63
  def set_parent
59
64
  return if %w[types calculators].include?(action_name)
60
65
 
@@ -33,6 +33,11 @@ module Spree
33
33
  params.permit(:type, preferences: {})
34
34
  end
35
35
 
36
+ # `types` is read-only discovery — maps to the read scope + :show ability.
37
+ def read_actions
38
+ super + %w[types]
39
+ end
40
+
36
41
  def set_parent
37
42
  return if action_name == 'types'
38
43
 
@@ -42,6 +42,7 @@ module Spree
42
42
  :preferred_storefront_access,
43
43
  :preferred_storefront_url,
44
44
  :preferred_guest_checkout,
45
+ :preferred_order_routing_strategy,
45
46
  :mail_from_address,
46
47
  :customer_support_email,
47
48
  :new_order_notifications_email,
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Api
5
+ module V3
6
+ module Admin
7
+ # Serializes Spree::OrderRoutingRule (and its STI subclasses) for the
8
+ # per-channel routing-rules editor. Same shape as PromotionRule so the
9
+ # frontend renders both with the same schema-driven preference form.
10
+ class OrderRoutingRuleSerializer < BaseSerializer
11
+ typelize type: :string,
12
+ channel_id: :string,
13
+ position: :number,
14
+ active: :boolean,
15
+ preferences: 'Record<string, unknown>',
16
+ preference_schema: "Array<{ key: string; type: string; default: unknown }>",
17
+ label: :string,
18
+ description: :string
19
+
20
+ attributes :position, :active
21
+ attributes created_at: :iso8601, updated_at: :iso8601
22
+
23
+ attribute :type do |rule|
24
+ rule.class.api_type
25
+ end
26
+
27
+ attribute :channel_id do |rule|
28
+ rule.channel&.prefixed_id
29
+ end
30
+
31
+ attribute :preferences, &:serialized_preferences
32
+ attribute :preference_schema, &:serialized_preference_schema
33
+
34
+ attribute :label, &:human_name
35
+ attribute :description, &:human_description
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -21,6 +21,7 @@ module Spree
21
21
  preferred_unit_system: :string,
22
22
  preferred_storefront_access: :string,
23
23
  preferred_guest_checkout: :boolean,
24
+ preferred_order_routing_strategy: :string,
24
25
  metadata: 'Record<string, unknown>'
25
26
 
26
27
  attributes :metadata,
@@ -39,6 +40,7 @@ module Spree
39
40
  :preferred_unit_system,
40
41
  :preferred_storefront_access,
41
42
  :preferred_guest_checkout,
43
+ :preferred_order_routing_strategy,
42
44
  created_at: :iso8601, updated_at: :iso8601
43
45
 
44
46
  attribute :url, &:storefront_url
data/config/routes.rb CHANGED
@@ -345,8 +345,15 @@ Spree::Core::Engine.add_routes do
345
345
  post :add_products
346
346
  post :remove_products
347
347
  end
348
+
349
+ resources :order_routing_rules, only: [:index, :show, :create, :update, :destroy]
348
350
  end
349
351
 
352
+ # Subclass discovery for the routing-rules editor, mirroring
353
+ # `/promotion_rules/types`. Top-level so the SPA can build the
354
+ # "Add rule" picker without a parent channel.
355
+ get 'order_routing_rules/types', to: 'order_routing_rules#types'
356
+
350
357
  # Variants (top-level, for search/autocomplete across all products)
351
358
  resources :variants, only: [:index, :show], concerns: :custom_fieldable
352
359
 
@@ -202,6 +202,7 @@ module Spree
202
202
  admin_admin_user_serializer: 'Spree::Api::V3::Admin::AdminUserSerializer',
203
203
  admin_address_serializer: 'Spree::Api::V3::Admin::AddressSerializer',
204
204
  admin_channel_serializer: 'Spree::Api::V3::Admin::ChannelSerializer',
205
+ admin_order_routing_rule_serializer: 'Spree::Api::V3::Admin::OrderRoutingRuleSerializer',
205
206
  admin_product_publication_serializer: 'Spree::Api::V3::Admin::ProductPublicationSerializer',
206
207
  admin_market_serializer: 'Spree::Api::V3::Admin::MarketSerializer',
207
208
  admin_shipping_method_serializer: 'Spree::Api::V3::Admin::DeliveryMethodSerializer',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.6.0.rc4
4
+ version: 5.6.0.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vendo Connect Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-07-20 00:00:00.000000000 Z
11
+ date: 2026-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rswag-specs
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 5.6.0.rc4
75
+ version: 5.6.0.rc5
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 5.6.0.rc4
82
+ version: 5.6.0.rc5
83
83
  description: Spree's API
84
84
  email:
85
85
  - hello@spreecommerce.org
@@ -142,6 +142,7 @@ files:
142
142
  - app/controllers/spree/api/v3/admin/me_controller.rb
143
143
  - app/controllers/spree/api/v3/admin/media_controller.rb
144
144
  - app/controllers/spree/api/v3/admin/option_types_controller.rb
145
+ - app/controllers/spree/api/v3/admin/order_routing_rules_controller.rb
145
146
  - app/controllers/spree/api/v3/admin/orders/adjustments_controller.rb
146
147
  - app/controllers/spree/api/v3/admin/orders/base_controller.rb
147
148
  - app/controllers/spree/api/v3/admin/orders/fulfillments_controller.rb
@@ -252,6 +253,7 @@ files:
252
253
  - app/serializers/spree/api/v3/admin/newsletter_subscriber_serializer.rb
253
254
  - app/serializers/spree/api/v3/admin/option_type_serializer.rb
254
255
  - app/serializers/spree/api/v3/admin/option_value_serializer.rb
256
+ - app/serializers/spree/api/v3/admin/order_routing_rule_serializer.rb
255
257
  - app/serializers/spree/api/v3/admin/order_serializer.rb
256
258
  - app/serializers/spree/api/v3/admin/payment_method_serializer.rb
257
259
  - app/serializers/spree/api/v3/admin/payment_serializer.rb
@@ -382,9 +384,9 @@ licenses:
382
384
  - BSD-3-Clause
383
385
  metadata:
384
386
  bug_tracker_uri: https://github.com/spree/spree/issues
385
- changelog_uri: https://github.com/spree/spree/releases/tag/v5.6.0.rc4
387
+ changelog_uri: https://github.com/spree/spree/releases/tag/v5.6.0.rc5
386
388
  documentation_uri: https://docs.spreecommerce.org/
387
- source_code_uri: https://github.com/spree/spree/tree/v5.6.0.rc4
389
+ source_code_uri: https://github.com/spree/spree/tree/v5.6.0.rc5
388
390
  post_install_message:
389
391
  rdoc_options: []
390
392
  require_paths: