solidus_api 3.1.9 → 3.2.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b92406c37b41f49753572e2aa6ab74e778feae4ef10afabe5596f0bd9ca70a68
4
- data.tar.gz: ee352d9fa6437d00cc099afe2ad52a6d8a92d322f8ec374036e95af485a1a047
3
+ metadata.gz: 954e041b1916b7b90a18bd23c5b62f826589f6c46e6477b9431ab5d581d02252
4
+ data.tar.gz: 7b2a66b3131d9b5af5d705e59ae6f55a586fce678af50b6f631d9863061a0483
5
5
  SHA512:
6
- metadata.gz: 5b59195e06ebd6917b003253503881ab98a49fdb388adafc7c58a38a30b0fc511262af98f2c850ade528717ad119a6aea6b20195c0de09e73a132fbfaceba868
7
- data.tar.gz: 37ce6153242f6b636a88b2a558d6b66c5ea19340af731092b1ba4cd4247cfbbf2cdcd779e0034547705f9799f82b403303731c290de787e59144555394e76ba6
6
+ metadata.gz: 11ee74a464094ebee9e038019956e7bb0fb6c7e8fd1bc2fba2efd22932bc4c50bb4335ccdaedf641a982575cc1a3f829abaa44200f8049ba3bca021043827a4a
7
+ data.tar.gz: ae8e2be6b2454c85ce930b1ab884af06493dd5ae3c3db308c5489d4f42d610e712b61257342a00cc795e67170c6a832e48ae3cbe42f7a600cc00b80d74e1b9c8
data/README.md CHANGED
@@ -40,5 +40,5 @@ version is released.
40
40
  easily extend it with the endpoints provided by your Solidus extensions!
41
41
 
42
42
  [docs-dir]: https://github.com/solidusio/solidus/tree/master/api/openapi
43
- [live-docs]: https://solidus.docs.stoplight.io
43
+ [live-docs]: https://solidus.stoplight.io
44
44
  [studio]: https://stoplight.io/p/studio
@@ -13,11 +13,20 @@ module Spree
13
13
  end
14
14
 
15
15
  def show
16
+ warn_if_nested_member_route
17
+
16
18
  @option_value = scope.find(params[:id])
17
19
  respond_with(@option_value)
18
20
  end
19
21
 
20
22
  def create
23
+ Spree::Deprecation.warn <<~MSG unless request.path.include?('/option_types/')
24
+ This route is deprecated, as it'll be no longer possible to create an
25
+ option_value without an associated option_type. Please, use instead:
26
+
27
+ POST api/option_types/{option_type_id}/option_values
28
+ MSG
29
+
21
30
  authorize! :create, Spree::OptionValue
22
31
  @option_value = scope.new(option_value_params)
23
32
  if @option_value.save
@@ -28,6 +37,8 @@ module Spree
28
37
  end
29
38
 
30
39
  def update
40
+ warn_if_nested_member_route
41
+
31
42
  @option_value = scope.accessible_by(current_ability, :update).find(params[:id])
32
43
  if @option_value.update(option_value_params)
33
44
  render :show
@@ -37,6 +48,8 @@ module Spree
37
48
  end
38
49
 
39
50
  def destroy
51
+ warn_if_nested_member_route
52
+
40
53
  @option_value = scope.accessible_by(current_ability, :destroy).find(params[:id])
41
54
  @option_value.destroy
42
55
  render plain: nil, status: 204
@@ -55,6 +68,14 @@ module Spree
55
68
  def option_value_params
56
69
  params.require(:option_value).permit(permitted_option_value_attributes)
57
70
  end
71
+
72
+ def warn_if_nested_member_route
73
+ Spree::Deprecation.warn <<~MSG if request.path.include?('/option_types/')
74
+ This route is deprecated. Use shallow version instead:
75
+
76
+ #{request.method.upcase} api/option_values/:id
77
+ MSG
78
+ end
58
79
  end
59
80
  end
60
81
  end
@@ -1,8 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # @deprecated Inherit directly from Spree::Api::BaseController
3
4
  class Spree::Api::ResourceController < Spree::Api::BaseController
4
5
  before_action :load_resource, only: [:show, :update, :destroy]
5
6
 
7
+ def self.inherited(klass)
8
+ Spree::Deprecation.warn <<~MSG
9
+ Spree::Api::ResourceController is deprecated. Please, copy any logic you
10
+ need and inherit directly from Spree::Api::BaseController.
11
+ MSG
12
+ super
13
+ end
14
+
6
15
  def index
7
16
  collection_scope = model_class.accessible_by(current_ability)
8
17
  if params[:ids]
@@ -40,13 +40,31 @@ module Spree
40
40
 
41
41
  def create
42
42
  authorize! :create, Shipment
43
- quantity = params[:quantity].to_i
43
+
44
44
  @shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))
45
- @order.contents.add(variant, quantity, { shipment: @shipment })
46
45
 
47
- @shipment.save!
46
+ if passing_deprecated_params_on_create?
47
+ Spree::Deprecation.warn <<~MSG
48
+ Passing `quantity` or `variant_id` to
48
49
 
49
- respond_with(@shipment.reload, default_template: :show)
50
+ POST /api/shipments
51
+
52
+ is deprecated and won't be allowed anymore starting from Solidus 4.0.
53
+ Instead, create an empty shipment and add items to it subsequently using
54
+ the dedicated endpoint:
55
+
56
+ PUT /api/shipments/{shipment_number}/add
57
+
58
+ MSG
59
+
60
+ quantity = params[:quantity].to_i
61
+ variant = Spree::Variant.unscoped.find(params[:variant_id])
62
+ @order.contents.add(variant, quantity, { shipment: @shipment })
63
+ @shipment.save!
64
+ @shipment.reload
65
+ end
66
+
67
+ respond_with(@shipment, default_template: :show)
50
68
  end
51
69
 
52
70
  def update
@@ -130,6 +148,10 @@ module Spree
130
148
  authorize! :create, Shipment
131
149
  end
132
150
 
151
+ def passing_deprecated_params_on_create?
152
+ params[:variant_id] || params[:quantity]
153
+ end
154
+
133
155
  def find_order_on_create
134
156
  @order = Spree::Order.find_by!(number: params[:shipment][:order_id])
135
157
  authorize! :show, @order
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Spree::Api::UsersController < Spree::Api::ResourceController
3
+ class Spree::Api::UsersController < Spree::Api::BaseController
4
+ before_action :load_resource, only: [:show, :update, :destroy]
5
+
4
6
  def index
5
- user_scope = model_class.accessible_by(current_ability, :show)
7
+ user_scope = user_class.accessible_by(current_ability, :show)
6
8
  if params[:ids]
7
9
  ids = params[:ids].split(",").flatten
8
10
  @users = user_scope.where(id: ids)
@@ -14,20 +16,71 @@ class Spree::Api::UsersController < Spree::Api::ResourceController
14
16
  respond_with(@users)
15
17
  end
16
18
 
17
- private
19
+ def show
20
+ respond_with(@user)
21
+ end
22
+
23
+ def new
24
+ authorize! :new, user_class
25
+ respond_with(user_class.new)
26
+ end
27
+
28
+ def create
29
+ authorize! :create, user_class
30
+
31
+ @user = user_class.new(permitted_user_params)
18
32
 
19
- attr_reader :user
33
+ if @user.save
34
+ respond_with(@user, status: 201, default_template: :show)
35
+ else
36
+ invalid_resource!(@user)
37
+ end
38
+ end
39
+
40
+ def update
41
+ authorize! :update, @user
20
42
 
21
- def model_class
43
+ if @user.update(permitted_user_params)
44
+ respond_with(@user, status: 200, default_template: :show)
45
+ else
46
+ invalid_resource!(@user)
47
+ end
48
+ end
49
+
50
+ def destroy
51
+ authorize! :destroy, @user
52
+
53
+ destroy_result = if @user.respond_to?(:discard)
54
+ @user.discard
55
+ else
56
+ @user.destroy
57
+ end
58
+
59
+ if destroy_result
60
+ respond_with(@user, status: 204)
61
+ else
62
+ invalid_resource!(@user)
63
+ end
64
+ rescue ActiveRecord::DeleteRestrictionError
65
+ render "spree/api/errors/delete_restriction", status: 422
66
+ end
67
+
68
+ private
69
+
70
+ def user_class
22
71
  Spree.user_class
23
72
  end
24
73
 
25
- def user_params
26
- permitted_resource_params
74
+ def load_resource
75
+ @user = user_class.accessible_by(current_ability, :show).find(params[:id])
76
+ end
77
+
78
+ def permitted_user_params
79
+ params.require(:user).permit(permitted_user_attributes)
27
80
  end
28
81
 
29
- def permitted_resource_attributes
30
- if action_name == "create" || can?(:update_email, user)
82
+ def permitted_user_attributes
83
+ if action_name == "create" || can?(:update_email, @user)
31
84
  super | [:email]
32
85
  else
33
86
  super
@@ -6,6 +6,12 @@ module Spree
6
6
  before_action :product
7
7
 
8
8
  def create
9
+ Spree::Deprecation.warn <<~MSG unless request.path.include?('/products/')
10
+ This route is deprecated. Use the route nested within the product resource:
11
+
12
+ POST api/products/{product_id}/variants
13
+ MSG
14
+
9
15
  authorize! :create, Variant
10
16
  @variant = scope.new(variant_params)
11
17
  if @variant.save
@@ -16,6 +22,8 @@ module Spree
16
22
  end
17
23
 
18
24
  def destroy
25
+ warn_if_nested_member_route
26
+
19
27
  @variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
20
28
  @variant.discard
21
29
  respond_with(@variant, status: 204)
@@ -25,8 +33,14 @@ module Spree
25
33
  # we render on the view so we better update it any time a node is included
26
34
  # or removed from the views.
27
35
  def index
28
- @variants = scope.includes(include_list)
29
- .ransack(params[:q]).result
36
+ @variants =
37
+ if params[:variant_search_term]
38
+ Spree::Config.variant_search_class.new(
39
+ params[:variant_search_term], scope: scope
40
+ ).results.includes(include_list)
41
+ else
42
+ scope.includes(include_list).ransack(params[:q]).result
43
+ end
30
44
 
31
45
  @variants = paginate(@variants)
32
46
  respond_with(@variants)
@@ -36,12 +50,16 @@ module Spree
36
50
  end
37
51
 
38
52
  def show
53
+ warn_if_nested_member_route
54
+
39
55
  @variant = scope.includes(include_list)
40
56
  .find(params[:id])
41
57
  respond_with(@variant)
42
58
  end
43
59
 
44
60
  def update
61
+ warn_if_nested_member_route
62
+
45
63
  @variant = scope.accessible_by(current_ability, :update).find(params[:id])
46
64
  if @variant.update(variant_params)
47
65
  respond_with(@variant, status: 200, default_template: :show)
@@ -52,6 +70,14 @@ module Spree
52
70
 
53
71
  private
54
72
 
73
+ def warn_if_nested_member_route
74
+ Spree::Deprecation.warn <<~MSG if request.path.include?('/products/')
75
+ This route is deprecated. Use shallow version instead:
76
+
77
+ #{request.method.upcase} api/variants/:id
78
+ MSG
79
+ end
80
+
55
81
  def product
56
82
  @product ||= Spree::Product.accessible_by(current_ability, :show).friendly.find(params[:product_id]) if params[:product_id]
57
83
  end
data/config/routes.rb CHANGED
@@ -12,10 +12,16 @@ Spree::Core::Engine.routes.draw do
12
12
 
13
13
  resources :products do
14
14
  resources :images
15
+ # TODO: Use shallow option on Solidus v4.0
15
16
  resources :variants
16
17
  resources :product_properties
17
18
  end
18
19
 
20
+ # TODO: Use only: :index on Solidus v4.0
21
+ resources :variants do
22
+ resources :images
23
+ end
24
+
19
25
  concern :order_routes do
20
26
  resources :line_items
21
27
  resources :payments do
@@ -47,13 +53,12 @@ Spree::Core::Engine.routes.draw do
47
53
  end
48
54
  end
49
55
 
50
- resources :variants do
51
- resources :images
52
- end
53
-
54
56
  resources :option_types do
57
+ # TODO: Use shallow option on Solidus v4.0
55
58
  resources :option_values
56
59
  end
60
+ # TODO: Use only: :index on Solidus v4.0 and use shallow option on the nested routes
61
+ # within option_types
57
62
  resources :option_values
58
63
 
59
64
  get '/orders/mine', to: 'orders#mine', as: 'my_orders'
@@ -47,7 +47,7 @@ module Spree
47
47
  end
48
48
 
49
49
  def upload_image(filename)
50
- Rack::Test::UploadedFile.new(File.open(image(filename).path), 'image/jpg')
50
+ Rack::Test::UploadedFile.new(File.open(image(filename).path), 'image/jpeg')
51
51
  end
52
52
  end
53
53
  end
@@ -682,7 +682,10 @@ paths:
682
682
  '404':
683
683
  $ref: '#/components/responses/not-found'
684
684
  summary: Get product variant
685
- description: Retrieves a product's variant.
685
+ description: |-
686
+ **Deprecation Warning**: Use [shallow version](/docs/solidus/87df124706c5f-get-variant) instead
687
+
688
+ Retrieves a product's variant.
686
689
  operationId: get-product-variant
687
690
  tags:
688
691
  - Variants
@@ -714,7 +717,10 @@ paths:
714
717
  '422':
715
718
  $ref: '#/components/responses/delete-restriction'
716
719
  summary: Delete product variant
717
- description: Deletes a product's variant.
720
+ description: |-
721
+ **Deprecation Warning**: Use [shallow version](/docs/solidus/82ccaada99139-delete-variant) instead
722
+
723
+ Deletes a product's variant.
718
724
  operationId: delete-product-variant
719
725
  tags:
720
726
  - Variants
@@ -735,7 +741,10 @@ paths:
735
741
  '422':
736
742
  $ref: '#/components/responses/unprocessable-entity'
737
743
  summary: Update product variant
738
- description: Updates a product's variant.
744
+ description: |-
745
+ **Deprecation Warning**: Use [shallow version](/docs/solidus/ce338b5f3b940-update-variant) instead
746
+
747
+ Updates a product's variant.
739
748
  operationId: update-product-variant
740
749
  tags:
741
750
  - Variants
@@ -857,7 +866,10 @@ paths:
857
866
  '422':
858
867
  $ref: '#/components/responses/unprocessable-entity'
859
868
  summary: Create variant
860
- description: 'Creates a variant. Only users with `can :create, Variant` permissions can perform this action.'
869
+ description: |-
870
+ **Deprecation Warning**: Use [nested version](/docs/solidus/681aa6cb75b1e-create-product-variant) instead
871
+
872
+ Creates a variant. Only users with `can :create, Variant` permissions can perform this action.
861
873
  operationId: create-variant
862
874
  tags:
863
875
  - Variants
@@ -2544,6 +2556,8 @@ paths:
2544
2556
  $ref: '#/components/responses/unprocessable-entity'
2545
2557
  summary: Create option value
2546
2558
  description: |-
2559
+ **Deprecation Warning**: Use [nested version](/docs/solidus/810154673c613-create-option-type-value) instead
2560
+
2547
2561
  Creates an option value.
2548
2562
 
2549
2563
  Only users with the `create` permission on `Spree::OptionValue` can perform this action.
@@ -2715,7 +2729,10 @@ paths:
2715
2729
  '404':
2716
2730
  $ref: '#/components/responses/not-found'
2717
2731
  summary: Get option type value
2718
- description: Retrieves an option type's value.
2732
+ description: |-
2733
+ **Deprecation Warning**: Use [shallow version](/docs/solidus/cbbc403ed08a3-get-option-value) instead
2734
+
2735
+ Retrieves an option type's value.
2719
2736
  operationId: get-option-type-value
2720
2737
  tags:
2721
2738
  - Option values
@@ -2749,7 +2766,10 @@ paths:
2749
2766
  '422':
2750
2767
  $ref: '#/components/responses/delete-restriction'
2751
2768
  summary: Delete option type value
2752
- description: Deletes an option type's value.
2769
+ description: |-
2770
+ **Deprecation Warning**: Use [shallow version](/docs/solidus/0742e63219b1f-delete-option-value) instead
2771
+
2772
+ Deletes an option type's value.
2753
2773
  operationId: delete-option-type-value
2754
2774
  tags:
2755
2775
  - Option values
@@ -2771,6 +2791,8 @@ paths:
2771
2791
  $ref: '#/components/responses/unprocessable-entity'
2772
2792
  summary: Update option type value
2773
2793
  description: |-
2794
+ **Deprecation Warning**: Use [shallow version](/docs/solidus/b43f889175ebb-update-option-value) instead
2795
+
2774
2796
  Updates an option type's value.
2775
2797
 
2776
2798
  Only users with the `update` permission on the option value can perform this action.
@@ -5569,6 +5591,10 @@ paths:
5569
5591
  Creates a shipment.
5570
5592
 
5571
5593
  Please note that this request can be only performed by users with the `create` permission on the shipment.
5594
+
5595
+ **Deprecation Warning**: Adding items to the shipment via this endpoint
5596
+ is deprecated. Instead, create an empty shipment and populate it with
5597
+ the dedicated endpoint [to add items to the shipment](/docs/solidus/7078dbcf415ac-add-shipment-item).
5572
5598
  operationId: create-shipment
5573
5599
  tags:
5574
5600
  - Shipments
@@ -5584,8 +5610,10 @@ paths:
5584
5610
  type: integer
5585
5611
  variant_id:
5586
5612
  type: integer
5613
+ deprecated: true
5587
5614
  quantity:
5588
5615
  type: integer
5616
+ deprecated: true
5589
5617
  examples:
5590
5618
  Example:
5591
5619
  value:
@@ -7141,6 +7169,8 @@ components:
7141
7169
  type: boolean
7142
7170
  product_id:
7143
7171
  type: integer
7172
+ tax_category_id:
7173
+ type: integer
7144
7174
  weight:
7145
7175
  type: string
7146
7176
  height:
@@ -7161,6 +7191,23 @@ components:
7161
7191
  type: array
7162
7192
  items:
7163
7193
  $ref: '#/components/schemas/option-value-input'
7194
+ options:
7195
+ weight:
7196
+ type: string
7197
+ height:
7198
+ type: string
7199
+ width:
7200
+ type: string
7201
+ depth:
7202
+ type: string
7203
+ sku:
7204
+ type: string
7205
+ cost_currency:
7206
+ type: string
7207
+ option_value_ids:
7208
+ type: array
7209
+ items:
7210
+ type: integer
7164
7211
  options:
7165
7212
  type: object
7166
7213
  description: '`Name` will be the name/presentation of the option type and `Value` will be the name/presentation of the option value. They will be created if not exist.'
data/solidus_api.gemspec CHANGED
@@ -14,6 +14,8 @@ Gem::Specification.new do |s|
14
14
  s.homepage = 'http://solidus.io'
15
15
  s.license = 'BSD-3-Clause'
16
16
 
17
+ s.metadata['rubygems_mfa_required'] = 'true'
18
+
17
19
  s.files = `git ls-files -z`.split("\x0").reject do |f|
18
20
  f.match(%r{^(spec|script)/})
19
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.9
4
+ version: 3.2.0.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-07 00:00:00.000000000 Z
11
+ date: 2022-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jbuilder
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 3.1.9
61
+ version: 3.2.0.alpha
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 3.1.9
68
+ version: 3.2.0.alpha
69
69
  description: REST API for the Solidus e-commerce framework.
70
70
  email: contact@solidus.io
71
71
  executables: []
@@ -255,8 +255,9 @@ files:
255
255
  homepage: http://solidus.io
256
256
  licenses:
257
257
  - BSD-3-Clause
258
- metadata: {}
259
- post_install_message:
258
+ metadata:
259
+ rubygems_mfa_required: 'true'
260
+ post_install_message:
260
261
  rdoc_options: []
261
262
  require_paths:
262
263
  - lib
@@ -271,8 +272,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
272
  - !ruby/object:Gem::Version
272
273
  version: 1.8.23
273
274
  requirements: []
274
- rubygems_version: 3.3.7
275
- signing_key:
275
+ rubygems_version: 3.1.2
276
+ signing_key:
276
277
  specification_version: 4
277
278
  summary: REST API for the Solidus e-commerce framework.
278
279
  test_files: []