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.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/base_controller.rb +17 -21
  3. data/app/controllers/spree/api/v1/countries_controller.rb +2 -4
  4. data/app/controllers/spree/api/v1/credit_cards_controller.rb +9 -10
  5. data/app/controllers/spree/api/v1/images_controller.rb +1 -2
  6. data/app/controllers/spree/api/v1/inventory_units_controller.rb +2 -2
  7. data/app/controllers/spree/api/v1/line_items_controller.rb +24 -28
  8. data/app/controllers/spree/api/v1/option_types_controller.rb +5 -5
  9. data/app/controllers/spree/api/v1/option_values_controller.rb +16 -17
  10. data/app/controllers/spree/api/v1/orders_controller.rb +39 -49
  11. data/app/controllers/spree/api/v1/payments_controller.rb +15 -17
  12. data/app/controllers/spree/api/v1/product_properties_controller.rb +2 -3
  13. data/app/controllers/spree/api/v1/products_controller.rb +24 -25
  14. data/app/controllers/spree/api/v1/promotions_controller.rb +9 -8
  15. data/app/controllers/spree/api/v1/properties_controller.rb +14 -16
  16. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +0 -1
  17. data/app/controllers/spree/api/v1/shipments_controller.rb +17 -26
  18. data/app/controllers/spree/api/v1/states_controller.rb +9 -10
  19. data/app/controllers/spree/api/v1/stock_items_controller.rb +2 -2
  20. data/app/controllers/spree/api/v1/stores_controller.rb +0 -1
  21. data/app/controllers/spree/api/v1/tags_controller.rb +1 -1
  22. data/app/controllers/spree/api/v1/taxonomies_controller.rb +1 -3
  23. data/app/controllers/spree/api/v1/taxons_controller.rb +15 -16
  24. data/app/controllers/spree/api/v1/users_controller.rb +1 -4
  25. data/app/controllers/spree/api/v1/variants_controller.rb +22 -22
  26. data/app/controllers/spree/api/v1/zones_controller.rb +0 -1
  27. data/app/helpers/spree/api/api_helpers.rb +5 -5
  28. data/app/views/spree/api/errors/gateway_error.v1.rabl +1 -1
  29. data/app/views/spree/api/errors/invalid_api_key.v1.rabl +1 -1
  30. data/app/views/spree/api/errors/invalid_resource.v1.rabl +1 -1
  31. data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +1 -1
  32. data/app/views/spree/api/errors/not_found.v1.rabl +1 -1
  33. data/app/views/spree/api/errors/unauthorized.v1.rabl +1 -1
  34. data/app/views/spree/api/v1/addresses/show.v1.rabl +2 -2
  35. data/app/views/spree/api/v1/credit_cards/index.v1.rabl +1 -1
  36. data/app/views/spree/api/v1/images/index.v1.rabl +1 -1
  37. data/app/views/spree/api/v1/images/show.v1.rabl +1 -1
  38. data/app/views/spree/api/v1/line_items/show.v1.rabl +3 -3
  39. data/app/views/spree/api/v1/option_types/index.v1.rabl +1 -1
  40. data/app/views/spree/api/v1/option_types/show.v1.rabl +1 -1
  41. data/app/views/spree/api/v1/option_values/index.v1.rabl +1 -1
  42. data/app/views/spree/api/v1/option_values/show.v1.rabl +1 -1
  43. data/app/views/spree/api/v1/orders/could_not_transition.v1.rabl +1 -1
  44. data/app/views/spree/api/v1/orders/index.v1.rabl +1 -1
  45. data/app/views/spree/api/v1/orders/invalid_shipping_method.v1.rabl +1 -1
  46. data/app/views/spree/api/v1/orders/mine.v1.rabl +1 -1
  47. data/app/views/spree/api/v1/orders/order.v1.rabl +5 -5
  48. data/app/views/spree/api/v1/orders/show.v1.rabl +7 -7
  49. data/app/views/spree/api/v1/product_properties/index.v1.rabl +1 -1
  50. data/app/views/spree/api/v1/product_properties/new.v1.rabl +1 -1
  51. data/app/views/spree/api/v1/products/index.v1.rabl +1 -1
  52. data/app/views/spree/api/v1/products/show.v1.rabl +5 -5
  53. data/app/views/spree/api/v1/return_authorizations/show.v1.rabl +1 -1
  54. data/app/views/spree/api/v1/shared/stock_location_required.v1.rabl +1 -1
  55. data/app/views/spree/api/v1/shipments/big.v1.rabl +8 -8
  56. data/app/views/spree/api/v1/shipments/cannot_ready_shipment.v1.rabl +1 -1
  57. data/app/views/spree/api/v1/shipments/mine.v1.rabl +1 -1
  58. data/app/views/spree/api/v1/shipments/show.v1.rabl +5 -5
  59. data/app/views/spree/api/v1/shipments/small.v1.rabl +5 -5
  60. data/app/views/spree/api/v1/shipping_rates/show.v1.rabl +1 -1
  61. data/app/views/spree/api/v1/states/index.v1.rabl +1 -3
  62. data/app/views/spree/api/v1/stock_items/show.v1.rabl +1 -1
  63. data/app/views/spree/api/v1/stock_locations/show.v1.rabl +2 -2
  64. data/app/views/spree/api/v1/stock_movements/show.v1.rabl +1 -1
  65. data/app/views/spree/api/v1/taxonomies/index.v1.rabl +1 -1
  66. data/app/views/spree/api/v1/taxonomies/jstree.rabl +2 -3
  67. data/app/views/spree/api/v1/taxonomies/nested.v1.rabl +1 -1
  68. data/app/views/spree/api/v1/taxonomies/show.v1.rabl +1 -1
  69. data/app/views/spree/api/v1/taxons/index.v1.rabl +1 -3
  70. data/app/views/spree/api/v1/taxons/jstree.rabl +3 -4
  71. data/app/views/spree/api/v1/taxons/taxons.v1.rabl +1 -1
  72. data/app/views/spree/api/v1/users/index.v1.rabl +1 -1
  73. data/app/views/spree/api/v1/users/show.v1.rabl +3 -3
  74. data/app/views/spree/api/v1/variants/big.v1.rabl +1 -1
  75. data/app/views/spree/api/v1/variants/index.v1.rabl +1 -1
  76. data/app/views/spree/api/v1/variants/show.v1.rabl +1 -1
  77. data/app/views/spree/api/v1/variants/small.v1.rabl +7 -7
  78. data/config/routes.rb +3 -3
  79. data/lib/spree/api/controller_setup.rb +2 -2
  80. data/lib/spree/api/engine.rb +3 -3
  81. data/lib/spree/api/responders/rabl_template.rb +1 -3
  82. data/lib/spree/api/testing_support/caching.rb +3 -3
  83. data/lib/spree/api/testing_support/helpers.rb +4 -4
  84. data/lib/spree/api/testing_support/setup.rb +2 -2
  85. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 949e3374b130bd1cd8c1de9fe328915bfe17d519
4
- data.tar.gz: 1c70da25fc3f172998d608a92418c9b8cad46716
3
+ metadata.gz: caba802b7afa26a82233bfc0febb57c3c17e40b2
4
+ data.tar.gz: 440f5f7989eec445403422c946090c78eb67acc6
5
5
  SHA512:
6
- metadata.gz: 55ef6ad5ed1daf562ca67b8df0b071c89cb823dc4332de337b19f03c8262703e473874c3924fd2d2b76d2153f0b6cce536ac1db47049d20a1109f2e4ba959d69
7
- data.tar.gz: afc35989746989dc55cf0ff84b6d86a46f439875c2e2a08232650fbc0b85ffe507a0d9f8955ac7384f3747ef37c8d833baf4d272d8e7dfadbaa00a6fe75002bf
6
+ metadata.gz: 38cda01b2989356cc970658c54f3317459482d56ce16aa10832b8b4e7a74e5b04dda0a88bb3300bee29dc95b0ddf0d8a2e56dd52f79bacd32b12ed3aeeac2a76
7
+ data.tar.gz: 9ff1e6162ebbc664277e98fe26c15347e39e0e7bd22990b877221e5bd24e6a709c41ff0a49e2c44c753f0e2417ab426d70aa1aaa1fbd8f1c833cc9e4d814f2c9
@@ -11,7 +11,7 @@ module Spree
11
11
 
12
12
  before_action :set_content_type
13
13
  before_action :load_user
14
- before_action :authorize_for_order, if: Proc.new { order_token.present? }
14
+ before_action :authorize_for_order, if: proc { order_token.present? }
15
15
  before_action :authenticate_user
16
16
  before_action :load_user_roles
17
17
 
@@ -25,7 +25,7 @@ module Spree
25
25
 
26
26
  # users should be able to set price when importing orders via api
27
27
  def permitted_line_item_attributes
28
- if @current_user_roles.include?("admin")
28
+ if @current_user_roles.include?('admin')
29
29
  super + [:price, :variant_id, :sku]
30
30
  else
31
31
  super
@@ -34,17 +34,17 @@ module Spree
34
34
 
35
35
  def content_type
36
36
  case params[:format]
37
- when "json"
38
- "application/json; charset=utf-8"
39
- when "xml"
40
- "text/xml; charset=utf-8"
37
+ when 'json'
38
+ 'application/json; charset=utf-8'
39
+ when 'xml'
40
+ 'text/xml; charset=utf-8'
41
41
  end
42
42
  end
43
43
 
44
44
  private
45
45
 
46
46
  def set_content_type
47
- headers["Content-Type"] = content_type
47
+ headers['Content-Type'] = content_type
48
48
  end
49
49
 
50
50
  def load_user
@@ -65,11 +65,11 @@ module Spree
65
65
  end
66
66
 
67
67
  def invalid_api_key
68
- render "spree/api/errors/invalid_api_key", status: 401
68
+ render 'spree/api/errors/invalid_api_key', status: 401
69
69
  end
70
70
 
71
71
  def must_specify_api_key
72
- render "spree/api/errors/must_specify_api_key", status: 401
72
+ render 'spree/api/errors/must_specify_api_key', status: 401
73
73
  end
74
74
 
75
75
  def load_user_roles
@@ -77,7 +77,7 @@ module Spree
77
77
  end
78
78
 
79
79
  def unauthorized
80
- render "spree/api/errors/unauthorized", status: 401 and return
80
+ render 'spree/api/errors/unauthorized', status: 401 and return
81
81
  end
82
82
 
83
83
  def error_during_processing(exception)
@@ -101,7 +101,7 @@ module Spree
101
101
  end
102
102
 
103
103
  def not_found
104
- render "spree/api/errors/not_found", status: 404 and return
104
+ render 'spree/api/errors/not_found', status: 404 and return
105
105
  end
106
106
 
107
107
  def current_ability
@@ -110,16 +110,16 @@ module Spree
110
110
 
111
111
  def invalid_resource!(resource)
112
112
  @resource = resource
113
- render "spree/api/errors/invalid_resource", status: 422
113
+ render 'spree/api/errors/invalid_resource', status: 422
114
114
  end
115
115
 
116
116
  def api_key
117
- request.headers["X-Spree-Token"] || params[:token]
117
+ request.headers['X-Spree-Token'] || params[:token]
118
118
  end
119
119
  helper_method :api_key
120
120
 
121
121
  def order_token
122
- request.headers["X-Spree-Order-Token"] || params[:order_token]
122
+ request.headers['X-Spree-Order-Token'] || params[:order_token]
123
123
  end
124
124
 
125
125
  def find_product(id)
@@ -129,15 +129,11 @@ module Spree
129
129
  end
130
130
 
131
131
  def product_scope
132
- if @current_user_roles.include?("admin")
132
+ if @current_user_roles.include?('admin')
133
133
  scope = Product.with_deleted.accessible_by(current_ability, :read).includes(*product_includes)
134
134
 
135
- unless params[:show_deleted]
136
- scope = scope.not_deleted
137
- end
138
- unless params[:show_discontinued]
139
- scope = scope.not_discontinued
140
- end
135
+ scope = scope.not_deleted unless params[:show_deleted]
136
+ scope = scope.not_discontinued unless params[:show_discontinued]
141
137
  else
142
138
  scope = Product.accessible_by(current_ability, :read).active.includes(*product_includes)
143
139
  end
@@ -8,10 +8,8 @@ module Spree
8
8
  @countries = Country.accessible_by(current_ability, :read).ransack(params[:q]).result.
9
9
  order('name ASC').
10
10
  page(params[:page]).per(params[:per_page])
11
- country = Country.order("updated_at ASC").last
12
- if stale?(country)
13
- respond_with(@countries)
14
- end
11
+ country = Country.order('updated_at ASC').last
12
+ respond_with(@countries) if stale?(country)
15
13
  end
16
14
 
17
15
  def show
@@ -5,22 +5,21 @@ module Spree
5
5
  before_action :user
6
6
 
7
7
  def index
8
- @credit_cards = user
9
- .credit_cards
10
- .accessible_by(current_ability, :read)
11
- .with_payment_profile
12
- .ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
8
+ @credit_cards = user.
9
+ credit_cards.
10
+ accessible_by(current_ability, :read).
11
+ with_payment_profile.
12
+ ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
13
13
  respond_with(@credit_cards)
14
14
  end
15
15
 
16
16
  private
17
17
 
18
- def user
19
- if params[:user_id].present?
20
- @user ||= Spree::user_class.accessible_by(current_ability, :read).find(params[:user_id])
21
- end
18
+ def user
19
+ if params[:user_id].present?
20
+ @user ||= Spree.user_class.accessible_by(current_ability, :read).find(params[:user_id])
22
21
  end
23
-
22
+ end
24
23
  end
25
24
  end
26
25
  end
@@ -12,8 +12,7 @@ module Spree
12
12
  respond_with(@image)
13
13
  end
14
14
 
15
- def new
16
- end
15
+ def new; end
17
16
 
18
17
  def create
19
18
  authorize! :create, Image
@@ -34,7 +34,7 @@ module Spree
34
34
  can_event = "can_#{@event}?"
35
35
 
36
36
  unless inventory_unit.respond_to?(can_event) &&
37
- inventory_unit.send(can_event)
37
+ inventory_unit.send(can_event)
38
38
  render plain: { exception: "cannot transition to #{@event}" }.to_json,
39
39
  status: 200
40
40
  false
@@ -44,7 +44,7 @@ module Spree
44
44
  def fire
45
45
  inventory_unit.send("#{@event}!") if @event
46
46
  end
47
-
47
+
48
48
  def inventory_unit_params
49
49
  params.require(:inventory_unit).permit(permitted_inventory_unit_attributes)
50
50
  end
@@ -6,15 +6,14 @@ module Spree
6
6
 
7
7
  self.line_item_options = []
8
8
 
9
- def new
10
- end
9
+ def new; end
11
10
 
12
11
  def create
13
12
  variant = Spree::Variant.find(params[:line_item][:variant_id])
14
13
  @line_item = order.contents.add(
15
- variant,
16
- params[:line_item][:quantity] || 1,
17
- line_item_params[:options] || {}
14
+ variant,
15
+ params[:line_item][:quantity] || 1,
16
+ line_item_params[:options] || {}
18
17
  )
19
18
 
20
19
  if @line_item.errors.empty?
@@ -41,32 +40,29 @@ module Spree
41
40
  end
42
41
 
43
42
  private
44
- def order
45
- @order ||= Spree::Order.includes(:line_items).find_by!(number: order_id)
46
- authorize! :update, @order, order_token
47
- end
48
43
 
49
- def find_line_item
50
- id = params[:id].to_i
51
- order.line_items.detect { |line_item| line_item.id == id } or
52
- raise ActiveRecord::RecordNotFound
53
- end
44
+ def order
45
+ @order ||= Spree::Order.includes(:line_items).find_by!(number: order_id)
46
+ authorize! :update, @order, order_token
47
+ end
54
48
 
55
- def line_items_attributes
56
- {line_items_attributes: {
57
- id: params[:id],
58
- quantity: params[:line_item][:quantity],
59
- options: line_item_params[:options] || {}
60
- }}
61
- end
49
+ def find_line_item
50
+ id = params[:id].to_i
51
+ order.line_items.detect { |line_item| line_item.id == id } or
52
+ raise ActiveRecord::RecordNotFound
53
+ end
62
54
 
63
- def line_item_params
64
- params.require(:line_item).permit(
65
- :quantity,
66
- :variant_id,
67
- options: line_item_options
68
- )
69
- end
55
+ def line_items_attributes
56
+ { line_items_attributes: {
57
+ id: params[:id],
58
+ quantity: params[:line_item][:quantity],
59
+ options: line_item_params[:options] || {}
60
+ } }
61
+ end
62
+
63
+ def line_item_params
64
+ params.require(:line_item).permit(:quantity, :variant_id, options: line_item_options)
65
+ end
70
66
  end
71
67
  end
72
68
  end
@@ -22,8 +22,7 @@ module Spree
22
22
  respond_with(@option_type)
23
23
  end
24
24
 
25
- def new
26
- end
25
+ def new; end
27
26
 
28
27
  def create
29
28
  authorize! :create, Spree::OptionType
@@ -51,9 +50,10 @@ module Spree
51
50
  end
52
51
 
53
52
  private
54
- def option_type_params
55
- params.require(:option_type).permit(permitted_option_type_attributes)
56
- end
53
+
54
+ def option_type_params
55
+ params.require(:option_type).permit(permitted_option_type_attributes)
56
+ end
57
57
  end
58
58
  end
59
59
  end
@@ -3,11 +3,11 @@ module Spree
3
3
  module V1
4
4
  class OptionValuesController < Spree::Api::BaseController
5
5
  def index
6
- if params[:ids]
7
- @option_values = scope.where(id: params[:ids])
8
- else
9
- @option_values = scope.ransack(params[:q]).result.distinct
10
- end
6
+ @option_values = if params[:ids]
7
+ scope.where(id: params[:ids])
8
+ else
9
+ scope.ransack(params[:q]).result.distinct
10
+ end
11
11
  respond_with(@option_values)
12
12
  end
13
13
 
@@ -16,8 +16,7 @@ module Spree
16
16
  respond_with(@option_value)
17
17
  end
18
18
 
19
- def new
20
- end
19
+ def new; end
21
20
 
22
21
  def create
23
22
  authorize! :create, Spree::OptionValue
@@ -46,17 +45,17 @@ module Spree
46
45
 
47
46
  private
48
47
 
49
- def scope
50
- if params[:option_type_id]
51
- @scope ||= Spree::OptionType.find(params[:option_type_id]).option_values.accessible_by(current_ability, :read)
52
- else
53
- @scope ||= Spree::OptionValue.accessible_by(current_ability, :read).load
54
- end
55
- end
48
+ def scope
49
+ @scope ||= if params[:option_type_id]
50
+ Spree::OptionType.find(params[:option_type_id]).option_values.accessible_by(current_ability, :read)
51
+ else
52
+ Spree::OptionValue.accessible_by(current_ability, :read).load
53
+ end
54
+ end
56
55
 
57
- def option_value_params
58
- params.require(:option_value).permit(permitted_option_value_attributes)
59
- end
56
+ def option_value_params
57
+ params.require(:option_value).permit(permitted_option_value_attributes)
58
+ end
60
59
  end
61
60
  end
62
61
  end
@@ -27,32 +27,21 @@ module Spree
27
27
  end
28
28
 
29
29
  def create
30
- authorize! :create, Spree::Order
31
- if can?(:admin, Spree::Order)
32
-
33
- order_user = if @current_user_roles.include?('admin') && order_params[:user_id]
34
- Spree.user_class.find(order_params[:user_id])
35
- else
36
- current_api_user
37
- end
38
-
39
- import_params = if @current_user_roles.include?("admin")
40
- params[:order].present? ? params[:order].permit! : {}
41
- else
42
- order_params
43
- end
44
-
45
- @order = Spree::Core::Importer::Order.import(order_user, import_params)
30
+ authorize! :create, Order
31
+ order_user = if @current_user_roles.include?('admin') && order_params[:user_id]
32
+ Spree.user_class.find(order_params[:user_id])
33
+ else
34
+ current_api_user
35
+ end
46
36
 
47
- respond_with(@order, default_template: :show, status: 201)
48
- else
49
- @order = Spree::Order.create!(user: current_api_user, store: current_store)
50
- if @order.contents.update_cart(order_params)
51
- respond_with(@order, default_template: :show, status: 201)
52
- else
53
- invalid_resource!(@order)
54
- end
37
+ import_params = if @current_user_roles.include?('admin')
38
+ params[:order].present? ? params[:order].permit! : {}
39
+ else
40
+ order_params
55
41
  end
42
+
43
+ @order = Spree::Core::Importer::Order.import(order_user, import_params)
44
+ respond_with(@order, default_template: :show, status: 201)
56
45
  end
57
46
 
58
47
  def empty
@@ -100,7 +89,7 @@ module Spree
100
89
  if current_api_user.persisted?
101
90
  @orders = current_api_user.orders.reverse_chronological.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
102
91
  else
103
- render "spree/api/errors/unauthorized", status: :unauthorized
92
+ render 'spree/api/errors/unauthorized', status: :unauthorized
104
93
  end
105
94
  end
106
95
 
@@ -110,38 +99,39 @@ module Spree
110
99
  @order.coupon_code = params[:coupon_code]
111
100
  @handler = PromotionHandler::Coupon.new(@order).apply
112
101
  status = @handler.successful? ? 200 : 422
113
- render "spree/api/v1/promotions/handler", status: status
102
+ render 'spree/api/v1/promotions/handler', status: status
114
103
  end
115
104
 
116
105
  private
117
- def order_params
118
- if params[:order]
119
- normalize_params
120
- params.require(:order).permit(permitted_order_attributes)
121
- else
122
- {}
123
- end
124
- end
125
106
 
126
- def normalize_params
127
- params[:order][:payments_attributes] = params[:order].delete(:payments) if params[:order][:payments]
128
- params[:order][:shipments_attributes] = params[:order].delete(:shipments) if params[:order][:shipments]
129
- params[:order][:line_items_attributes] = params[:order].delete(:line_items) if params[:order][:line_items]
130
- params[:order][:ship_address_attributes] = params[:order].delete(:ship_address) if params[:order][:ship_address]
131
- params[:order][:bill_address_attributes] = params[:order].delete(:bill_address) if params[:order][:bill_address]
107
+ def order_params
108
+ if params[:order]
109
+ normalize_params
110
+ params.require(:order).permit(permitted_order_attributes)
111
+ else
112
+ {}
132
113
  end
114
+ end
133
115
 
134
- def find_order(lock = false)
135
- @order = Spree::Order.lock(lock).find_by!(number: params[:id])
136
- end
116
+ def normalize_params
117
+ params[:order][:payments_attributes] = params[:order].delete(:payments) if params[:order][:payments]
118
+ params[:order][:shipments_attributes] = params[:order].delete(:shipments) if params[:order][:shipments]
119
+ params[:order][:line_items_attributes] = params[:order].delete(:line_items) if params[:order][:line_items]
120
+ params[:order][:ship_address_attributes] = params[:order].delete(:ship_address) if params[:order][:ship_address]
121
+ params[:order][:bill_address_attributes] = params[:order].delete(:bill_address) if params[:order][:bill_address]
122
+ end
137
123
 
138
- def find_current_order
139
- current_api_user ? current_api_user.orders.incomplete.order(:created_at).last : nil
140
- end
124
+ def find_order(lock = false)
125
+ @order = Spree::Order.lock(lock).find_by!(number: params[:id])
126
+ end
141
127
 
142
- def order_id
143
- super || params[:id]
144
- end
128
+ def find_current_order
129
+ current_api_user ? current_api_user.orders.incomplete.order(:created_at).last : nil
130
+ end
131
+
132
+ def order_id
133
+ super || params[:id]
134
+ end
145
135
  end
146
136
  end
147
137
  end