solidus_api 4.7.3 → 4.7.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/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 +6 -8
- data/app/controllers/spree/api/customer_returns_controller.rb +4 -2
- data/app/controllers/spree/api/orders_controller.rb +34 -23
- 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: 6ae4b619a4e7e9f30c12bb133effb05dc4883c91126d19633d759156fa336cd6
|
|
4
|
+
data.tar.gz: d7c0ed1fefb94ca7c94ce3a147a1f01dbc79bfbfbebfeff52312fa8259748acf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ffa3263370c7a5af3b213aef76adcfd8abb53003f44bb094d2c1c5372658b7d12511e08af41825ba1637e6501dc6a505e3e9430f7fe69d5487f16731f1b6be7
|
|
7
|
+
data.tar.gz: 8429f320cd6981b3f10aea88f4bc0105c2ee16e293fe5ac242ebf2e548dcc506585d630c8258f8af440fcd2ae44fa368cc868abe0997ee39968388efe72f43c0
|
|
@@ -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,10 +42,12 @@ module Spree
|
|
|
42
42
|
def update
|
|
43
43
|
authorize! :update, @order, order_token
|
|
44
44
|
|
|
45
|
+
if can?(:admin_update, @order) && user_id.present?
|
|
46
|
+
user = Spree.user_class.accessible_by(current_ability, :show).find(user_id)
|
|
47
|
+
end
|
|
48
|
+
|
|
45
49
|
if Spree::Config.order_update_attributes_class.new(@order, update_params, request_env: request.headers.env).call
|
|
46
|
-
|
|
47
|
-
@order.associate_user!(Spree.user_class.find(user_id))
|
|
48
|
-
end
|
|
50
|
+
@order.associate_user!(user) if user
|
|
49
51
|
|
|
50
52
|
return if after_update_attributes
|
|
51
53
|
|
|
@@ -87,11 +89,7 @@ module Spree
|
|
|
87
89
|
end
|
|
88
90
|
|
|
89
91
|
def massaged_params
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
set_payment_parameters_amount(massaged_params, @order)
|
|
93
|
-
|
|
94
|
-
massaged_params
|
|
92
|
+
params.deep_dup
|
|
95
93
|
end
|
|
96
94
|
|
|
97
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)
|
|
@@ -85,11 +86,13 @@ module Spree
|
|
|
85
86
|
def update
|
|
86
87
|
authorize! :update, @order, order_token
|
|
87
88
|
|
|
89
|
+
user_id = params[:order][:user_id]
|
|
90
|
+
if can?(:admin_update, @order) && user_id
|
|
91
|
+
user = Spree.user_class.accessible_by(current_ability, :show).find(user_id)
|
|
92
|
+
end
|
|
93
|
+
|
|
88
94
|
if @order.contents.update_cart(order_params)
|
|
89
|
-
|
|
90
|
-
if can?(:admin, @order) && user_id
|
|
91
|
-
@order.associate_user!(Spree.user_class.find(user_id))
|
|
92
|
-
end
|
|
95
|
+
@order.associate_user!(user) if user
|
|
93
96
|
respond_with(@order, default_template: :show)
|
|
94
97
|
else
|
|
95
98
|
invalid_resource!(@order)
|
|
@@ -159,36 +162,44 @@ module Spree
|
|
|
159
162
|
# @api public
|
|
160
163
|
def determine_order_user
|
|
161
164
|
if order_params[:user_id].present?
|
|
162
|
-
Spree.user_class.find(order_params[:user_id])
|
|
165
|
+
Spree.user_class.accessible_by(current_ability, :show).find(order_params[:user_id])
|
|
163
166
|
else
|
|
164
167
|
current_api_user
|
|
165
168
|
end
|
|
166
169
|
end
|
|
167
170
|
|
|
168
171
|
def permitted_order_attributes
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
#
|
|
175
|
-
#
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
# permitted attributes, which could have unintended side effects.
|
|
179
|
-
order_attributes = super.deep_dup
|
|
180
|
-
|
|
181
|
-
payments_attributes = order_attributes.find do |attribute|
|
|
182
|
-
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)
|
|
183
181
|
end
|
|
184
|
-
|
|
182
|
+
shipments_attributes[:shipments_attributes] |= permitted_attributes.shipment_attributes
|
|
185
183
|
|
|
184
|
+
permit_payment_amount(order_attributes) +
|
|
185
|
+
admin_order_attributes.reject { |attribute| attribute == :user_id && action_name == "update" }
|
|
186
|
+
else
|
|
186
187
|
order_attributes
|
|
187
188
|
end
|
|
188
189
|
end
|
|
189
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
|
+
|
|
190
201
|
def permitted_shipment_attributes
|
|
191
|
-
if
|
|
202
|
+
if can_admin_action?(Spree::Order)
|
|
192
203
|
super + admin_shipment_attributes
|
|
193
204
|
else
|
|
194
205
|
super
|
|
@@ -202,7 +213,7 @@ module Spree
|
|
|
202
213
|
"permitted_order_attributes uses the permitted_checkout_payment_attributes " \
|
|
203
214
|
"method to determine the permitted attributes for payments."
|
|
204
215
|
)
|
|
205
|
-
if
|
|
216
|
+
if can_admin_action?(Spree::Order)
|
|
206
217
|
super + admin_payment_attributes
|
|
207
218
|
else
|
|
208
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.7.
|
|
4
|
+
version: 4.7.4
|
|
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.7.
|
|
60
|
+
version: 4.7.4
|
|
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.7.
|
|
67
|
+
version: 4.7.4
|
|
68
68
|
description: REST API for the Solidus e-commerce framework.
|
|
69
69
|
email: contact@solidus.io
|
|
70
70
|
executables: []
|
|
@@ -271,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
271
271
|
- !ruby/object:Gem::Version
|
|
272
272
|
version: 1.8.23
|
|
273
273
|
requirements: []
|
|
274
|
-
rubygems_version: 4.0.
|
|
274
|
+
rubygems_version: 4.0.20
|
|
275
275
|
specification_version: 4
|
|
276
276
|
summary: REST API for the Solidus e-commerce framework.
|
|
277
277
|
test_files: []
|