solidus_api 3.4.6 → 4.0.0

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: 64a1451f72d82e35895d4f45c14eaaf010358673e067d5a6e7d82d9a5853bb3e
4
- data.tar.gz: 0fcc29a38729acbe7e06455dea0cf8ef80e87bc65039f76c1f50fcb2ab49307b
3
+ metadata.gz: 889a03ceedfdc041802ee129c1be2a2aba750d8d6501757f09ecc5cf26da2662
4
+ data.tar.gz: 912510a11207bda356602e8bf5d98780b95aaf88b556bfad714c1393392f3ada
5
5
  SHA512:
6
- metadata.gz: 472b014de96424ec71e6c60f1a046463f784e3412317bb2194a6c6e3876f07ffd40a21938491dab0fc025a7a355b236c266a28b8004e8ddc28f6dde1d57a3eb3
7
- data.tar.gz: 5e6ced5e85efd0c56e2a906ac1a2cd0d4787816044fffc669ea45c5a5e51173f52bb20e88e2f2ce4bd46b1d7b190775eb9d377100e1bd080640c3a6773cce1fd
6
+ metadata.gz: 66890843cd4957ff345aec5ff633b28c5f7224d9171ec027062943ac0cdf2df43db1be12d861c73c5b5a6399330b62b5b70706791f097a09c0046e6ea99c3761
7
+ data.tar.gz: 9fd9b5e9c7d8e774f31637e62177662c9fb1c597e1a085ce7192c2b0d52001486a83ce63050fbc9ecb24b71fe2f6a68d6bd440501b8d970f345388e8ef76b484
data/Rakefile CHANGED
@@ -5,7 +5,6 @@ require 'rake'
5
5
  require 'rake/testtask'
6
6
  require 'rspec/core/rake_task'
7
7
  require 'spree/testing_support/dummy_app/rake_tasks'
8
- require 'bundler/gem_tasks'
9
8
 
10
9
  RSpec::Core::RakeTask.new
11
10
  task default: :spec
@@ -69,14 +69,6 @@ module Spree
69
69
  return_items_params = customer_return_attributes.
70
70
  delete(:return_items_attributes)
71
71
 
72
- if return_items_params.is_a? ActionController::Parameters
73
- return_items_params = return_items_params.values
74
- Spree::Deprecation.warn(
75
- "Passing `return_items_attributes` as a hash of hashes is \
76
- deprecated and will be removed in future versions of Solidus."
77
- )
78
- end
79
-
80
72
  @customer_return = CustomerReturn.new(customer_return_attributes)
81
73
 
82
74
  @customer_return.return_items = return_items_params.map do |item_params|
@@ -13,20 +13,11 @@ module Spree
13
13
  end
14
14
 
15
15
  def show
16
- warn_if_nested_member_route
17
-
18
16
  @option_value = scope.find(params[:id])
19
17
  respond_with(@option_value)
20
18
  end
21
19
 
22
20
  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
-
30
21
  authorize! :create, Spree::OptionValue
31
22
  @option_value = scope.new(option_value_params)
32
23
  if @option_value.save
@@ -37,8 +28,6 @@ module Spree
37
28
  end
38
29
 
39
30
  def update
40
- warn_if_nested_member_route
41
-
42
31
  @option_value = scope.accessible_by(current_ability, :update).find(params[:id])
43
32
  if @option_value.update(option_value_params)
44
33
  render :show
@@ -48,8 +37,6 @@ module Spree
48
37
  end
49
38
 
50
39
  def destroy
51
- warn_if_nested_member_route
52
-
53
40
  @option_value = scope.accessible_by(current_ability, :destroy).find(params[:id])
54
41
  @option_value.destroy
55
42
  render plain: nil, status: 204
@@ -68,14 +55,6 @@ module Spree
68
55
  def option_value_params
69
56
  params.require(:option_value).permit(permitted_option_value_attributes)
70
57
  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
79
58
  end
80
59
  end
81
60
  end
@@ -40,30 +40,8 @@ module Spree
40
40
 
41
41
  def create
42
42
  authorize! :create, Shipment
43
-
44
43
  @shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))
45
44
 
46
- if passing_deprecated_params_on_create?
47
- Spree::Deprecation.warn <<~MSG
48
- Passing `quantity` or `variant_id` to
49
-
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
45
  respond_with(@shipment, default_template: :show)
68
46
  end
69
47
 
@@ -149,10 +127,6 @@ module Spree
149
127
  authorize! :create, Shipment
150
128
  end
151
129
 
152
- def passing_deprecated_params_on_create?
153
- params[:variant_id] || params[:quantity]
154
- end
155
-
156
130
  def find_order_on_create
157
131
  @order = Spree::Order.find_by!(number: params[:shipment][:order_id])
158
132
  authorize! :show, @order
@@ -6,12 +6,6 @@ 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
-
15
9
  authorize! :create, Variant
16
10
  @variant = scope.new(variant_params)
17
11
  if @variant.save
@@ -22,8 +16,6 @@ module Spree
22
16
  end
23
17
 
24
18
  def destroy
25
- warn_if_nested_member_route
26
-
27
19
  @variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
28
20
  @variant.discard
29
21
  respond_with(@variant, status: 204)
@@ -50,16 +42,12 @@ module Spree
50
42
  end
51
43
 
52
44
  def show
53
- warn_if_nested_member_route
54
-
55
45
  @variant = scope.includes(include_list)
56
46
  .find(params[:id])
57
47
  respond_with(@variant)
58
48
  end
59
49
 
60
50
  def update
61
- warn_if_nested_member_route
62
-
63
51
  @variant = scope.accessible_by(current_ability, :update).find(params[:id])
64
52
  if @variant.update(variant_params)
65
53
  respond_with(@variant, status: 200, default_template: :show)
@@ -70,14 +58,6 @@ module Spree
70
58
 
71
59
  private
72
60
 
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
-
81
61
  def product
82
62
  @product ||= Spree::Product.accessible_by(current_ability, :show).friendly.find(params[:product_id]) if params[:product_id]
83
63
  end
@@ -41,11 +41,6 @@ module Spree
41
41
  define_method attribute do
42
42
  Spree::Api::Config.send(attribute)
43
43
  end
44
-
45
- define_singleton_method attribute do
46
- Spree::Deprecation.warn("Please use Spree::Api::Config::#{attribute} instead.")
47
- Spree::Api::Config.send(attribute)
48
- end
49
44
  end
50
45
 
51
46
  def required_fields_for(model)
data/config/routes.rb CHANGED
@@ -54,12 +54,9 @@ Spree::Core::Engine.routes.draw do
54
54
  end
55
55
 
56
56
  resources :option_types do
57
- # TODO: Use shallow option on Solidus v4.0
58
- resources :option_values
57
+ resources :option_values, shallow: true
59
58
  end
60
- # TODO: Use only: :index on Solidus v4.0 and use shallow option on the nested routes
61
- # within option_types
62
- resources :option_values
59
+ resources :option_values, only: :index
63
60
 
64
61
  get '/orders/mine', to: 'orders#mine', as: 'my_orders'
65
62
  get "/orders/current", to: "orders#current", as: "current_order"
@@ -114,7 +114,7 @@ module Spree
114
114
 
115
115
  preference :promotion_attributes, :array, default: [
116
116
  :id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,
117
- :match_policy, :advertise, :path
117
+ :advertise, :path
118
118
  ]
119
119
 
120
120
  preference :store_attributes, :array, default: [
@@ -667,121 +667,6 @@ paths:
667
667
  properties:
668
668
  image:
669
669
  $ref: '#/components/schemas/image-input'
670
- '/products/{product_id}/variants/{id}':
671
- get:
672
- responses:
673
- '200':
674
- description: ''
675
- content:
676
- application/json:
677
- schema:
678
- $ref: '#/components/schemas/variant'
679
- '401':
680
- $ref: '#/components/responses/invalid-api-key'
681
- '404':
682
- $ref: '#/components/responses/not-found'
683
- summary: Get product variant
684
- description: |-
685
- **Deprecation Warning**: Use [shallow version](/docs/solidus/87df124706c5f-get-variant) instead
686
-
687
- Retrieves a product's variant.
688
- operationId: get-product-variant
689
- tags:
690
- - Variants
691
- security:
692
- - api-key: []
693
- parameters:
694
- - name: product_id
695
- in: path
696
- required: true
697
- schema:
698
- type: string
699
- - name: id
700
- in: path
701
- required: true
702
- schema:
703
- type: string
704
- delete:
705
- responses:
706
- '204':
707
- description: ''
708
- content:
709
- application/json:
710
- schema:
711
- $ref: '#/components/schemas/variant'
712
- '401':
713
- $ref: '#/components/responses/invalid-api-key'
714
- '404':
715
- $ref: '#/components/responses/not-found'
716
- '422':
717
- $ref: '#/components/responses/delete-restriction'
718
- summary: Delete product variant
719
- description: |-
720
- **Deprecation Warning**: Use [shallow version](/docs/solidus/82ccaada99139-delete-variant) instead
721
-
722
- Deletes a product's variant.
723
- operationId: delete-product-variant
724
- tags:
725
- - Variants
726
- security:
727
- - api-key: []
728
- put:
729
- responses:
730
- '200':
731
- description: ''
732
- content:
733
- application/json:
734
- schema:
735
- $ref: '#/components/schemas/variant'
736
- '401':
737
- $ref: '#/components/responses/invalid-api-key'
738
- '404':
739
- $ref: '#/components/responses/not-found'
740
- '422':
741
- $ref: '#/components/responses/unprocessable-entity'
742
- summary: Update product variant
743
- description: |-
744
- **Deprecation Warning**: Use [shallow version](/docs/solidus/ce338b5f3b940-update-variant) instead
745
-
746
- Updates a product's variant.
747
- operationId: update-product-variant
748
- tags:
749
- - Variants
750
- security:
751
- - api-key: []
752
- requestBody:
753
- content:
754
- application/json:
755
- schema:
756
- type: object
757
- properties:
758
- variant:
759
- $ref: '#/components/schemas/variant-input'
760
- examples:
761
- Example with Option Value Ids:
762
- value:
763
- variant:
764
- price: '11.22'
765
- cost_price: '9'
766
- position: 1
767
- track_inventory: true
768
- sku: AWSOME-1122
769
- cost_currency: USD
770
- option_value_ids:
771
- - 1
772
- - 2
773
- Example with Option Value Text:
774
- value:
775
- variant:
776
- price: '11.22'
777
- cost_price: '9'
778
- position: 1
779
- track_inventory: true
780
- sku: AWSOME-1122
781
- cost_currency: USD
782
- options:
783
- name: Color
784
- value: White
785
670
  /states:
786
671
  get:
787
672
  responses:
@@ -852,65 +737,6 @@ paths:
852
737
  - $ref: '#/components/parameters/q'
853
738
  security:
854
739
  - api-key: []
855
- post:
856
- responses:
857
- '200':
858
- description: ''
859
- content:
860
- application/json:
861
- schema:
862
- $ref: '#/components/schemas/variant'
863
- '401':
864
- $ref: '#/components/responses/invalid-api-key'
865
- '422':
866
- $ref: '#/components/responses/unprocessable-entity'
867
- summary: Create variant
868
- description: |-
869
- **Deprecation Warning**: Use [nested version](/docs/solidus/681aa6cb75b1e-create-product-variant) instead
870
-
871
- Creates a variant. Only users with `can :create, Variant` permissions can perform this action.
872
- operationId: create-variant
873
- tags:
874
- - Variants
875
- security:
876
- - api-key: []
877
- requestBody:
878
- content:
879
- application/json:
880
- schema:
881
- type: object
882
- properties:
883
- product_id:
884
- type: integer
885
- variant:
886
- $ref: '#/components/schemas/variant-input'
887
- examples:
888
- Example with Option Value Ids:
889
- value:
890
- product_id: 1
891
- variant:
892
- price: '11.22'
893
- cost_price: '9'
894
- position: 1
895
- track_inventory: true
896
- sku: AWSOME-1122
897
- cost_currency: USD
898
- option_value_ids:
899
- - 1
900
- - 2
901
- Example with Option Value Text:
902
- value:
903
- product_id: 1
904
- variant:
905
- price: '11.22'
906
- cost_price: '9'
907
- position: 1
908
- track_inventory: true
909
- sku: AWSOME-1122
910
- cost_currency: USD
911
- options:
912
- name: Color
913
- value: White
914
740
  '/variants/{id}':
915
741
  get:
916
742
  responses:
@@ -2541,38 +2367,6 @@ paths:
2541
2367
  - Option values
2542
2368
  security:
2543
2369
  - api-key: []
2544
- post:
2545
- responses:
2546
- '200':
2547
- description: ''
2548
- content:
2549
- application/json:
2550
- schema:
2551
- $ref: '#/components/schemas/option-value'
2552
- '401':
2553
- $ref: '#/components/responses/invalid-api-key'
2554
- '422':
2555
- $ref: '#/components/responses/unprocessable-entity'
2556
- summary: Create option value
2557
- description: |-
2558
- **Deprecation Warning**: Use [nested version](/docs/solidus/810154673c613-create-option-type-value) instead
2559
-
2560
- Creates an option value.
2561
-
2562
- Only users with the `create` permission on `Spree::OptionValue` can perform this action.
2563
- operationId: create-option-value
2564
- tags:
2565
- - Option values
2566
- security:
2567
- - api-key: []
2568
- requestBody:
2569
- content:
2570
- application/json:
2571
- schema:
2572
- type: object
2573
- properties:
2574
- option_value:
2575
- $ref: '#/components/schemas/option-value-input'
2576
2370
  '/option_values/{id}':
2577
2371
  get:
2578
2372
  responses:
@@ -2715,99 +2509,6 @@ paths:
2715
2509
  properties:
2716
2510
  option_value:
2717
2511
  $ref: '#/components/schemas/option-value-input'
2718
- '/option_types/{option_type_id}/option_values/{id}':
2719
- get:
2720
- responses:
2721
- '200':
2722
- description: ''
2723
- content:
2724
- application/json:
2725
- schema: {}
2726
- '401':
2727
- $ref: '#/components/responses/invalid-api-key'
2728
- '404':
2729
- $ref: '#/components/responses/not-found'
2730
- summary: Get option type value
2731
- description: |-
2732
- **Deprecation Warning**: Use [shallow version](/docs/solidus/cbbc403ed08a3-get-option-value) instead
2733
-
2734
- Retrieves an option type's value.
2735
- operationId: get-option-type-value
2736
- tags:
2737
- - Option values
2738
- security:
2739
- - api-key: []
2740
- parameters:
2741
- - name: option_type_id
2742
- in: path
2743
- required: true
2744
- schema:
2745
- type: string
2746
- description: 'The ID of the Spree::OptionType'
2747
- - name: id
2748
- in: path
2749
- required: true
2750
- schema:
2751
- type: string
2752
- description: The ID of the OptionValue
2753
- delete:
2754
- responses:
2755
- '204':
2756
- description: ''
2757
- content:
2758
- application/json:
2759
- schema:
2760
- $ref: '#/components/schemas/option-value'
2761
- '401':
2762
- $ref: '#/components/responses/invalid-api-key'
2763
- '404':
2764
- $ref: '#/components/responses/not-found'
2765
- '422':
2766
- $ref: '#/components/responses/delete-restriction'
2767
- summary: Delete option type value
2768
- description: |-
2769
- **Deprecation Warning**: Use [shallow version](/docs/solidus/0742e63219b1f-delete-option-value) instead
2770
-
2771
- Deletes an option type's value.
2772
- operationId: delete-option-type-value
2773
- tags:
2774
- - Option values
2775
- security:
2776
- - api-key: []
2777
- patch:
2778
- responses:
2779
- '200':
2780
- description: ''
2781
- content:
2782
- application/json:
2783
- schema:
2784
- $ref: '#/components/schemas/option-value'
2785
- '401':
2786
- $ref: '#/components/responses/invalid-api-key'
2787
- '404':
2788
- $ref: '#/components/responses/not-found'
2789
- '422':
2790
- $ref: '#/components/responses/unprocessable-entity'
2791
- summary: Update option type value
2792
- description: |-
2793
- **Deprecation Warning**: Use [shallow version](/docs/solidus/b43f889175ebb-update-option-value) instead
2794
-
2795
- Updates an option type's value.
2796
-
2797
- Only users with the `update` permission on the option value can perform this action.
2798
- operationId: update-option-type-value
2799
- tags:
2800
- - Option values
2801
- security:
2802
- - api-key: []
2803
- requestBody:
2804
- content:
2805
- application/json:
2806
- schema:
2807
- type: object
2808
- properties:
2809
- option_value:
2810
- $ref: '#/components/schemas/option-value-input'
2811
2512
  '/products/{product_id}/product_properties':
2812
2513
  get:
2813
2514
  responses:
@@ -5589,10 +5290,6 @@ paths:
5589
5290
  Creates a shipment.
5590
5291
 
5591
5292
  Please note that this request can be only performed by users with the `create` permission on the shipment.
5592
-
5593
- **Deprecation Warning**: Adding items to the shipment via this endpoint
5594
- is deprecated. Instead, create an empty shipment and populate it with
5595
- the dedicated endpoint [to add items to the shipment](/docs/solidus/7078dbcf415ac-add-shipment-item).
5596
5293
  operationId: create-shipment
5597
5294
  tags:
5598
5295
  - Shipments
@@ -5606,18 +5303,10 @@ paths:
5606
5303
  properties:
5607
5304
  stock_location_id:
5608
5305
  type: integer
5609
- variant_id:
5610
- type: integer
5611
- deprecated: true
5612
- quantity:
5613
- type: integer
5614
- deprecated: true
5615
5306
  examples:
5616
5307
  Example:
5617
5308
  value:
5618
5309
  stock_location_id: 0
5619
- variant_id: 0
5620
- quantity: 0
5621
5310
  /shipments/transfer_to_location:
5622
5311
  post:
5623
5312
  responses:
data/solidus_api.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  f.match(%r{^(spec|script)/})
21
21
  end
22
22
 
23
- s.required_ruby_version = '>= 2.7.0'
23
+ s.required_ruby_version = '>= 3.0.0'
24
24
  s.required_rubygems_version = '>= 1.8.23'
25
25
 
26
26
  s.add_dependency 'jbuilder', '~> 2.8'
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.4.6
4
+ version: 4.0.0
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-11-02 00:00:00.000000000 Z
11
+ date: 2023-05-08 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.4.6
61
+ version: 4.0.0
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.4.6
68
+ version: 4.0.0
69
69
  description: REST API for the Solidus e-commerce framework.
70
70
  email: contact@solidus.io
71
71
  executables: []
@@ -97,7 +97,6 @@ files:
97
97
  - app/controllers/spree/api/products_controller.rb
98
98
  - app/controllers/spree/api/promotions_controller.rb
99
99
  - app/controllers/spree/api/properties_controller.rb
100
- - app/controllers/spree/api/resource_controller.rb
101
100
  - app/controllers/spree/api/return_authorizations_controller.rb
102
101
  - app/controllers/spree/api/shipments_controller.rb
103
102
  - app/controllers/spree/api/states_controller.rb
@@ -258,7 +257,7 @@ licenses:
258
257
  - BSD-3-Clause
259
258
  metadata:
260
259
  rubygems_mfa_required: 'true'
261
- post_install_message:
260
+ post_install_message:
262
261
  rdoc_options: []
263
262
  require_paths:
264
263
  - lib
@@ -266,15 +265,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
265
  requirements:
267
266
  - - ">="
268
267
  - !ruby/object:Gem::Version
269
- version: 2.7.0
268
+ version: 3.0.0
270
269
  required_rubygems_version: !ruby/object:Gem::Requirement
271
270
  requirements:
272
271
  - - ">="
273
272
  - !ruby/object:Gem::Version
274
273
  version: 1.8.23
275
274
  requirements: []
276
- rubygems_version: 3.4.17
277
- signing_key:
275
+ rubygems_version: 3.4.9
276
+ signing_key:
278
277
  specification_version: 4
279
278
  summary: REST API for the Solidus e-commerce framework.
280
279
  test_files: []
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @deprecated Inherit directly from Spree::Api::BaseController
4
- class Spree::Api::ResourceController < Spree::Api::BaseController
5
- before_action :load_resource, only: [:show, :update, :destroy]
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
-
15
- def index
16
- collection_scope = model_class.accessible_by(current_ability)
17
- if params[:ids]
18
- ids = params[:ids].split(",").flatten
19
- collection_scope = collection_scope.where(id: ids)
20
- else
21
- collection_scope = collection_scope.ransack(params[:q]).result
22
- end
23
-
24
- @collection = paginate(collection_scope)
25
- instance_variable_set("@#{controller_name}", @collection)
26
-
27
- respond_with(@collection)
28
- end
29
-
30
- def show
31
- respond_with(@object)
32
- end
33
-
34
- def new
35
- authorize! :new, model_class
36
- respond_with(model_class.new)
37
- end
38
-
39
- def create
40
- authorize! :create, model_class
41
-
42
- @object = model_class.new(permitted_resource_params)
43
- instance_variable_set("@#{object_name}", @object)
44
-
45
- if @object.save
46
- respond_with(@object, status: 201, default_template: :show)
47
- else
48
- invalid_resource!(@object)
49
- end
50
- end
51
-
52
- def update
53
- authorize! :update, @object
54
-
55
- if @object.update(permitted_resource_params)
56
- respond_with(@object, status: 200, default_template: :show)
57
- else
58
- invalid_resource!(@object)
59
- end
60
- end
61
-
62
- def destroy
63
- authorize! :destroy, @object
64
-
65
- destroy_result = if @object.respond_to?(:discard)
66
- @object.discard
67
- else
68
- @object.destroy
69
- end
70
-
71
- if destroy_result
72
- respond_with(@object, status: 204)
73
- else
74
- invalid_resource!(@object)
75
- end
76
- rescue ActiveRecord::DeleteRestrictionError
77
- render "spree/api/errors/delete_restriction", status: 422
78
- end
79
-
80
- protected
81
-
82
- def load_resource
83
- @object = model_class.accessible_by(current_ability, :show).find(params[:id])
84
- instance_variable_set("@#{object_name}", @object)
85
- end
86
-
87
- def permitted_resource_params
88
- params.require(object_name).permit(permitted_resource_attributes)
89
- end
90
-
91
- def permitted_resource_attributes
92
- send("permitted_#{object_name}_attributes")
93
- end
94
-
95
- def model_class
96
- "Spree::#{controller_name.classify}".constantize
97
- end
98
-
99
- def object_name
100
- controller_name.singularize
101
- end
102
- end