solidus_api 4.8.1 → 4.8.2
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/controllers/spree/api/addresses_controller.rb +3 -0
- data/app/controllers/spree/api/base_controller.rb +7 -3
- data/app/controllers/spree/api/checkouts_controller.rb +2 -6
- data/app/controllers/spree/api/customer_returns_controller.rb +4 -2
- data/app/controllers/spree/api/orders_controller.rb +28 -19
- data/app/controllers/spree/api/payments_controller.rb +1 -1
- data/app/views/spree/api/orders/_order.json.jbuilder +4 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 21e4c047ca744ac92f4ee5e35dd4b50fd43eea41c454071a04bf8817a6fd17dc
|
|
4
|
+
data.tar.gz: febb90eb9a4246379c478c1478968468785ad0599f6361dd2724378ab76590c4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 25a4ef5c76917c7a6fefcd2a3346cc7045a39da8e3e2bb4dc4c8558f04af024ab6dc33901a9556e2f9ae42b93f92c745ab20b67494e15c221798a07000ec5263
|
|
7
|
+
data.tar.gz: f9098952cb11759b69836d046397c1007a28ac27b515115d347bbd2e935557f26bcffa49f239ade7c58e4a6d6821ea7b526be4ea1e11fcd5e298ab3ee9966067
|
|
@@ -4,6 +4,7 @@ module Spree
|
|
|
4
4
|
module Api
|
|
5
5
|
class AddressesController < Spree::Api::BaseController
|
|
6
6
|
before_action :find_order
|
|
7
|
+
around_action :lock_order, only: :update
|
|
7
8
|
|
|
8
9
|
def show
|
|
9
10
|
authorize! :show, @order, order_token
|
|
@@ -12,6 +13,8 @@ module Spree
|
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def update
|
|
16
|
+
# The order may have changed between being loaded and being locked.
|
|
17
|
+
@order.reload
|
|
15
18
|
authorize! :update, @order, order_token
|
|
16
19
|
find_address
|
|
17
20
|
|
|
@@ -40,7 +40,7 @@ module Spree
|
|
|
40
40
|
|
|
41
41
|
Spree::Api::Config.metadata_permit_parameters.each do |resource|
|
|
42
42
|
define_method("permitted_#{resource.to_s.underscore}_attributes") do
|
|
43
|
-
if
|
|
43
|
+
if can_admin_action?("Spree::#{resource}".constantize)
|
|
44
44
|
super() + admin_metadata_attributes
|
|
45
45
|
else
|
|
46
46
|
super()
|
|
@@ -50,7 +50,7 @@ module Spree
|
|
|
50
50
|
|
|
51
51
|
# users should be able to set price when importing orders via api
|
|
52
52
|
def permitted_line_item_attributes
|
|
53
|
-
if
|
|
53
|
+
if can_admin_action?(Spree::LineItem)
|
|
54
54
|
super + admin_line_item_attributes + admin_metadata_attributes
|
|
55
55
|
else
|
|
56
56
|
super
|
|
@@ -58,7 +58,11 @@ module Spree
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def permitted_user_attributes
|
|
61
|
-
|
|
61
|
+
can_admin_action?(Spree.user_class) ? super + admin_metadata_attributes : super
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def can_admin_action?(subject)
|
|
65
|
+
can?((action_name == "create") ? :admin_create : :admin_update, subject)
|
|
62
66
|
end
|
|
63
67
|
|
|
64
68
|
def current_api_user
|
|
@@ -42,7 +42,7 @@ module Spree
|
|
|
42
42
|
def update
|
|
43
43
|
authorize! :update, @order, order_token
|
|
44
44
|
|
|
45
|
-
if can?(:
|
|
45
|
+
if can?(:admin_update, @order) && user_id.present?
|
|
46
46
|
user = Spree.user_class.accessible_by(current_ability, :show).find(user_id)
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -89,11 +89,7 @@ module Spree
|
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
def massaged_params
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
set_payment_parameters_amount(massaged_params, @order)
|
|
95
|
-
|
|
96
|
-
massaged_params
|
|
92
|
+
params.deep_dup
|
|
97
93
|
end
|
|
98
94
|
|
|
99
95
|
# Should be overridden if you have areas of your checkout that don't match
|
|
@@ -10,7 +10,7 @@ module Spree
|
|
|
10
10
|
rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
|
|
11
11
|
|
|
12
12
|
def create
|
|
13
|
-
authorize! :create,
|
|
13
|
+
authorize! :create, @customer_return
|
|
14
14
|
|
|
15
15
|
if @customer_return.save
|
|
16
16
|
respond_with(@customer_return, status: 201, default_template: :show)
|
|
@@ -73,12 +73,14 @@ module Spree
|
|
|
73
73
|
|
|
74
74
|
@customer_return.return_items = return_items_params.map do |item_params|
|
|
75
75
|
return_item = if item_params[:id]
|
|
76
|
-
|
|
76
|
+
@order.return_items.find(item_params[:id])
|
|
77
77
|
else
|
|
78
78
|
Spree::ReturnItem.new
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
+
authorize! :update, return_item.customer_return if return_item.customer_return
|
|
81
82
|
return_item.assign_attributes(item_params)
|
|
83
|
+
@order.inventory_units.find(return_item.inventory_unit_id) if return_item.inventory_unit_id
|
|
82
84
|
|
|
83
85
|
return_item
|
|
84
86
|
end
|
|
@@ -37,7 +37,7 @@ module Spree
|
|
|
37
37
|
def create
|
|
38
38
|
authorize! :create, Order
|
|
39
39
|
|
|
40
|
-
if can?(:
|
|
40
|
+
if can?(:admin_create, Order)
|
|
41
41
|
@order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
|
|
42
42
|
respond_with(@order, default_template: :show, status: 201)
|
|
43
43
|
else
|
|
@@ -70,6 +70,7 @@ module Spree
|
|
|
70
70
|
]
|
|
71
71
|
@orders = paginate(
|
|
72
72
|
Spree::Order
|
|
73
|
+
.accessible_by(current_ability, :index)
|
|
73
74
|
.ransack(params[:q])
|
|
74
75
|
.result
|
|
75
76
|
.includes(orders_includes)
|
|
@@ -86,7 +87,7 @@ module Spree
|
|
|
86
87
|
authorize! :update, @order, order_token
|
|
87
88
|
|
|
88
89
|
user_id = params[:order][:user_id]
|
|
89
|
-
if can?(:
|
|
90
|
+
if can?(:admin_update, @order) && user_id
|
|
90
91
|
user = Spree.user_class.accessible_by(current_ability, :show).find(user_id)
|
|
91
92
|
end
|
|
92
93
|
|
|
@@ -168,29 +169,37 @@ module Spree
|
|
|
168
169
|
end
|
|
169
170
|
|
|
170
171
|
def permitted_order_attributes
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
#
|
|
177
|
-
#
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
# permitted attributes, which could have unintended side effects.
|
|
181
|
-
order_attributes = super.deep_dup
|
|
182
|
-
|
|
183
|
-
payments_attributes = order_attributes.find do |attribute|
|
|
184
|
-
attribute.is_a?(Hash) && attribute.has_key?(:payments_attributes)
|
|
172
|
+
# We're doing a deep_dup here to avoid modifying the original
|
|
173
|
+
# permitted attributes, which could have unintended side effects.
|
|
174
|
+
order_attributes = super.deep_dup
|
|
175
|
+
|
|
176
|
+
if can_admin_action?(Spree::Order)
|
|
177
|
+
# order_attributes only has the shipment attributes customers can
|
|
178
|
+
# set at checkout. Admins can set all of them.
|
|
179
|
+
shipments_attributes = order_attributes.find do |attribute|
|
|
180
|
+
attribute.is_a?(Hash) && attribute.has_key?(:shipments_attributes)
|
|
185
181
|
end
|
|
186
|
-
|
|
182
|
+
shipments_attributes[:shipments_attributes] |= permitted_attributes.shipment_attributes
|
|
187
183
|
|
|
184
|
+
permit_payment_amount(order_attributes) +
|
|
185
|
+
admin_order_attributes.reject { |attribute| attribute == :user_id && action_name == "update" }
|
|
186
|
+
else
|
|
188
187
|
order_attributes
|
|
189
188
|
end
|
|
190
189
|
end
|
|
191
190
|
|
|
191
|
+
def permit_payment_amount(attributes)
|
|
192
|
+
attributes.map do |attribute|
|
|
193
|
+
if attribute.is_a?(Hash) && attribute.key?(:payments_attributes)
|
|
194
|
+
attribute.merge(payments_attributes: attribute[:payments_attributes] | [:amount])
|
|
195
|
+
else
|
|
196
|
+
attribute
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
192
201
|
def permitted_shipment_attributes
|
|
193
|
-
if
|
|
202
|
+
if can_admin_action?(Spree::Order)
|
|
194
203
|
super + admin_shipment_attributes
|
|
195
204
|
else
|
|
196
205
|
super
|
|
@@ -204,7 +213,7 @@ module Spree
|
|
|
204
213
|
"permitted_order_attributes uses the permitted_checkout_payment_attributes " \
|
|
205
214
|
"method to determine the permitted attributes for payments."
|
|
206
215
|
)
|
|
207
|
-
if
|
|
216
|
+
if can_admin_action?(Spree::Order)
|
|
208
217
|
super + admin_payment_attributes
|
|
209
218
|
else
|
|
210
219
|
super
|
|
@@ -7,6 +7,9 @@ json.cache! [I18n.locale, order, order_attributes] do
|
|
|
7
7
|
json.display_total(order.display_total.to_s)
|
|
8
8
|
json.display_ship_total(order.display_ship_total)
|
|
9
9
|
json.display_tax_total(order.display_tax_total)
|
|
10
|
-
json.token(order.guest_token)
|
|
11
10
|
json.checkout_steps(order.checkout_steps)
|
|
12
11
|
end
|
|
12
|
+
|
|
13
|
+
if can?(:update, order)
|
|
14
|
+
json.token(order.guest_token)
|
|
15
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solidus_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.8.
|
|
4
|
+
version: 4.8.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Solidus Team
|
|
@@ -57,14 +57,14 @@ dependencies:
|
|
|
57
57
|
requirements:
|
|
58
58
|
- - '='
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: 4.8.
|
|
60
|
+
version: 4.8.2
|
|
61
61
|
type: :runtime
|
|
62
62
|
prerelease: false
|
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
64
64
|
requirements:
|
|
65
65
|
- - '='
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: 4.8.
|
|
67
|
+
version: 4.8.2
|
|
68
68
|
description: REST API for the Solidus e-commerce framework.
|
|
69
69
|
email: contact@solidus.io
|
|
70
70
|
executables: []
|
|
@@ -272,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
272
272
|
- !ruby/object:Gem::Version
|
|
273
273
|
version: 1.8.23
|
|
274
274
|
requirements: []
|
|
275
|
-
rubygems_version: 4.0.
|
|
275
|
+
rubygems_version: 4.0.20
|
|
276
276
|
specification_version: 4
|
|
277
277
|
summary: REST API for the Solidus e-commerce framework.
|
|
278
278
|
test_files: []
|