spree_api 3.3.6 → 3.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +17 -21
- data/app/controllers/spree/api/v1/countries_controller.rb +2 -4
- data/app/controllers/spree/api/v1/credit_cards_controller.rb +9 -10
- data/app/controllers/spree/api/v1/images_controller.rb +1 -2
- data/app/controllers/spree/api/v1/inventory_units_controller.rb +2 -2
- data/app/controllers/spree/api/v1/line_items_controller.rb +24 -28
- data/app/controllers/spree/api/v1/option_types_controller.rb +5 -5
- data/app/controllers/spree/api/v1/option_values_controller.rb +16 -17
- data/app/controllers/spree/api/v1/orders_controller.rb +39 -49
- data/app/controllers/spree/api/v1/payments_controller.rb +15 -17
- data/app/controllers/spree/api/v1/product_properties_controller.rb +2 -3
- data/app/controllers/spree/api/v1/products_controller.rb +24 -25
- data/app/controllers/spree/api/v1/promotions_controller.rb +9 -8
- data/app/controllers/spree/api/v1/properties_controller.rb +14 -16
- data/app/controllers/spree/api/v1/return_authorizations_controller.rb +0 -1
- data/app/controllers/spree/api/v1/shipments_controller.rb +17 -26
- data/app/controllers/spree/api/v1/states_controller.rb +9 -10
- data/app/controllers/spree/api/v1/stock_items_controller.rb +2 -2
- data/app/controllers/spree/api/v1/stores_controller.rb +0 -1
- data/app/controllers/spree/api/v1/tags_controller.rb +1 -1
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +1 -3
- data/app/controllers/spree/api/v1/taxons_controller.rb +15 -16
- data/app/controllers/spree/api/v1/users_controller.rb +1 -4
- data/app/controllers/spree/api/v1/variants_controller.rb +22 -22
- data/app/controllers/spree/api/v1/zones_controller.rb +0 -1
- data/app/helpers/spree/api/api_helpers.rb +5 -5
- data/app/views/spree/api/errors/gateway_error.v1.rabl +1 -1
- data/app/views/spree/api/errors/invalid_api_key.v1.rabl +1 -1
- data/app/views/spree/api/errors/invalid_resource.v1.rabl +1 -1
- data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +1 -1
- data/app/views/spree/api/errors/not_found.v1.rabl +1 -1
- data/app/views/spree/api/errors/unauthorized.v1.rabl +1 -1
- data/app/views/spree/api/v1/addresses/show.v1.rabl +2 -2
- data/app/views/spree/api/v1/credit_cards/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/images/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/images/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/line_items/show.v1.rabl +3 -3
- data/app/views/spree/api/v1/option_types/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/option_types/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/option_values/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/option_values/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/could_not_transition.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/invalid_shipping_method.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/mine.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/order.v1.rabl +5 -5
- data/app/views/spree/api/v1/orders/show.v1.rabl +7 -7
- data/app/views/spree/api/v1/product_properties/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/product_properties/new.v1.rabl +1 -1
- data/app/views/spree/api/v1/products/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/products/show.v1.rabl +5 -5
- data/app/views/spree/api/v1/return_authorizations/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/shared/stock_location_required.v1.rabl +1 -1
- data/app/views/spree/api/v1/shipments/big.v1.rabl +8 -8
- data/app/views/spree/api/v1/shipments/cannot_ready_shipment.v1.rabl +1 -1
- data/app/views/spree/api/v1/shipments/mine.v1.rabl +1 -1
- data/app/views/spree/api/v1/shipments/show.v1.rabl +5 -5
- data/app/views/spree/api/v1/shipments/small.v1.rabl +5 -5
- data/app/views/spree/api/v1/shipping_rates/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/states/index.v1.rabl +1 -3
- data/app/views/spree/api/v1/stock_items/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/stock_locations/show.v1.rabl +2 -2
- data/app/views/spree/api/v1/stock_movements/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/taxonomies/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/taxonomies/jstree.rabl +2 -3
- data/app/views/spree/api/v1/taxonomies/nested.v1.rabl +1 -1
- data/app/views/spree/api/v1/taxonomies/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/taxons/index.v1.rabl +1 -3
- data/app/views/spree/api/v1/taxons/jstree.rabl +3 -4
- data/app/views/spree/api/v1/taxons/taxons.v1.rabl +1 -1
- data/app/views/spree/api/v1/users/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/users/show.v1.rabl +3 -3
- data/app/views/spree/api/v1/variants/big.v1.rabl +1 -1
- data/app/views/spree/api/v1/variants/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/variants/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/variants/small.v1.rabl +7 -7
- data/config/routes.rb +3 -3
- data/lib/spree/api/controller_setup.rb +2 -2
- data/lib/spree/api/engine.rb +3 -3
- data/lib/spree/api/responders/rabl_template.rb +1 -3
- data/lib/spree/api/testing_support/caching.rb +3 -3
- data/lib/spree/api/testing_support/helpers.rb +4 -4
- data/lib/spree/api/testing_support/setup.rb +2 -2
- metadata +7 -7
@@ -2,7 +2,6 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
module V1
|
4
4
|
class UsersController < Spree::Api::BaseController
|
5
|
-
|
6
5
|
rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing
|
7
6
|
|
8
7
|
def index
|
@@ -24,8 +23,7 @@ module Spree
|
|
24
23
|
respond_with(user)
|
25
24
|
end
|
26
25
|
|
27
|
-
def new
|
28
|
-
end
|
26
|
+
def new; end
|
29
27
|
|
30
28
|
def create
|
31
29
|
authorize! :create, Spree.user_class
|
@@ -63,7 +61,6 @@ module Spree
|
|
63
61
|
[bill_address_attributes: permitted_address_attributes,
|
64
62
|
ship_address_attributes: permitted_address_attributes])
|
65
63
|
end
|
66
|
-
|
67
64
|
end
|
68
65
|
end
|
69
66
|
end
|
@@ -24,17 +24,16 @@ module Spree
|
|
24
24
|
# we render on the view so we better update it any time a node is included
|
25
25
|
# or removed from the views.
|
26
26
|
def index
|
27
|
-
@variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images,
|
28
|
-
|
27
|
+
@variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images, stock_items: :stock_location).
|
28
|
+
ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
29
29
|
respond_with(@variants)
|
30
30
|
end
|
31
31
|
|
32
|
-
def new
|
33
|
-
end
|
32
|
+
def new; end
|
34
33
|
|
35
34
|
def show
|
36
|
-
@variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images,
|
37
|
-
|
35
|
+
@variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images, stock_items: :stock_location).
|
36
|
+
find(params[:id])
|
38
37
|
respond_with(@variant)
|
39
38
|
end
|
40
39
|
|
@@ -48,27 +47,28 @@ module Spree
|
|
48
47
|
end
|
49
48
|
|
50
49
|
private
|
51
|
-
def product
|
52
|
-
@product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id]
|
53
|
-
end
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
else
|
59
|
-
variants = Variant
|
60
|
-
end
|
51
|
+
def product
|
52
|
+
@product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id]
|
53
|
+
end
|
61
54
|
|
62
|
-
|
63
|
-
|
64
|
-
|
55
|
+
def scope
|
56
|
+
variants = if @product
|
57
|
+
@product.variants_including_master
|
58
|
+
else
|
59
|
+
Variant
|
60
|
+
end
|
65
61
|
|
66
|
-
|
62
|
+
if current_ability.can?(:manage, Variant) && params[:show_deleted]
|
63
|
+
variants = variants.with_deleted
|
67
64
|
end
|
68
65
|
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
variants.accessible_by(current_ability, :read)
|
67
|
+
end
|
68
|
+
|
69
|
+
def variant_params
|
70
|
+
params.require(:variant).permit(permitted_variant_attributes)
|
71
|
+
end
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -38,14 +38,14 @@ module Spree
|
|
38
38
|
mattr_reader *ATTRIBUTES
|
39
39
|
|
40
40
|
def required_fields_for(model)
|
41
|
-
required_fields = model._validators.select do |
|
41
|
+
required_fields = model._validators.select do |_field, validations|
|
42
42
|
validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
|
43
43
|
end.map(&:first) # get fields that are invalid
|
44
44
|
# Permalinks presence is validated, but are really automatically generated
|
45
45
|
# Therefore we shouldn't tell API clients that they MUST send one through
|
46
|
-
required_fields.map!(&:to_s).delete(
|
46
|
+
required_fields.map!(&:to_s).delete('permalink')
|
47
47
|
# Do not require slugs, either
|
48
|
-
required_fields.delete(
|
48
|
+
required_fields.delete('slug')
|
49
49
|
required_fields
|
50
50
|
end
|
51
51
|
|
@@ -126,7 +126,7 @@ module Spree
|
|
126
126
|
@@adjustment_attributes = [
|
127
127
|
:id, :source_type, :source_id, :adjustable_type, :adjustable_id,
|
128
128
|
:originator_type, :originator_id, :amount, :label, :mandatory,
|
129
|
-
:locked, :eligible,
|
129
|
+
:locked, :eligible, :created_at, :updated_at
|
130
130
|
]
|
131
131
|
|
132
132
|
@@creditcard_attributes = [
|
@@ -177,7 +177,7 @@ module Spree
|
|
177
177
|
]
|
178
178
|
|
179
179
|
def variant_attributes
|
180
|
-
if @current_user_roles && @current_user_roles.include?(
|
180
|
+
if @current_user_roles && @current_user_roles.include?('admin')
|
181
181
|
@@variant_attributes + [:cost_price]
|
182
182
|
else
|
183
183
|
@@variant_attributes
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:gateway_error, scope:
|
2
|
+
node(:error) { I18n.t(:gateway_error, scope: 'spree.api', text: @error) }
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:invalid_api_key, key: api_key, scope:
|
2
|
+
node(:error) { I18n.t(:invalid_api_key, key: api_key, scope: 'spree.api') }
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:must_specify_api_key, scope:
|
2
|
+
node(:error) { I18n.t(:must_specify_api_key, scope: 'spree.api') }
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:resource_not_found, scope:
|
2
|
+
node(:error) { I18n.t(:resource_not_found, scope: 'spree.api') }
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:unauthorized, scope:
|
2
|
+
node(:error) { I18n.t(:unauthorized, scope: 'spree.api') }
|
@@ -2,9 +2,9 @@ object @address
|
|
2
2
|
cache [I18n.locale, root_object]
|
3
3
|
attributes *address_attributes
|
4
4
|
|
5
|
-
child(:country) do |
|
5
|
+
child(:country) do |_address|
|
6
6
|
attributes *country_attributes
|
7
7
|
end
|
8
|
-
child(:state) do |
|
8
|
+
child(:state) do |_address|
|
9
9
|
attributes *state_attributes
|
10
10
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
object @image
|
2
2
|
attributes *image_attributes
|
3
3
|
attributes :viewable_type, :viewable_id
|
4
|
-
Spree::Image.attachment_definitions[:attachment][:styles].each do |k,
|
4
|
+
Spree::Image.attachment_definitions[:attachment][:styles].each do |k, _v|
|
5
5
|
node("#{k}_url") { |i| i.attachment.url(k) }
|
6
6
|
end
|
@@ -3,12 +3,12 @@ cache [I18n.locale, root_object]
|
|
3
3
|
attributes *line_item_attributes
|
4
4
|
node(:single_display_amount) { |li| li.single_display_amount.to_s }
|
5
5
|
node(:display_amount) { |li| li.display_amount.to_s }
|
6
|
-
node(:total
|
6
|
+
node(:total, &:total)
|
7
7
|
child :variant do
|
8
|
-
extends
|
8
|
+
extends 'spree/api/v1/variants/small'
|
9
9
|
attributes :product_id
|
10
10
|
end
|
11
11
|
|
12
12
|
child adjustments: :adjustments do
|
13
|
-
extends
|
13
|
+
extends 'spree/api/v1/adjustments/show'
|
14
14
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object @option_value
|
2
|
-
attributes *option_value_attributes
|
2
|
+
attributes *option_value_attributes
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:errors) { [I18n.t(:invalid_shipping_method, scope:
|
2
|
+
node(:errors) { [I18n.t(:invalid_shipping_method, scope: 'spree.api.order')] }
|
@@ -3,8 +3,8 @@ attributes *order_attributes
|
|
3
3
|
node(:display_item_total) { |o| o.display_item_total.to_s }
|
4
4
|
node(:total_quantity) { |o| o.line_items.sum(:quantity) }
|
5
5
|
node(:display_total) { |o| o.display_total.to_s }
|
6
|
-
node(:display_ship_total
|
7
|
-
node(:display_tax_total
|
8
|
-
node(:display_adjustment_total
|
9
|
-
node(:token
|
10
|
-
node(:checkout_steps
|
6
|
+
node(:display_ship_total, &:display_ship_total)
|
7
|
+
node(:display_tax_total, &:display_tax_total)
|
8
|
+
node(:display_adjustment_total, &:display_adjustment_total)
|
9
|
+
node(:token, &:guest_token)
|
10
|
+
node(:checkout_steps, &:checkout_steps)
|
@@ -1,20 +1,20 @@
|
|
1
1
|
object @order
|
2
|
-
extends
|
2
|
+
extends 'spree/api/v1/orders/order'
|
3
3
|
|
4
4
|
if lookup_context.find_all("spree/api/v1/orders/#{root_object.state}").present?
|
5
5
|
extends "spree/api/v1/orders/#{root_object.state}"
|
6
6
|
end
|
7
7
|
|
8
8
|
child billing_address: :bill_address do
|
9
|
-
extends
|
9
|
+
extends 'spree/api/v1/addresses/show'
|
10
10
|
end
|
11
11
|
|
12
12
|
child shipping_address: :ship_address do
|
13
|
-
extends
|
13
|
+
extends 'spree/api/v1/addresses/show'
|
14
14
|
end
|
15
15
|
|
16
16
|
child line_items: :line_items do
|
17
|
-
extends
|
17
|
+
extends 'spree/api/v1/line_items/show'
|
18
18
|
end
|
19
19
|
|
20
20
|
child payments: :payments do
|
@@ -34,11 +34,11 @@ child payments: :payments do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
child shipments: :shipments do
|
37
|
-
extends
|
37
|
+
extends 'spree/api/v1/shipments/small'
|
38
38
|
end
|
39
39
|
|
40
40
|
child adjustments: :adjustments do
|
41
|
-
extends
|
41
|
+
extends 'spree/api/v1/adjustments/show'
|
42
42
|
end
|
43
43
|
|
44
44
|
# Necessary for backend's order interface
|
@@ -47,5 +47,5 @@ node :permissions do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
child valid_credit_cards: :credit_cards do
|
50
|
-
extends
|
50
|
+
extends 'spree/api/v1/credit_cards/show'
|
51
51
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
node(:attributes) { [*product_property_attributes] }
|
2
|
-
node(:required_attributes) { [] }
|
2
|
+
node(:required_attributes) { [] }
|
@@ -5,5 +5,5 @@ node(:current_page) { params[:page] ? params[:page].to_i : 1 }
|
|
5
5
|
node(:per_page) { params[:per_page].try(:to_i) || Kaminari.config.default_per_page }
|
6
6
|
node(:pages) { @products.total_pages }
|
7
7
|
child(@products => :products) do
|
8
|
-
extends
|
8
|
+
extends 'spree/api/v1/products/show'
|
9
9
|
end
|
@@ -4,15 +4,15 @@ cache [I18n.locale, @current_user_roles.include?('admin'), current_currency, roo
|
|
4
4
|
attributes *product_attributes
|
5
5
|
|
6
6
|
node(:display_price) { |p| p.display_price.to_s }
|
7
|
-
node(:has_variants
|
8
|
-
node(:taxon_ids
|
7
|
+
node(:has_variants, &:has_variants?)
|
8
|
+
node(:taxon_ids, &:taxon_ids)
|
9
9
|
|
10
10
|
child master: :master do
|
11
|
-
extends
|
11
|
+
extends 'spree/api/v1/variants/small'
|
12
12
|
end
|
13
13
|
|
14
14
|
child variants: :variants do
|
15
|
-
extends
|
15
|
+
extends 'spree/api/v1/variants/small'
|
16
16
|
end
|
17
17
|
|
18
18
|
child option_types: :option_types do
|
@@ -27,6 +27,6 @@ child classifications: :classifications do
|
|
27
27
|
attributes :taxon_id, :position
|
28
28
|
|
29
29
|
child(:taxon) do
|
30
|
-
extends
|
30
|
+
extends 'spree/api/v1/taxons/show'
|
31
31
|
end
|
32
32
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object @return_authorization
|
2
|
-
attributes *return_authorization_attributes
|
2
|
+
attributes *return_authorization_attributes
|
@@ -1,2 +1,2 @@
|
|
1
1
|
object false
|
2
|
-
node(:error) { I18n.t(:stock_location_required, scope:
|
2
|
+
node(:error) { I18n.t(:stock_location_required, scope: 'spree.api') }
|
@@ -3,7 +3,7 @@ cache @shipment
|
|
3
3
|
attributes *shipment_attributes
|
4
4
|
|
5
5
|
child selected_shipping_rate: :selected_shipping_rate do
|
6
|
-
extends
|
6
|
+
extends 'spree/api/v1/shipping_rates/show'
|
7
7
|
end
|
8
8
|
|
9
9
|
child inventory_units: :inventory_units do
|
@@ -11,32 +11,32 @@ child inventory_units: :inventory_units do
|
|
11
11
|
attributes *inventory_unit_attributes
|
12
12
|
|
13
13
|
child :variant do
|
14
|
-
extends
|
14
|
+
extends 'spree/api/v1/variants/small'
|
15
15
|
attributes :product_id
|
16
|
-
child(images: :images) { extends
|
16
|
+
child(images: :images) { extends 'spree/api/v1/images/show' }
|
17
17
|
end
|
18
18
|
|
19
19
|
child :line_item do
|
20
20
|
attributes *line_item_attributes
|
21
21
|
node(:single_display_amount) { |li| li.single_display_amount.to_s }
|
22
22
|
node(:display_amount) { |li| li.display_amount.to_s }
|
23
|
-
node(:total
|
23
|
+
node(:total, &:total)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
child order: :order do
|
28
|
-
extends
|
28
|
+
extends 'spree/api/v1/orders/order'
|
29
29
|
|
30
30
|
child billing_address: :bill_address do
|
31
|
-
extends
|
31
|
+
extends 'spree/api/v1/addresses/show'
|
32
32
|
end
|
33
33
|
|
34
34
|
child shipping_address: :ship_address do
|
35
|
-
extends
|
35
|
+
extends 'spree/api/v1/addresses/show'
|
36
36
|
end
|
37
37
|
|
38
38
|
child adjustments: :adjustments do
|
39
|
-
extends
|
39
|
+
extends 'spree/api/v1/adjustments/show'
|
40
40
|
end
|
41
41
|
|
42
42
|
child payments: :payments do
|