solidus_api 1.2.3 → 1.3.0.beta1

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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Rakefile +1 -1
  4. data/app/controllers/spree/api/addresses_controller.rb +3 -2
  5. data/app/controllers/spree/api/base_controller.rb +10 -15
  6. data/app/controllers/spree/api/checkouts_controller.rb +56 -55
  7. data/app/controllers/spree/api/classifications_controller.rb +4 -4
  8. data/app/controllers/spree/api/config_controller.rb +6 -1
  9. data/app/controllers/spree/api/credit_cards_controller.rb +11 -11
  10. data/app/controllers/spree/api/images_controller.rb +13 -13
  11. data/app/controllers/spree/api/inventory_units_controller.rb +4 -4
  12. data/app/controllers/spree/api/line_items_controller.rb +27 -23
  13. data/app/controllers/spree/api/option_types_controller.rb +6 -5
  14. data/app/controllers/spree/api/option_values_controller.rb +12 -12
  15. data/app/controllers/spree/api/orders_controller.rb +6 -17
  16. data/app/controllers/spree/api/payments_controller.rb +15 -17
  17. data/app/controllers/spree/api/product_properties_controller.rb +13 -14
  18. data/app/controllers/spree/api/products_controller.rb +31 -28
  19. data/app/controllers/spree/api/promotions_controller.rb +9 -8
  20. data/app/controllers/spree/api/properties_controller.rb +9 -10
  21. data/app/controllers/spree/api/resource_controller.rb +9 -1
  22. data/app/controllers/spree/api/shipments_controller.rb +18 -18
  23. data/app/controllers/spree/api/states_controller.rb +8 -7
  24. data/app/controllers/spree/api/stock_items_controller.rb +2 -1
  25. data/app/controllers/spree/api/stock_locations_controller.rb +1 -1
  26. data/app/controllers/spree/api/stores_controller.rb +0 -1
  27. data/app/controllers/spree/api/taxonomies_controller.rb +7 -5
  28. data/app/controllers/spree/api/taxons_controller.rb +20 -19
  29. data/app/controllers/spree/api/users_controller.rb +1 -4
  30. data/app/controllers/spree/api/variants_controller.rb +19 -18
  31. data/app/controllers/spree/api/zones_controller.rb +3 -4
  32. data/app/helpers/spree/api/api_helpers.rb +7 -6
  33. data/app/models/spree/api_configuration.rb +1 -1
  34. data/app/views/spree/api/config/show.v1.rabl +2 -1
  35. data/app/views/spree/api/products/show.v1.rabl +1 -1
  36. data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +1 -1
  37. data/db/migrate/20120411123334_resize_api_key_field.rb +1 -1
  38. data/lib/spree/api/engine.rb +8 -8
  39. data/lib/spree/api/responders/rabl_template.rb +1 -1
  40. data/lib/spree/api/testing_support/caching.rb +4 -4
  41. data/script/rails +0 -1
  42. data/solidus_api.gemspec +3 -3
  43. data/spec/controllers/spree/api/addresses_controller_spec.rb +12 -13
  44. data/spec/controllers/spree/api/base_controller_spec.rb +10 -11
  45. data/spec/controllers/spree/api/checkouts_controller_spec.rb +38 -59
  46. data/spec/controllers/spree/api/config_controller_spec.rb +4 -2
  47. data/spec/controllers/spree/api/countries_controller_spec.rb +5 -5
  48. data/spec/controllers/spree/api/credit_cards_controller_spec.rb +5 -5
  49. data/spec/controllers/spree/api/images_controller_spec.rb +20 -18
  50. data/spec/controllers/spree/api/inventory_units_controller_spec.rb +11 -11
  51. data/spec/controllers/spree/api/line_items_controller_spec.rb +20 -19
  52. data/spec/controllers/spree/api/option_types_controller_spec.rb +23 -24
  53. data/spec/controllers/spree/api/option_values_controller_spec.rb +28 -29
  54. data/spec/controllers/spree/api/orders_controller_spec.rb +157 -179
  55. data/spec/controllers/spree/api/payments_controller_spec.rb +35 -45
  56. data/spec/controllers/spree/api/product_properties_controller_spec.rb +14 -15
  57. data/spec/controllers/spree/api/products_controller_spec.rb +64 -70
  58. data/spec/controllers/spree/api/promotion_application_spec.rb +4 -4
  59. data/spec/controllers/spree/api/promotions_controller_spec.rb +1 -1
  60. data/spec/controllers/spree/api/properties_controller_spec.rb +15 -15
  61. data/spec/controllers/spree/api/resource_controller_spec.rb +31 -2
  62. data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +31 -31
  63. data/spec/controllers/spree/api/shipments_controller_spec.rb +6 -8
  64. data/spec/controllers/spree/api/states_controller_spec.rb +11 -12
  65. data/spec/controllers/spree/api/stock_items_controller_spec.rb +10 -7
  66. data/spec/controllers/spree/api/stock_locations_controller_spec.rb +3 -4
  67. data/spec/controllers/spree/api/stock_movements_controller_spec.rb +2 -3
  68. data/spec/controllers/spree/api/store_credit_events_controller_spec.rb +0 -2
  69. data/spec/controllers/spree/api/stores_controller_spec.rb +1 -2
  70. data/spec/controllers/spree/api/taxonomies_controller_spec.rb +17 -18
  71. data/spec/controllers/spree/api/taxons_controller_spec.rb +22 -24
  72. data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +1 -2
  73. data/spec/controllers/spree/api/users_controller_spec.rb +13 -15
  74. data/spec/controllers/spree/api/variants_controller_spec.rb +42 -37
  75. data/spec/controllers/spree/api/zones_controller_spec.rb +18 -18
  76. data/spec/features/checkout_spec.rb +2 -2
  77. data/spec/models/spree/legacy_user_spec.rb +5 -5
  78. data/spec/requests/api/address_books_spec.rb +10 -11
  79. data/spec/requests/rabl_cache_spec.rb +7 -7
  80. data/spec/requests/ransackable_attributes_spec.rb +5 -7
  81. data/spec/shared_examples/protect_product_actions.rb +3 -4
  82. data/spec/spec_helper.rb +8 -4
  83. data/spec/support/controller_hacks.rb +5 -5
  84. data/spec/support/have_attributes_matcher.rb +0 -4
  85. data/spec/test_views/spree/api/widgets/show.v1.rabl +1 -1
  86. metadata +9 -10
  87. data/app/models/spree/option_value_decorator.rb +0 -9
@@ -1,7 +1,6 @@
1
1
  module Spree
2
2
  module Api
3
3
  class PaymentsController < Spree::Api::BaseController
4
-
5
4
  before_filter :find_order
6
5
  around_filter :lock_order, only: [:create, :update, :destroy, :authorize, :capture, :purchase, :void, :credit]
7
6
  before_filter :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void, :credit]
@@ -17,7 +16,6 @@ module Spree
17
16
  end
18
17
 
19
18
  def create
20
- @order.validate_payments_attributes(payment_params)
21
19
  @payment = PaymentCreate.new(@order, payment_params).build
22
20
  if @payment.save
23
21
  respond_with(@payment, status: 201, default_template: :show)
@@ -59,24 +57,24 @@ module Spree
59
57
 
60
58
  private
61
59
 
62
- def find_order
63
- @order = Spree::Order.find_by(number: order_id)
64
- authorize! :read, @order, order_token
65
- end
60
+ def find_order
61
+ @order = Spree::Order.find_by(number: order_id)
62
+ authorize! :read, @order, order_token
63
+ end
66
64
 
67
- def find_payment
68
- @payment = @order.payments.find(params[:id])
69
- end
65
+ def find_payment
66
+ @payment = @order.payments.find(params[:id])
67
+ end
70
68
 
71
- def perform_payment_action(action, *args)
72
- authorize! action, Payment
73
- @payment.send("#{action}!", *args)
74
- respond_with(@payment, default_template: :show)
75
- end
69
+ def perform_payment_action(action, *args)
70
+ authorize! action, Payment
71
+ @payment.send("#{action}!", *args)
72
+ respond_with(@payment, default_template: :show)
73
+ end
76
74
 
77
- def payment_params
78
- params.require(:payment).permit(permitted_payment_attributes)
79
- end
75
+ def payment_params
76
+ params.require(:payment).permit(permitted_payment_attributes)
77
+ end
80
78
  end
81
79
  end
82
80
  end
@@ -1,7 +1,6 @@
1
1
  module Spree
2
2
  module Api
3
3
  class ProductPropertiesController < Spree::Api::BaseController
4
-
5
4
  before_action :find_product
6
5
  before_action :product_property, only: [:show, :update, :destroy]
7
6
 
@@ -51,22 +50,22 @@ module Spree
51
50
 
52
51
  private
53
52
 
54
- def find_product
55
- @product = super(params[:product_id])
56
- authorize! :read, @product
57
- end
53
+ def find_product
54
+ @product = super(params[:product_id])
55
+ authorize! :read, @product
56
+ end
58
57
 
59
- def product_property
60
- if @product
61
- @product_property ||= @product.product_properties.find_by(id: params[:id])
62
- @product_property ||= @product.product_properties.includes(:property).where(spree_properties: { name: params[:id] }).first
63
- authorize! :read, @product_property
64
- end
58
+ def product_property
59
+ if @product
60
+ @product_property ||= @product.product_properties.find_by(id: params[:id])
61
+ @product_property ||= @product.product_properties.includes(:property).where(spree_properties: { name: params[:id] }).first
62
+ authorize! :read, @product_property
65
63
  end
64
+ end
66
65
 
67
- def product_property_params
68
- params.require(:product_property).permit(permitted_product_properties_attributes)
69
- end
66
+ def product_property_params
67
+ params.require(:product_property).permit(permitted_product_properties_attributes)
68
+ end
70
69
  end
71
70
  end
72
71
  end
@@ -1,7 +1,6 @@
1
1
  module Spree
2
2
  module Api
3
3
  class ProductsController < Spree::Api::BaseController
4
-
5
4
  def index
6
5
  if params[:ids]
7
6
  ids = params[:ids].split(",").flatten
@@ -11,14 +10,17 @@ module Spree
11
10
  end
12
11
 
13
12
  @products = @products.distinct.page(params[:page]).per(params[:per_page])
14
- expires_in 15.minutes, :public => true
13
+ expires_in 15.minutes, public: true
15
14
  headers['Surrogate-Control'] = "max-age=#{15.minutes}"
16
15
  respond_with(@products)
17
16
  end
18
17
 
18
+ def new
19
+ end
20
+
19
21
  def show
20
22
  @product = find_product(params[:id])
21
- expires_in 15.minutes, :public => true
23
+ expires_in 15.minutes, public: true
22
24
  headers['Surrogate-Control'] = "max-age=#{15.minutes}"
23
25
  headers['Surrogate-Key'] = "product_id=1"
24
26
  respond_with(@product)
@@ -90,40 +92,41 @@ module Spree
90
92
  @product = find_product(params[:id])
91
93
  authorize! :destroy, @product
92
94
  @product.destroy
93
- respond_with(@product, :status => 204)
95
+ respond_with(@product, status: 204)
94
96
  end
95
97
 
96
98
  private
97
- def product_params
98
- product_params = params.require(:product).permit(permitted_product_attributes)
99
- if product_params[:taxon_ids].present?
100
- product_params[:taxon_ids] = product_params[:taxon_ids].split(',')
101
- end
102
- product_params
103
- end
104
-
105
- def variants_params
106
- variants_key = if params[:product].has_key? :variants
107
- :variants
108
- else
109
- :variants_attributes
110
- end
111
99
 
112
- params.require(:product).permit(
113
- variants_key => [permitted_variant_attributes, :id],
114
- ).delete(variants_key) || []
100
+ def product_params
101
+ product_params = params.require(:product).permit(permitted_product_attributes)
102
+ if product_params[:taxon_ids].present?
103
+ product_params[:taxon_ids] = product_params[:taxon_ids].split(',')
115
104
  end
105
+ product_params
106
+ end
116
107
 
117
- def option_types_params
118
- params[:product].fetch(:option_types, [])
108
+ def variants_params
109
+ variants_key = if params[:product].key? :variants
110
+ :variants
111
+ else
112
+ :variants_attributes
119
113
  end
120
114
 
121
- def set_up_shipping_category
122
- if shipping_category = params[:product].delete(:shipping_category)
123
- id = ShippingCategory.find_or_create_by(name: shipping_category).id
124
- params[:product][:shipping_category_id] = id
125
- end
115
+ params.require(:product).permit(
116
+ variants_key => [permitted_variant_attributes, :id]
117
+ ).delete(variants_key) || []
118
+ end
119
+
120
+ def option_types_params
121
+ params[:product].fetch(:option_types, [])
122
+ end
123
+
124
+ def set_up_shipping_category
125
+ if shipping_category = params[:product].delete(:shipping_category)
126
+ id = ShippingCategory.find_or_create_by(name: shipping_category).id
127
+ params[:product][:shipping_category_id] = id
126
128
  end
129
+ end
127
130
  end
128
131
  end
129
132
  end
@@ -12,15 +12,16 @@ module Spree
12
12
  end
13
13
  end
14
14
 
15
- private
16
- def requires_admin
17
- return if @current_user_roles.include?("admin")
18
- unauthorized and return
19
- end
15
+ private
20
16
 
21
- def load_promotion
22
- @promotion = Spree::Promotion.find_by_id(params[:id]) || Spree::Promotion.with_coupon_code(params[:id])
23
- end
17
+ def requires_admin
18
+ return if @current_user_roles.include?("admin")
19
+ unauthorized && return
20
+ end
21
+
22
+ def load_promotion
23
+ @promotion = Spree::Promotion.find_by_id(params[:id]) || Spree::Promotion.with_coupon_code(params[:id])
24
+ end
24
25
  end
25
26
  end
26
27
  end
@@ -1,7 +1,6 @@
1
1
  module Spree
2
2
  module Api
3
3
  class PropertiesController < Spree::Api::BaseController
4
-
5
4
  before_action :find_property, only: [:show, :update, :destroy]
6
5
 
7
6
  def index
@@ -9,7 +8,7 @@ module Spree
9
8
 
10
9
  if params[:ids]
11
10
  ids = params[:ids].split(",").flatten
12
- @properties = @properties.where(:id => ids)
11
+ @properties = @properties.where(id: ids)
13
12
  else
14
13
  @properties = @properties.ransack(params[:q]).result
15
14
  end
@@ -57,15 +56,15 @@ module Spree
57
56
 
58
57
  private
59
58
 
60
- def find_property
61
- @property = Spree::Property.accessible_by(current_ability, :read).find(params[:id])
62
- rescue ActiveRecord::RecordNotFound
63
- @property = Spree::Property.accessible_by(current_ability, :read).find_by!(name: params[:id])
64
- end
59
+ def find_property
60
+ @property = Spree::Property.accessible_by(current_ability, :read).find(params[:id])
61
+ rescue ActiveRecord::RecordNotFound
62
+ @property = Spree::Property.accessible_by(current_ability, :read).find_by!(name: params[:id])
63
+ end
65
64
 
66
- def property_params
67
- params.require(:property).permit(permitted_property_attributes)
68
- end
65
+ def property_params
66
+ params.require(:property).permit(permitted_property_attributes)
67
+ end
69
68
  end
70
69
  end
71
70
  end
@@ -2,7 +2,15 @@ class Spree::Api::ResourceController < Spree::Api::BaseController
2
2
  before_action :load_resource, only: [:show, :update, :destroy]
3
3
 
4
4
  def index
5
- @collection = model_class.accessible_by(current_ability, :read).ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
5
+ collection_scope = model_class.accessible_by(current_ability, :read)
6
+ if params[:ids]
7
+ ids = params[:ids].split(",").flatten
8
+ collection_scope = collection_scope.where(id: ids)
9
+ else
10
+ collection_scope = collection_scope.ransack(params[:q]).result
11
+ end
12
+
13
+ @collection = collection_scope.page(params[:page]).per(params[:per_page])
6
14
  instance_variable_set("@#{controller_name}", @collection)
7
15
 
8
16
  respond_with(@collection)
@@ -12,7 +12,7 @@ module Spree
12
12
  @shipments = Spree::Shipment
13
13
  .reverse_chronological
14
14
  .joins(:order)
15
- .where(spree_orders: {user_id: current_api_user.id})
15
+ .where(spree_orders: { user_id: current_api_user.id })
16
16
  .includes(mine_includes)
17
17
  .ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
18
18
  else
@@ -21,7 +21,7 @@ module Spree
21
21
  end
22
22
 
23
23
  def create
24
- # TODO Can remove conditional here once deprecated #find_order is removed.
24
+ # TODO: Can remove conditional here once deprecated #find_order is removed.
25
25
  unless @order.present?
26
26
  @order = Spree::Order.find_by!(number: params[:shipment][:order_id])
27
27
  authorize! :read, @order
@@ -29,7 +29,7 @@ module Spree
29
29
  authorize! :create, Shipment
30
30
  quantity = params[:quantity].to_i
31
31
  @shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))
32
- @order.contents.add(variant, quantity, {shipment: @shipment})
32
+ @order.contents.add(variant, quantity, { shipment: @shipment })
33
33
 
34
34
  @shipment.save!
35
35
 
@@ -48,7 +48,7 @@ module Spree
48
48
  @shipment.ready!
49
49
  else
50
50
  logger.error("cannot_ready_shipment shipment_state=#{@shipment.state}")
51
- render 'spree/api/shipments/cannot_ready_shipment', status: 422 and return
51
+ render('spree/api/shipments/cannot_ready_shipment', status: 422) && return
52
52
  end
53
53
  end
54
54
  respond_with(@shipment, default_template: :show)
@@ -66,7 +66,7 @@ module Spree
66
66
  def add
67
67
  quantity = params[:quantity].to_i
68
68
 
69
- @shipment.order.contents.add(variant, quantity, {shipment: @shipment})
69
+ @shipment.order.contents.add(variant, quantity, { shipment: @shipment })
70
70
  respond_with(@shipment, default_template: :show)
71
71
  end
72
72
 
@@ -74,7 +74,7 @@ module Spree
74
74
  quantity = params[:quantity].to_i
75
75
 
76
76
  if @shipment.pending?
77
- @shipment.order.contents.remove(variant, quantity, {shipment: @shipment})
77
+ @shipment.order.contents.remove(variant, quantity, { shipment: @shipment })
78
78
  @shipment.reload if @shipment.persisted?
79
79
  respond_with(@shipment, default_template: :show)
80
80
  else
@@ -86,13 +86,13 @@ module Spree
86
86
  def transfer_to_location
87
87
  @stock_location = Spree::StockLocation.find(params[:stock_location_id])
88
88
  @original_shipment.transfer_to_location(@variant, @quantity, @stock_location)
89
- render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201
89
+ render json: { success: true, message: Spree.t(:shipment_transfer_success) }, status: 201
90
90
  end
91
91
 
92
92
  def transfer_to_shipment
93
93
  @target_shipment = Spree::Shipment.find_by!(number: params[:target_shipment_number])
94
94
  @original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)
95
- render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201
95
+ render json: { success: true, message: Spree.t(:shipment_transfer_success) }, status: 201
96
96
  end
97
97
 
98
98
  private
@@ -107,7 +107,7 @@ module Spree
107
107
  end
108
108
 
109
109
  def find_order_on_create
110
- # TODO Can remove conditional here once deprecated #find_order is removed.
110
+ # TODO: Can remove conditional here once deprecated #find_order is removed.
111
111
  unless @order.present?
112
112
  @order = Spree::Order.find_by!(number: params[:shipment][:order_id])
113
113
  authorize! :read, @order
@@ -146,31 +146,31 @@ module Spree
146
146
  order: {
147
147
  bill_address: {
148
148
  state: {},
149
- country: {},
149
+ country: {}
150
150
  },
151
151
  ship_address: {
152
152
  state: {},
153
- country: {},
153
+ country: {}
154
154
  },
155
155
  adjustments: {},
156
156
  payments: {
157
157
  order: {},
158
- payment_method: {},
159
- },
158
+ payment_method: {}
159
+ }
160
160
  },
161
161
  inventory_units: {
162
162
  line_item: {
163
163
  product: {},
164
- variant: {},
164
+ variant: {}
165
165
  },
166
166
  variant: {
167
167
  product: {},
168
168
  default_price: {},
169
169
  option_values: {
170
- option_type: {},
171
- },
172
- },
173
- },
170
+ option_type: {}
171
+ }
172
+ }
173
+ }
174
174
  }
175
175
  end
176
176
  end
@@ -20,14 +20,15 @@ module Spree
20
20
  end
21
21
 
22
22
  private
23
- def scope
24
- if params[:country_id]
25
- @country = Country.accessible_by(current_ability, :read).find(params[:country_id])
26
- return @country.states.accessible_by(current_ability, :read)
27
- else
28
- return State.accessible_by(current_ability, :read)
29
- end
23
+
24
+ def scope
25
+ if params[:country_id]
26
+ @country = Country.accessible_by(current_ability, :read).find(params[:country_id])
27
+ return @country.states.accessible_by(current_ability, :read)
28
+ else
29
+ return State.accessible_by(current_ability, :read)
30
30
  end
31
+ end
31
32
  end
32
33
  end
33
34
  end
@@ -58,11 +58,12 @@ module Spree
58
58
  end
59
59
 
60
60
  def scope
61
- includes = {:variant => [{ :option_values => :option_type }, :product] }
61
+ includes = { variant: [{ option_values: :option_type }, :product] }
62
62
  @stock_location.stock_items.accessible_by(current_ability, :read).includes(includes)
63
63
  end
64
64
 
65
65
  def stock_item_params
66
+ params.require(:stock_item).delete(:force)
66
67
  params.require(:stock_item).permit(permitted_stock_item_attributes)
67
68
  end
68
69
 
@@ -33,7 +33,7 @@ module Spree
33
33
  def destroy
34
34
  authorize! :destroy, stock_location
35
35
  stock_location.destroy
36
- respond_with(stock_location, :status => 204)
36
+ respond_with(stock_location, status: 204)
37
37
  end
38
38
 
39
39
  private
@@ -1,7 +1,6 @@
1
1
  module Spree
2
2
  module Api
3
3
  class StoresController < Spree::Api::BaseController
4
-
5
4
  before_filter :get_store, except: [:index, :create]
6
5
 
7
6
  def index
@@ -1,11 +1,13 @@
1
1
  module Spree
2
2
  module Api
3
3
  class TaxonomiesController < Spree::Api::BaseController
4
-
5
4
  def index
6
5
  respond_with(taxonomies)
7
6
  end
8
7
 
8
+ def new
9
+ end
10
+
9
11
  def show
10
12
  respond_with(taxonomy)
11
13
  end
@@ -19,7 +21,7 @@ module Spree
19
21
  authorize! :create, Taxonomy
20
22
  @taxonomy = Taxonomy.new(taxonomy_params)
21
23
  if @taxonomy.save
22
- respond_with(@taxonomy, :status => 201, :default_template => :show)
24
+ respond_with(@taxonomy, status: 201, default_template: :show)
23
25
  else
24
26
  invalid_resource!(@taxonomy)
25
27
  end
@@ -28,7 +30,7 @@ module Spree
28
30
  def update
29
31
  authorize! :update, taxonomy
30
32
  if taxonomy.update_attributes(taxonomy_params)
31
- respond_with(taxonomy, :status => 200, :default_template => :show)
33
+ respond_with(taxonomy, status: 200, default_template: :show)
32
34
  else
33
35
  invalid_resource!(taxonomy)
34
36
  end
@@ -37,13 +39,13 @@ module Spree
37
39
  def destroy
38
40
  authorize! :destroy, taxonomy
39
41
  taxonomy.destroy
40
- respond_with(taxonomy, :status => 204)
42
+ respond_with(taxonomy, status: 204)
41
43
  end
42
44
 
43
45
  private
44
46
 
45
47
  def taxonomies
46
- @taxonomies = Taxonomy.accessible_by(current_ability, :read).order('name').includes(:root => :children).
48
+ @taxonomies = Taxonomy.accessible_by(current_ability, :read).order('name').includes(root: :children).
47
49
  ransack(params[:q]).result.
48
50
  page(params[:page]).per(params[:per_page])
49
51
  end
@@ -4,18 +4,19 @@ module Spree
4
4
  def index
5
5
  if taxonomy
6
6
  @taxons = taxonomy.root.children
7
+ elsif params[:ids]
8
+ @taxons = Spree::Taxon.accessible_by(current_ability, :read).where(id: params[:ids].split(','))
7
9
  else
8
- if params[:ids]
9
- @taxons = Spree::Taxon.accessible_by(current_ability, :read).where(id: params[:ids].split(','))
10
- else
11
- @taxons = Spree::Taxon.accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
12
- end
10
+ @taxons = Spree::Taxon.accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
13
11
  end
14
12
 
15
13
  @taxons = @taxons.page(params[:page]).per(params[:per_page])
16
14
  respond_with(@taxons)
17
15
  end
18
16
 
17
+ def new
18
+ end
19
+
19
20
  def show
20
21
  @taxon = taxon
21
22
  respond_with(@taxon)
@@ -33,7 +34,7 @@ module Spree
33
34
 
34
35
  if taxonomy.nil?
35
36
  @taxon.errors[:taxonomy_id] = I18n.t(:invalid_taxonomy_id, scope: 'spree.api')
36
- invalid_resource!(@taxon) and return
37
+ invalid_resource!(@taxon) && return
37
38
  end
38
39
 
39
40
  @taxon.parent_id = taxonomy.root.id unless params[:taxon][:parent_id]
@@ -71,23 +72,23 @@ module Spree
71
72
 
72
73
  private
73
74
 
74
- def taxonomy
75
- if params[:taxonomy_id].present?
76
- @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:taxonomy_id])
77
- end
75
+ def taxonomy
76
+ if params[:taxonomy_id].present?
77
+ @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:taxonomy_id])
78
78
  end
79
+ end
79
80
 
80
- def taxon
81
- @taxon ||= taxonomy.taxons.accessible_by(current_ability, :read).find(params[:id])
82
- end
81
+ def taxon
82
+ @taxon ||= taxonomy.taxons.accessible_by(current_ability, :read).find(params[:id])
83
+ end
83
84
 
84
- def taxon_params
85
- if params[:taxon] && !params[:taxon].empty?
86
- params.require(:taxon).permit(permitted_taxon_attributes)
87
- else
88
- {}
89
- end
85
+ def taxon_params
86
+ if params[:taxon] && !params[:taxon].empty?
87
+ params.require(:taxon).permit(permitted_taxon_attributes)
88
+ else
89
+ {}
90
90
  end
91
+ end
91
92
  end
92
93
  end
93
94
  end
@@ -1,10 +1,7 @@
1
1
  class Spree::Api::UsersController < Spree::Api::ResourceController
2
-
3
2
  private
4
3
 
5
- def user
6
- @user
7
- end
4
+ attr_reader :user
8
5
 
9
6
  def model_class
10
7
  Spree.user_class
@@ -47,29 +47,30 @@ module Spree
47
47
  end
48
48
 
49
49
  private
50
- def product
51
- @product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id]
52
- end
53
-
54
- def scope
55
- if @product
56
- variants = @product.variants_including_master
57
- else
58
- variants = Variant
59
- end
60
50
 
61
- if current_ability.can?(:manage, Variant) && params[:show_deleted]
62
- variants = variants.with_deleted
63
- end
51
+ def product
52
+ @product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id]
53
+ end
64
54
 
65
- variants = variants.accessible_by(current_ability, :read)
66
- variants = variants.in_stock if params[:in_stock_only] || cannot?(:view_out_of_stock, Spree::Variant)
67
- variants
55
+ def scope
56
+ if @product
57
+ variants = @product.variants_including_master
58
+ else
59
+ variants = Variant
68
60
  end
69
61
 
70
- def variant_params
71
- params.require(:variant).permit(permitted_variant_attributes)
62
+ if current_ability.can?(:manage, Variant) && params[:show_deleted]
63
+ variants = variants.with_deleted
72
64
  end
65
+
66
+ variants = variants.accessible_by(current_ability, :read)
67
+ variants = variants.in_stock if params[:in_stock_only] || cannot?(:view_out_of_stock, Spree::Variant)
68
+ variants
69
+ end
70
+
71
+ def variant_params
72
+ params.require(:variant).permit(permitted_variant_attributes)
73
+ end
73
74
  end
74
75
  end
75
76
  end
@@ -1,12 +1,11 @@
1
1
  module Spree
2
2
  module Api
3
3
  class ZonesController < Spree::Api::BaseController
4
-
5
4
  def create
6
5
  authorize! :create, Zone
7
6
  @zone = Zone.new(zone_params)
8
7
  if @zone.save
9
- respond_with(@zone, :status => 201, :default_template => :show)
8
+ respond_with(@zone, status: 201, default_template: :show)
10
9
  else
11
10
  invalid_resource!(@zone)
12
11
  end
@@ -15,7 +14,7 @@ module Spree
15
14
  def destroy
16
15
  authorize! :destroy, zone
17
16
  zone.destroy
18
- respond_with(zone, :status => 204)
17
+ respond_with(zone, status: 204)
19
18
  end
20
19
 
21
20
  def index
@@ -30,7 +29,7 @@ module Spree
30
29
  def update
31
30
  authorize! :update, zone
32
31
  if zone.update_attributes(zone_params)
33
- respond_with(zone, :status => 200, :default_template => :show)
32
+ respond_with(zone, status: 200, default_template: :show)
34
33
  else
35
34
  invalid_resource!(zone)
36
35
  end