spree_core 6.0.2 → 6.0.4
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 +4 -4
- data/app/jobs/spree/addresses/geocode_address_job.rb +6 -3
- data/app/jobs/spree/payments/handle_webhook_job.rb +12 -1
- data/app/jobs/spree/variants/remove_line_item_job.rb +5 -0
- data/app/models/concerns/spree/has_custom_fields.rb +4 -1
- data/app/models/concerns/spree/personal_data_matching.rb +5 -1
- data/app/models/concerns/spree/preference_schema.rb +5 -0
- data/app/models/concerns/spree/product_scopes.rb +2 -2
- data/app/models/concerns/spree/publishable.rb +26 -3
- data/app/models/concerns/spree/typed_associations.rb +53 -20
- data/app/models/spree/address.rb +2 -2
- data/app/models/spree/authentication/strategies/base_strategy.rb +10 -1
- data/app/models/spree/cart.rb +7 -2
- data/app/models/spree/collection.rb +7 -2
- data/app/models/spree/invitation.rb +6 -2
- data/app/models/spree/media.rb +25 -1
- data/app/models/spree/order.rb +6 -2
- data/app/models/spree/price.rb +3 -0
- data/app/models/spree/product.rb +21 -14
- data/app/models/spree/product_category.rb +7 -1
- data/app/models/spree/product_collection.rb +8 -1
- data/app/models/spree/promotion.rb +1 -2
- data/app/models/spree/seller.rb +93 -10
- data/app/models/spree/seller_requirements/complete_profile.rb +26 -7
- data/app/models/spree/stock_level.rb +30 -1
- data/app/models/spree/stock_movement.rb +1 -0
- data/app/services/spree/carts/destroy.rb +22 -6
- data/app/services/spree/collections/regenerate_products.rb +37 -15
- data/app/services/spree/companies/add_member.rb +9 -4
- data/app/services/spree/diagnostics/error_log.rb +139 -0
- data/app/services/spree/diagnostics/section.rb +72 -0
- data/app/services/spree/diagnostics/sections.rb +121 -0
- data/app/services/spree/diagnostics/stack.rb +73 -0
- data/app/services/spree/diagnostics.rb +132 -0
- data/app/services/spree/newsletter/subscribe.rb +8 -4
- data/app/services/spree/orders/create_from_cart.rb +6 -2
- data/app/services/spree/orders/remove_line_item.rb +16 -5
- data/app/services/spree/product_memberships.rb +21 -1
- data/app/services/spree/product_types/apply_to_products.rb +12 -2
- data/app/services/spree/products/auto_match_collections.rb +20 -4
- data/app/services/spree/stock_reservations/reserve.rb +9 -6
- data/app/services/spree/store_credits/apply.rb +9 -1
- data/app/services/spree/update_check.rb +7 -31
- data/app/tools/spree/agent_tools/create_export.rb +3 -1
- data/app/tools/spree/agent_tools/create_import.rb +1 -0
- data/app/tools/spree/agent_tools/create_media.rb +2 -1
- data/app/tools/spree/agent_tools/create_resource.rb +12 -4
- data/app/tools/spree/agent_tools/delete_resource.rb +12 -4
- data/app/tools/spree/agent_tools/describe_resource.rb +72 -6
- data/app/tools/spree/agent_tools/get_resource.rb +8 -5
- data/app/tools/spree/agent_tools/resource_write.rb +16 -3
- data/app/tools/spree/agent_tools/search_resources.rb +51 -20
- data/app/tools/spree/agent_tools/update_resource.rb +6 -6
- data/app/tools/spree/agent_tools/upload_file.rb +1 -0
- data/app/workflows/spree/carts/add_item.rb +51 -0
- data/app/workflows/spree/carts/complete.rb +18 -3
- data/app/workflows/spree/carts/merge.rb +25 -4
- data/app/workflows/spree/orders/complete.rb +39 -14
- data/app/workflows/spree/payments/handle_webhook.rb +7 -3
- data/app/workflows/spree/products/activate.rb +7 -2
- data/app/workflows/spree/products/archive.rb +7 -2
- data/app/workflows/spree/products/draft.rb +7 -2
- data/app/workflows/spree/products/status_transition.rb +24 -0
- data/app/workflows/spree/sellers/approve.rb +6 -0
- data/app/workflows/spree/sellers/create.rb +5 -2
- data/app/workflows/spree/stock_levels/bulk_upsert.rb +19 -7
- data/config/locales/be.yml +1 -1
- data/config/locales/en.yml +11 -0
- data/config/locales/fr.yml +1 -1
- data/config/locales/lt.yml +1 -1
- data/config/locales/ru.yml +1 -1
- data/config/locales/uk.yml +1 -1
- data/db/migrate/20240303174340_fix_spree_stock_item_unique_index.rb +14 -10
- data/db/migrate/20260814000001_rename_stock_items_to_stock_levels.rb +13 -7
- data/lib/generators/spree/api_resource/api_resource_generator.rb +35 -3
- data/lib/generators/spree/api_resource/templates/admin_controller.rb.tt +9 -4
- data/lib/generators/spree/api_resource/templates/admin_integration_spec.rb.tt +74 -0
- data/lib/generators/spree/api_resource/templates/store_controller.rb.tt +11 -6
- data/lib/spree/agent_tool.rb +105 -1
- data/lib/spree/agent_tools/default_catalog.rb +16 -21
- data/lib/spree/agent_tools/legacy_tools.rb +212 -0
- data/lib/spree/agent_tools/operation_catalog.rb +206 -0
- data/lib/spree/agent_tools/operation_tool.rb +189 -0
- data/lib/spree/agent_tools/record_summary.rb +8 -2
- data/lib/spree/agent_tools/registry.rb +65 -31
- data/lib/spree/agent_tools/resource_map.rb +207 -9
- data/lib/spree/agent_tools.rb +3 -3
- data/lib/spree/core/dependencies_helper.rb +96 -40
- data/lib/spree/core/engine.rb +12 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +30 -2
- data/lib/spree/reporting/default_vocabulary.rb +25 -5
- data/lib/spree/testing_support/extension_rake.rb +12 -0
- data/lib/spree/upgrades/5_6_to_6_0/manifest.yml +34 -0
- data/lib/tasks/dependencies.rake +2 -2
- data/lib/tasks/diagnostics.rake +11 -0
- metadata +29 -7
- data/lib/spree/agent_tools/workflow_endpoints.rb +0 -88
- data/lib/spree/agent_tools/workflow_schema.rb +0 -279
- data/lib/spree/agent_tools/workflow_tool.rb +0 -654
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'swagger_helper'
|
|
4
|
+
|
|
5
|
+
# Documents the <%= plural_name.humanize(capitalize: false) %> Admin API in openapi/admin.yaml (`spree task
|
|
6
|
+
# openapi:generate`). The SDK request types come from these operations, and
|
|
7
|
+
# each action other than create, read, update and delete becomes an agent tool.
|
|
8
|
+
RSpec.describe '<%= plural_name.humanize %> Admin API', type: :request, swagger_doc: 'openapi/admin.yaml' do
|
|
9
|
+
let!(:<%= singular_name %>) { create(:<%= singular_name %>) }
|
|
10
|
+
|
|
11
|
+
path '/api/v3/admin/<%= plural_name %>' do
|
|
12
|
+
get 'List <%= plural_name.humanize(capitalize: false) %>' do
|
|
13
|
+
tags '<%= plural_name.humanize %>'
|
|
14
|
+
admin_operation :read, :<%= plural_name %>, description: 'Lists the <%= plural_name.humanize(capitalize: false) %>.'
|
|
15
|
+
parameter name: :page, in: :query, type: :integer, required: false, description: 'Page number'
|
|
16
|
+
parameter name: :limit, in: :query, type: :integer, required: false, description: 'Number of records per page'
|
|
17
|
+
filter_parameters_for
|
|
18
|
+
|
|
19
|
+
response '200', '<%= plural_name.humanize(capitalize: false) %> found' do
|
|
20
|
+
run_test! do |response|
|
|
21
|
+
expect(JSON.parse(response.body)['data'].map { |record| record['id'] }).to include(<%= singular_name %>.prefixed_id)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
post 'Create a <%= singular_name.humanize(capitalize: false) %>' do
|
|
27
|
+
tags '<%= plural_name.humanize %>'
|
|
28
|
+
admin_operation :write, :<%= plural_name %>, description: 'Creates a <%= singular_name.humanize(capitalize: false) %>.'
|
|
29
|
+
request_body_for
|
|
30
|
+
|
|
31
|
+
response '201', '<%= singular_name.humanize(capitalize: false) %> created' do
|
|
32
|
+
let(:body) { attributes_for(:<%= singular_name %>).slice(<%= permitted_attribute_names.map { |a| ":#{a}" }.join(', ') %>)<%= decimal_attribute_names.map { |a| ".merge(#{a}: '1.00')" }.join %> }
|
|
33
|
+
|
|
34
|
+
run_test!
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
path '/api/v3/admin/<%= plural_name %>/{id}' do
|
|
40
|
+
parameter name: :id, in: :path, type: :string, required: true, description: '<%= singular_name.humanize %> ID'
|
|
41
|
+
|
|
42
|
+
let(:id) { <%= singular_name %>.prefixed_id }
|
|
43
|
+
|
|
44
|
+
get 'Get a <%= singular_name.humanize(capitalize: false) %>' do
|
|
45
|
+
tags '<%= plural_name.humanize %>'
|
|
46
|
+
admin_operation :read, :<%= plural_name %>, description: 'Returns a <%= singular_name.humanize(capitalize: false) %>.'
|
|
47
|
+
|
|
48
|
+
response '200', '<%= singular_name.humanize(capitalize: false) %> found' do
|
|
49
|
+
run_test!
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
patch 'Update a <%= singular_name.humanize(capitalize: false) %>' do
|
|
54
|
+
tags '<%= plural_name.humanize %>'
|
|
55
|
+
admin_operation :write, :<%= plural_name %>, description: 'Updates a <%= singular_name.humanize(capitalize: false) %>.'
|
|
56
|
+
request_body_for
|
|
57
|
+
|
|
58
|
+
response '200', '<%= singular_name.humanize(capitalize: false) %> updated' do
|
|
59
|
+
let(:body) { attributes_for(:<%= singular_name %>).slice(<%= permitted_attribute_names.map { |a| ":#{a}" }.join(', ') %>)<%= decimal_attribute_names.map { |a| ".merge(#{a}: '1.00')" }.join %> }
|
|
60
|
+
|
|
61
|
+
run_test!
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
delete 'Delete a <%= singular_name.humanize(capitalize: false) %>' do
|
|
66
|
+
tags '<%= plural_name.humanize %>'
|
|
67
|
+
admin_operation :write, :<%= plural_name %>, description: 'Deletes a <%= singular_name.humanize(capitalize: false) %>.'
|
|
68
|
+
|
|
69
|
+
response '204', '<%= singular_name.humanize(capitalize: false) %> deleted' do
|
|
70
|
+
run_test!
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -3,6 +3,17 @@ module Spree
|
|
|
3
3
|
module V3
|
|
4
4
|
module Store
|
|
5
5
|
class <%= plural_name.camelize %>Controller < ResourceController
|
|
6
|
+
<% if writable? -%>
|
|
7
|
+
# What create and update accept: the controller permits from it, and
|
|
8
|
+
# the integration spec documents it (`request_body_for`), which is
|
|
9
|
+
# where the SDK request types come from.
|
|
10
|
+
request_params :<%= singular_name %> do |body|
|
|
11
|
+
<% request_param_attributes.each do |name, type, required| -%>
|
|
12
|
+
body.attribute :<%= name %>, :<%= type %><%= ', required: true, on: :create' if required %>
|
|
13
|
+
<% end -%>
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
<% end -%>
|
|
6
17
|
protected
|
|
7
18
|
|
|
8
19
|
def model_class
|
|
@@ -17,12 +28,6 @@ module Spree
|
|
|
17
28
|
def serializer_class
|
|
18
29
|
Spree::Api::V3::<%= bare_class_name %>Serializer
|
|
19
30
|
end
|
|
20
|
-
<% end -%>
|
|
21
|
-
<% if writable? -%>
|
|
22
|
-
|
|
23
|
-
def resource_permitted_attributes
|
|
24
|
-
[<%= permitted_attribute_names.map { |a| ":#{a}" }.join(', ') %>]
|
|
25
|
-
end
|
|
26
31
|
<% end -%>
|
|
27
32
|
end
|
|
28
33
|
end
|
data/lib/spree/agent_tool.rb
CHANGED
|
@@ -21,6 +21,12 @@ module Spree
|
|
|
21
21
|
# end
|
|
22
22
|
# end
|
|
23
23
|
class AgentTool
|
|
24
|
+
# The parameter every generic resource tool takes for a resource that
|
|
25
|
+
# lives under another record, such as an order's items.
|
|
26
|
+
PARENT_ID_DESCRIPTION = 'For a resource reached through another record (describe_resource names ' \
|
|
27
|
+
'it as parent or listed_under, e.g. an order for its items and claims, a ' \
|
|
28
|
+
'category for its products): that record\'s id as shown in search results'.freeze
|
|
29
|
+
|
|
24
30
|
# Declarations live in class attributes rather than plain class-level
|
|
25
31
|
# instance variables so a subclass inherits them. Subclassing a tool to
|
|
26
32
|
# tweak it is the documented extension path, and with bare ivars the
|
|
@@ -85,6 +91,26 @@ class AgentTool
|
|
|
85
91
|
declared_mutating == true
|
|
86
92
|
end
|
|
87
93
|
|
|
94
|
+
# Declares that this tool only adds — it creates a record or a file and
|
|
95
|
+
# never overwrites, removes or changes the state of one that exists.
|
|
96
|
+
# Every other mutating tool counts as destructive, so a tool that
|
|
97
|
+
# forgets to say is warned about more, never less.
|
|
98
|
+
#
|
|
99
|
+
# Unlike the declarations above, this one is not inherited: a subclass
|
|
100
|
+
# that overrides `call` may well change existing data, so it is
|
|
101
|
+
# destructive until it says otherwise itself.
|
|
102
|
+
#
|
|
103
|
+
# @return [void]
|
|
104
|
+
def additive!
|
|
105
|
+
@additive = true
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# @return [Boolean] whether the tool may overwrite, remove or change
|
|
109
|
+
# the state of existing data
|
|
110
|
+
def destructive?
|
|
111
|
+
mutating? && @additive != true
|
|
112
|
+
end
|
|
113
|
+
|
|
88
114
|
# @param name [Symbol]
|
|
89
115
|
# @param type [Symbol] JSON schema type
|
|
90
116
|
# @param description [String]
|
|
@@ -105,6 +131,44 @@ class AgentTool
|
|
|
105
131
|
def params
|
|
106
132
|
declared_params
|
|
107
133
|
end
|
|
134
|
+
|
|
135
|
+
# The declared params as JSON Schema, which is what an adapter hands a
|
|
136
|
+
# client. A tool built from an OpenAPI operation overrides this with the
|
|
137
|
+
# operation's own schema, nested properties included.
|
|
138
|
+
#
|
|
139
|
+
# @return [Hash]
|
|
140
|
+
def input_schema
|
|
141
|
+
properties = params.to_h do |name, options|
|
|
142
|
+
property = { 'type' => json_type(options[:type]) }
|
|
143
|
+
property['description'] = options[:description] if options[:description].present?
|
|
144
|
+
# An array must say what it holds: a client validating arguments
|
|
145
|
+
# against the schema refuses the call otherwise.
|
|
146
|
+
property['items'] = { 'type' => json_type(options[:items] || :string) } if property['type'] == 'array'
|
|
147
|
+
|
|
148
|
+
[name.to_s, property]
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
{
|
|
152
|
+
'type' => 'object',
|
|
153
|
+
'properties' => properties,
|
|
154
|
+
'required' => params.select { |_name, options| options[:required] }.keys.map(&:to_s)
|
|
155
|
+
}
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
private
|
|
159
|
+
|
|
160
|
+
# A tool declares Ruby-ish types; JSON Schema wants its own names, and
|
|
161
|
+
# anything unrecognised is a string, which every client can render.
|
|
162
|
+
def json_type(type)
|
|
163
|
+
case type&.to_sym
|
|
164
|
+
when :boolean then 'boolean'
|
|
165
|
+
when :integer then 'integer'
|
|
166
|
+
when :number, :float, :decimal then 'number'
|
|
167
|
+
when :object, :hash then 'object'
|
|
168
|
+
when :array then 'array'
|
|
169
|
+
else 'string'
|
|
170
|
+
end
|
|
171
|
+
end
|
|
108
172
|
end
|
|
109
173
|
|
|
110
174
|
# @return [Spree::AgentTools::Context] who is asking, and where
|
|
@@ -115,7 +179,7 @@ class AgentTool
|
|
|
115
179
|
@context = context
|
|
116
180
|
end
|
|
117
181
|
|
|
118
|
-
delegate :tool_name, :description, :permission, :mutating?, :params, to: :class
|
|
182
|
+
delegate :tool_name, :description, :permission, :mutating?, :destructive?, :params, to: :class
|
|
119
183
|
|
|
120
184
|
# Runs the tool. Subclasses implement this with keyword arguments matching
|
|
121
185
|
# their declared params.
|
|
@@ -167,6 +231,46 @@ class AgentTool
|
|
|
167
231
|
|
|
168
232
|
protected
|
|
169
233
|
|
|
234
|
+
# A resource that lives under a parent — a promotion's rules, an order's
|
|
235
|
+
# payments — has no path of its own to dispatch to, so every tool refuses
|
|
236
|
+
# it the same way: naming the parent and, where the parent carries the
|
|
237
|
+
# rows as an attribute, how to write and read them there. The old answer
|
|
238
|
+
# was the endpoint's 404 for a parent id nobody supplied.
|
|
239
|
+
#
|
|
240
|
+
# @param entry [Spree::AgentTools::ResourceMap::Entry]
|
|
241
|
+
# @param verb [String] 'searched', 'fetched', 'created'…
|
|
242
|
+
# @param action [Symbol] the operation whose path runs under the parent
|
|
243
|
+
# @return [Hash]
|
|
244
|
+
def nested_resource_error(entry, verb, action)
|
|
245
|
+
# A top-level path left unfilled is missing its own id, not a parent.
|
|
246
|
+
return { error: "Pass the id of the #{entry.key.singularize.tr('_', ' ')} to use." } unless entry.nested?(action)
|
|
247
|
+
|
|
248
|
+
parent = entry.parent_key(action)
|
|
249
|
+
parent_entry = Spree::AgentTools::ResourceMap.find(parent)
|
|
250
|
+
attribute = parent_entry&.nested_typed_families&.key(entry.model_class)
|
|
251
|
+
|
|
252
|
+
owner = parent.singularize.tr('_', ' ')
|
|
253
|
+
sentences = ["#{entry.key} belong to #{owner.match?(/\A[aeiou]/) ? 'an' : 'a'} #{owner} and cannot be #{verb} on their own."]
|
|
254
|
+
# Offered only where one parent id fills the path; a resource nested
|
|
255
|
+
# twice has no generic route.
|
|
256
|
+
reachable = entry.path_for(action, id: 'id', parent_id: 'parent').present?
|
|
257
|
+
sentences << "Pass the #{owner}'s id as parent_id to reach them under it." if reachable
|
|
258
|
+
# Each suggested call is one this caller may actually make; a hint
|
|
259
|
+
# that leads straight to a permission refusal is worse than none.
|
|
260
|
+
readable = parent_entry&.readable_by?(context)
|
|
261
|
+
writable = parent_entry&.write_permission.present? && context.permitted?(parent_entry.write_permission)
|
|
262
|
+
if attribute && writable
|
|
263
|
+
sentences << "Write them in the #{attribute} attribute of #{parent} — describe_resource #{parent} shows the shape and the accepted types."
|
|
264
|
+
end
|
|
265
|
+
if attribute && readable && parent_entry.expandable_associations.include?(attribute)
|
|
266
|
+
sentences << "Read them with get_resource on #{parent} and expand: [\"#{attribute}\"]."
|
|
267
|
+
elsif readable && !attribute
|
|
268
|
+
sentences << "Start from #{parent}: get_resource with expand lists what it carries (describe_resource #{parent} names the options)."
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
{ error: sentences.join(' '), parent: parent }
|
|
272
|
+
end
|
|
273
|
+
|
|
170
274
|
# Refuses unless this admin may take `action` on `record`.
|
|
171
275
|
#
|
|
172
276
|
# Holding `write_products` says an admin may edit products; it does not
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
module Spree
|
|
2
2
|
module AgentTools
|
|
3
|
-
# The tools Spree ships: the generic
|
|
4
|
-
#
|
|
3
|
+
# The hand-written tools Spree ships: the generic reads and writes,
|
|
4
|
+
# reporting, imports, files and stock.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# that
|
|
9
|
-
# replacement's schema; and a permission, which must equal the write scope
|
|
10
|
-
# of the admin controller that invokes the same workflow — a contract spec
|
|
11
|
-
# in `spree_api` fails when the two disagree, or when a controller gains a
|
|
12
|
-
# workflow that is neither listed here nor excluded below.
|
|
6
|
+
# Back-office actions are not listed here. Every Admin API action is a
|
|
7
|
+
# tool built from its OpenAPI operation ({OperationCatalog}); an action
|
|
8
|
+
# that should not be one is marked in its rswag spec, with the reason.
|
|
13
9
|
module DefaultCatalog
|
|
14
10
|
# Read tools, and the writes that are not workflows.
|
|
15
11
|
TOOLS = %w[
|
|
@@ -33,15 +29,11 @@ module Spree
|
|
|
33
29
|
].freeze
|
|
34
30
|
|
|
35
31
|
|
|
36
|
-
#
|
|
32
|
+
# @deprecated The 6.0.0 workflow allowlist, kept only so a reference to
|
|
33
|
+
# it does not break through 6.0.x. Nothing reads it: Admin API
|
|
34
|
+
# operations are tools on their own. Removed in 6.1.
|
|
37
35
|
WORKFLOWS = {
|
|
38
36
|
# Catalog
|
|
39
|
-
#
|
|
40
|
-
# The three status moves below run in this process rather than through
|
|
41
|
-
# an endpoint, because the Admin API has none for them: `PATCH` writes
|
|
42
|
-
# the column and the bulk action uses `update_all`, so neither
|
|
43
|
-
# publishes the status event nor withdraws an open seller submission.
|
|
44
|
-
# They dispatch as soon as an admin status endpoint exists.
|
|
45
37
|
product_activate_workflow: 'write_products',
|
|
46
38
|
product_draft_workflow: 'write_products',
|
|
47
39
|
product_archive_workflow: 'write_products',
|
|
@@ -59,8 +51,10 @@ module Spree
|
|
|
59
51
|
|
|
60
52
|
# Orders. `restock_items` is hidden: it is deprecated and ignored, so
|
|
61
53
|
# offering it would invite a model to set something that does nothing.
|
|
54
|
+
# `validated` is for callers that already ran their own veto; offered
|
|
55
|
+
# to a model it would be a way around orders.complete.validate.
|
|
62
56
|
order_cancel_workflow: { permission: 'write_orders', except: %i[restock_items] },
|
|
63
|
-
order_complete_workflow: 'write_orders',
|
|
57
|
+
order_complete_workflow: { permission: 'write_orders', except: %i[validated] },
|
|
64
58
|
|
|
65
59
|
# Fulfillment
|
|
66
60
|
fulfillment_create_workflow: 'write_fulfillments',
|
|
@@ -103,9 +97,9 @@ module Spree
|
|
|
103
97
|
tax_exemption_certificate_verify_workflow: 'write_customers'
|
|
104
98
|
}.freeze
|
|
105
99
|
|
|
106
|
-
#
|
|
107
|
-
#
|
|
108
|
-
#
|
|
100
|
+
# @deprecated The 6.0.0 exclusion list, kept like {WORKFLOWS}. Its
|
|
101
|
+
# reasons now travel as `agent_tool false, reason:` on the operation's
|
|
102
|
+
# rswag spec. Removed in 6.1.
|
|
109
103
|
# The email template editor is a draft-and-publish surface: its steps
|
|
110
104
|
# move a draft through revisions against a live preview, and they mean
|
|
111
105
|
# nothing outside that screen. Publishing one sends real mail in the
|
|
@@ -172,9 +166,10 @@ module Spree
|
|
|
172
166
|
# @return [void]
|
|
173
167
|
def install(registry)
|
|
174
168
|
TOOLS.each { |tool| registry << tool }
|
|
175
|
-
registry.expose_workflows(**WORKFLOWS)
|
|
176
169
|
end
|
|
177
170
|
end
|
|
171
|
+
|
|
172
|
+
deprecate_constant :WORKFLOWS, :EXCLUDED_WORKFLOWS
|
|
178
173
|
end
|
|
179
174
|
end
|
|
180
175
|
end
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module AgentTools
|
|
3
|
+
# The workflow tools Spree 6.0.0 offered, by the name and parameters a
|
|
4
|
+
# client saw then, and the operation each now runs.
|
|
5
|
+
#
|
|
6
|
+
# 6.0.0 derived a tool from a workflow's `perform` signature, so its
|
|
7
|
+
# parameters were the workflow's keywords (`order`, `reason`); a tool now
|
|
8
|
+
# takes the operation's own (`id`, `cancel_reason_id`). This table, written
|
|
9
|
+
# once from the 6.0.0 schemas, keeps those calls working through 6.0.x. It
|
|
10
|
+
# is an explicit list, not a rule: nothing here guesses one name from
|
|
11
|
+
# another.
|
|
12
|
+
#
|
|
13
|
+
# A parameter mapped to nil never reached the endpoint in 6.0.0 either; it
|
|
14
|
+
# is ignored, and the result says so. One mapped to `:merge` was a hash of
|
|
15
|
+
# fields, merged into the body, which is what 6.0.0 did with it.
|
|
16
|
+
#
|
|
17
|
+
# `deliveries_update_tracking` is not here: 6.0.0 sent it to the
|
|
18
|
+
# mark-delivered endpoint and dropped its tracking fields, so a call meant
|
|
19
|
+
# to record tracking marked the delivery delivered. No endpoint sets a
|
|
20
|
+
# carrier status, so the name no longer answers rather than doing that.
|
|
21
|
+
#
|
|
22
|
+
# Removed in 6.1, with the names that are no longer listed.
|
|
23
|
+
# See docs/plans/6.0-agent-tools-from-openapi.md.
|
|
24
|
+
module LegacyTools
|
|
25
|
+
# Old tool name => the operation it runs and its renamed parameters.
|
|
26
|
+
TOOLS = {
|
|
27
|
+
'catalogs_activate' => {
|
|
28
|
+
verb: 'patch', path: '/api/v3/admin/catalogs/{id}/activate',
|
|
29
|
+
parameters: { 'catalog' => 'id' }
|
|
30
|
+
},
|
|
31
|
+
'catalogs_deactivate' => {
|
|
32
|
+
verb: 'patch', path: '/api/v3/admin/catalogs/{id}/deactivate',
|
|
33
|
+
parameters: { 'catalog' => 'id' }
|
|
34
|
+
},
|
|
35
|
+
'fulfillments_create' => {
|
|
36
|
+
verb: 'post', path: '/api/v3/admin/orders/{order_id}/fulfillments',
|
|
37
|
+
parameters: {
|
|
38
|
+
'order' => 'order_id', 'stock_location' => 'stock_location_id',
|
|
39
|
+
'source_fulfillment' => 'source_fulfillment_id', 'delivery_method' => 'delivery_method_id'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
'fulfillments_mark_delivered' => {
|
|
43
|
+
verb: 'patch', path: '/api/v3/admin/orders/{order_id}/fulfillments/{id}/mark_delivered',
|
|
44
|
+
parameters: { 'fulfillment' => 'id' }
|
|
45
|
+
},
|
|
46
|
+
'orders_cancel' => {
|
|
47
|
+
verb: 'patch', path: '/api/v3/admin/orders/{id}/cancel',
|
|
48
|
+
parameters: { 'order' => 'id', 'canceled_at' => nil, 'reason' => 'cancel_reason_id', 'note' => 'cancel_note' }
|
|
49
|
+
},
|
|
50
|
+
'orders_complete' => {
|
|
51
|
+
verb: 'patch', path: '/api/v3/admin/orders/{id}/complete',
|
|
52
|
+
parameters: { 'order' => 'id' }
|
|
53
|
+
},
|
|
54
|
+
'payments_capture' => {
|
|
55
|
+
verb: 'patch', path: '/api/v3/admin/orders/{order_id}/payments/{id}/capture',
|
|
56
|
+
parameters: { 'payment' => 'id' }
|
|
57
|
+
},
|
|
58
|
+
'payments_void' => {
|
|
59
|
+
verb: 'patch', path: '/api/v3/admin/orders/{order_id}/payments/{id}/void',
|
|
60
|
+
parameters: { 'payment' => 'id' }
|
|
61
|
+
},
|
|
62
|
+
'price_lists_activate' => {
|
|
63
|
+
verb: 'patch', path: '/api/v3/admin/price_lists/{id}/activate',
|
|
64
|
+
parameters: { 'price_list' => 'id' }
|
|
65
|
+
},
|
|
66
|
+
'price_lists_deactivate' => {
|
|
67
|
+
verb: 'patch', path: '/api/v3/admin/price_lists/{id}/deactivate',
|
|
68
|
+
parameters: { 'price_list' => 'id' }
|
|
69
|
+
},
|
|
70
|
+
'products_activate' => {
|
|
71
|
+
verb: 'patch', path: '/api/v3/admin/products/{id}/activate',
|
|
72
|
+
parameters: { 'product' => 'id' }
|
|
73
|
+
},
|
|
74
|
+
'products_approve' => {
|
|
75
|
+
verb: 'patch', path: '/api/v3/admin/products/{id}/approve',
|
|
76
|
+
parameters: { 'product' => 'id' }
|
|
77
|
+
},
|
|
78
|
+
'products_archive' => {
|
|
79
|
+
verb: 'patch', path: '/api/v3/admin/products/{id}/archive',
|
|
80
|
+
parameters: { 'product' => 'id' }
|
|
81
|
+
},
|
|
82
|
+
'products_draft' => {
|
|
83
|
+
verb: 'patch', path: '/api/v3/admin/products/{id}/draft',
|
|
84
|
+
parameters: { 'product' => 'id' }
|
|
85
|
+
},
|
|
86
|
+
'products_reject' => {
|
|
87
|
+
verb: 'patch', path: '/api/v3/admin/products/{id}/reject',
|
|
88
|
+
parameters: { 'product' => 'id' }
|
|
89
|
+
},
|
|
90
|
+
'purchase_orders_cancel' => {
|
|
91
|
+
verb: 'patch', path: '/api/v3/admin/purchase_orders/{id}/cancel',
|
|
92
|
+
parameters: { 'purchase_order' => 'id' }
|
|
93
|
+
},
|
|
94
|
+
'purchase_orders_close' => {
|
|
95
|
+
verb: 'patch', path: '/api/v3/admin/purchase_orders/{id}/close',
|
|
96
|
+
parameters: { 'purchase_order' => 'id' }
|
|
97
|
+
},
|
|
98
|
+
'purchase_orders_mark_draft' => {
|
|
99
|
+
verb: 'patch', path: '/api/v3/admin/purchase_orders/{id}/mark_draft',
|
|
100
|
+
parameters: { 'purchase_order' => 'id' }
|
|
101
|
+
},
|
|
102
|
+
'purchase_orders_mark_ordered' => {
|
|
103
|
+
verb: 'patch', path: '/api/v3/admin/purchase_orders/{id}/mark_ordered',
|
|
104
|
+
parameters: { 'purchase_order' => 'id' }
|
|
105
|
+
},
|
|
106
|
+
'purchase_orders_receive' => {
|
|
107
|
+
verb: 'post', path: '/api/v3/admin/purchase_orders/{purchase_order_id}/stock_receipts',
|
|
108
|
+
parameters: { 'purchase_order' => 'purchase_order_id' }
|
|
109
|
+
},
|
|
110
|
+
'refunds_create' => {
|
|
111
|
+
verb: 'post', path: '/api/v3/admin/orders/{order_id}/refunds',
|
|
112
|
+
parameters: {
|
|
113
|
+
'payment' => 'payment_id', 'reason' => 'refund_reason_id', 'originator' => nil,
|
|
114
|
+
'order' => 'order_id', 'tax_amount' => nil
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
'seller_requirement_submissions_accept' => {
|
|
118
|
+
verb: 'patch', path: '/api/v3/admin/sellers/{seller_id}/requirement_submissions/{id}/accept',
|
|
119
|
+
parameters: { 'submission' => 'id' }
|
|
120
|
+
},
|
|
121
|
+
'seller_requirement_submissions_reject' => {
|
|
122
|
+
verb: 'patch', path: '/api/v3/admin/sellers/{seller_id}/requirement_submissions/{id}/reject',
|
|
123
|
+
parameters: { 'submission' => 'id' }
|
|
124
|
+
},
|
|
125
|
+
'seller_requirement_submissions_waive' => {
|
|
126
|
+
verb: 'post', path: '/api/v3/admin/sellers/{seller_id}/requirement_submissions',
|
|
127
|
+
parameters: { 'seller' => 'seller_id', 'requirement' => 'requirement_id' }
|
|
128
|
+
},
|
|
129
|
+
'sellers_approve' => {
|
|
130
|
+
verb: 'patch', path: '/api/v3/admin/sellers/{id}/approve',
|
|
131
|
+
parameters: { 'seller' => 'id' }
|
|
132
|
+
},
|
|
133
|
+
'sellers_invite' => {
|
|
134
|
+
verb: 'post', path: '/api/v3/admin/sellers/{id}/invite',
|
|
135
|
+
parameters: { 'seller' => 'id', 'inviter' => nil, 'role' => 'role_id' }
|
|
136
|
+
},
|
|
137
|
+
'sellers_reject' => {
|
|
138
|
+
verb: 'patch', path: '/api/v3/admin/sellers/{id}/reject',
|
|
139
|
+
parameters: { 'seller' => 'id' }
|
|
140
|
+
},
|
|
141
|
+
'sellers_reopen_onboarding' => {
|
|
142
|
+
verb: 'patch', path: '/api/v3/admin/sellers/{id}/reopen_onboarding',
|
|
143
|
+
parameters: { 'seller' => 'id' }
|
|
144
|
+
},
|
|
145
|
+
'sellers_suspend' => {
|
|
146
|
+
verb: 'patch', path: '/api/v3/admin/sellers/{id}/suspend',
|
|
147
|
+
parameters: { 'seller' => 'id' }
|
|
148
|
+
},
|
|
149
|
+
'shipping_labels_purchase' => {
|
|
150
|
+
verb: 'post', path: '/api/v3/admin/orders/{order_id}/fulfillments/{fulfillment_id}/labels',
|
|
151
|
+
parameters: { 'owner' => 'fulfillment_id' }
|
|
152
|
+
},
|
|
153
|
+
'shipping_labels_refund' => {
|
|
154
|
+
verb: 'patch', path: '/api/v3/admin/orders/{order_id}/fulfillments/{fulfillment_id}/labels/{id}/refund',
|
|
155
|
+
parameters: { 'shipping_label' => 'id' }
|
|
156
|
+
},
|
|
157
|
+
'stock_transfers_cancel' => {
|
|
158
|
+
verb: 'patch', path: '/api/v3/admin/stock_transfers/{id}/cancel',
|
|
159
|
+
parameters: { 'stock_transfer' => 'id' }
|
|
160
|
+
},
|
|
161
|
+
'stock_transfers_close' => {
|
|
162
|
+
verb: 'patch', path: '/api/v3/admin/stock_transfers/{id}/close',
|
|
163
|
+
parameters: { 'stock_transfer' => 'id' }
|
|
164
|
+
},
|
|
165
|
+
'stock_transfers_mark_draft' => {
|
|
166
|
+
verb: 'patch', path: '/api/v3/admin/stock_transfers/{id}/mark_draft',
|
|
167
|
+
parameters: { 'stock_transfer' => 'id' }
|
|
168
|
+
},
|
|
169
|
+
'stock_transfers_mark_in_transit' => {
|
|
170
|
+
verb: 'patch', path: '/api/v3/admin/stock_transfers/{id}/mark_in_transit',
|
|
171
|
+
parameters: { 'stock_transfer' => 'id' }
|
|
172
|
+
},
|
|
173
|
+
'stock_transfers_mark_ready' => {
|
|
174
|
+
verb: 'patch', path: '/api/v3/admin/stock_transfers/{id}/mark_ready',
|
|
175
|
+
parameters: { 'stock_transfer' => 'id' }
|
|
176
|
+
},
|
|
177
|
+
'stock_transfers_receive' => {
|
|
178
|
+
verb: 'post', path: '/api/v3/admin/stock_transfers/{stock_transfer_id}/stock_receipts',
|
|
179
|
+
parameters: { 'stock_transfer' => 'stock_transfer_id' }
|
|
180
|
+
},
|
|
181
|
+
'tax_exemption_certificates_verify' => {
|
|
182
|
+
verb: 'patch', path: '/api/v3/admin/companies/{company_id}/tax_exemption_certificates/{id}/verify',
|
|
183
|
+
parameters: { 'certificate' => 'id' }
|
|
184
|
+
},
|
|
185
|
+
'variants_create' => {
|
|
186
|
+
verb: 'post', path: '/api/v3/admin/products/{product_id}/variants',
|
|
187
|
+
parameters: { 'product' => 'product_id', 'attributes' => :merge }
|
|
188
|
+
},
|
|
189
|
+
'variants_update' => {
|
|
190
|
+
verb: 'patch', path: '/api/v3/admin/products/{product_id}/variants/{id}',
|
|
191
|
+
parameters: { 'variant' => 'id', 'attributes' => :merge }
|
|
192
|
+
}
|
|
193
|
+
}.freeze
|
|
194
|
+
|
|
195
|
+
class << self
|
|
196
|
+
# The 6.0.0 parameters of a tool that keeps its name, when it still
|
|
197
|
+
# runs the same operation.
|
|
198
|
+
#
|
|
199
|
+
# @param name [String]
|
|
200
|
+
# @param verb [String]
|
|
201
|
+
# @param path [String] the OpenAPI path
|
|
202
|
+
# @return [Hash{String => String, Symbol, nil}]
|
|
203
|
+
def parameters_for(name, verb, path)
|
|
204
|
+
tool = TOOLS[name.to_s]
|
|
205
|
+
return {} unless tool && tool[:verb] == verb.to_s && tool[:path] == path
|
|
206
|
+
|
|
207
|
+
tool[:parameters]
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|