spree_api 3.1.14 → 3.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/app/controllers/spree/api/base_controller.rb +2 -2
- data/app/controllers/spree/api/v1/addresses_controller.rb +1 -1
- data/app/controllers/spree/api/v1/classifications_controller.rb +1 -1
- data/app/controllers/spree/api/v1/images_controller.rb +3 -0
- data/app/controllers/spree/api/v1/inventory_units_controller.rb +3 -3
- data/app/controllers/spree/api/v1/line_items_controller.rb +3 -0
- data/app/controllers/spree/api/v1/option_types_controller.rb +16 -7
- data/app/controllers/spree/api/v1/option_values_controller.rb +6 -3
- data/app/controllers/spree/api/v1/orders_controller.rb +13 -24
- data/app/controllers/spree/api/v1/payments_controller.rb +0 -1
- data/app/controllers/spree/api/v1/products_controller.rb +8 -5
- data/app/controllers/spree/api/v1/stock_items_controller.rb +1 -1
- data/app/controllers/spree/api/v1/stock_locations_controller.rb +1 -1
- data/app/controllers/spree/api/v1/tags_controller.rb +28 -0
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +7 -4
- data/app/controllers/spree/api/v1/taxons_controller.rb +4 -1
- data/app/controllers/spree/api/v1/users_controller.rb +5 -3
- data/app/controllers/spree/api/v1/zones_controller.rb +3 -3
- data/app/helpers/spree/api/api_helpers.rb +4 -1
- data/app/models/spree/api_configuration.rb +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/countries/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/line_items/show.v1.rabl +2 -2
- data/app/views/spree/api/v1/option_types/show.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/payment.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/show.v1.rabl +9 -9
- data/app/views/spree/api/v1/payments/credit_over_limit.v1.rabl +1 -1
- data/app/views/spree/api/v1/payments/update_forbidden.v1.rabl +1 -1
- data/app/views/spree/api/v1/products/show.v1.rabl +5 -5
- data/app/views/spree/api/v1/shipments/cannot_ready_shipment.v1.rabl +1 -1
- data/app/views/spree/api/v1/shipments/show.v1.rabl +7 -7
- data/app/views/spree/api/v1/shipments/small.v1.rabl +8 -8
- data/app/views/spree/api/v1/tags/index.v1.rabl +9 -0
- data/app/views/spree/api/v1/taxonomies/jstree.rabl +2 -2
- data/app/views/spree/api/v1/taxonomies/nested.v1.rabl +2 -2
- data/app/views/spree/api/v1/taxons/jstree.rabl +3 -3
- data/app/views/spree/api/v1/taxons/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/taxons/taxons.v1.rabl +1 -1
- data/app/views/spree/api/v1/users/show.v1.rabl +3 -2
- data/app/views/spree/api/v1/variants/big.v1.rabl +3 -3
- data/app/views/spree/api/v1/variants/small.v1.rabl +3 -2
- data/app/views/spree/api/v1/zones/show.v1.rabl +1 -1
- data/config/routes.rb +4 -6
- data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +2 -2
- data/db/migrate/20120411123334_resize_api_key_field.rb +2 -2
- data/db/migrate/20120530054546_rename_api_key_to_spree_api_key.rb +1 -1
- data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +1 -1
- data/lib/spree/api/engine.rb +11 -3
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- data/lib/spree/api/testing_support/caching.rb +2 -2
- data/spec/controllers/spree/api/base_controller_spec.rb +96 -0
- data/spec/controllers/spree/api/v1/addresses_controller_spec.rb +56 -0
- data/spec/controllers/spree/api/v1/checkouts_controller_spec.rb +363 -0
- data/spec/controllers/spree/api/v1/classifications_controller_spec.rb +48 -0
- data/spec/controllers/spree/api/v1/countries_controller_spec.rb +48 -0
- data/spec/controllers/spree/api/v1/credit_cards_controller_spec.rb +80 -0
- data/spec/controllers/spree/api/v1/images_controller_spec.rb +114 -0
- data/spec/controllers/spree/api/v1/inventory_units_controller_spec.rb +48 -0
- data/spec/controllers/spree/api/v1/line_items_controller_spec.rb +203 -0
- data/spec/controllers/spree/api/v1/option_types_controller_spec.rb +122 -0
- data/spec/controllers/spree/api/v1/option_values_controller_spec.rb +141 -0
- data/spec/controllers/spree/api/v1/orders_controller_spec.rb +735 -0
- data/spec/controllers/spree/api/v1/payments_controller_spec.rb +234 -0
- data/spec/controllers/spree/api/v1/product_properties_controller_spec.rb +147 -0
- data/spec/controllers/spree/api/v1/products_controller_spec.rb +409 -0
- data/spec/controllers/spree/api/v1/promotion_application_spec.rb +50 -0
- data/spec/controllers/spree/api/v1/promotions_controller_spec.rb +64 -0
- data/spec/controllers/spree/api/v1/properties_controller_spec.rb +102 -0
- data/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb +161 -0
- data/spec/controllers/spree/api/v1/shipments_controller_spec.rb +187 -0
- data/spec/controllers/spree/api/v1/states_controller_spec.rb +86 -0
- data/spec/controllers/spree/api/v1/stock_items_controller_spec.rb +143 -0
- data/spec/controllers/spree/api/v1/stock_locations_controller_spec.rb +113 -0
- data/spec/controllers/spree/api/v1/stock_movements_controller_spec.rb +84 -0
- data/spec/controllers/spree/api/v1/stores_controller_spec.rb +133 -0
- data/spec/controllers/spree/api/v1/tags_controller_spec.rb +102 -0
- data/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb +114 -0
- data/spec/controllers/spree/api/v1/taxons_controller_spec.rb +177 -0
- data/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb +26 -0
- data/spec/controllers/spree/api/v1/users_controller_spec.rb +153 -0
- data/spec/controllers/spree/api/v1/variants_controller_spec.rb +205 -0
- data/spec/controllers/spree/api/v1/zones_controller_spec.rb +91 -0
- data/spec/models/spree/legacy_user_spec.rb +19 -0
- data/spec/requests/rabl_cache_spec.rb +32 -0
- data/spec/requests/ransackable_attributes_spec.rb +79 -0
- data/spec/requests/version_spec.rb +19 -0
- data/spec/shared_examples/protect_product_actions.rb +17 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/support/controller_hacks.rb +40 -0
- data/spec/support/database_cleaner.rb +14 -0
- data/spec/support/have_attributes_matcher.rb +13 -0
- data/spree_api.gemspec +7 -4
- metadata +99 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0263d4468e9dfa57da8fde935f0cb2b26fe8d7a0
|
4
|
+
data.tar.gz: 903c3bb494e975188c0ef6fa81440c15a8246096
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b052fff311b035d3324120f57643106450c26020eb8dcb93afdabea084b9904f2b9f0a18a41f53eb87d4fee50aa980bdc4fce0cfb30015ce066768b089d4edd
|
7
|
+
data.tar.gz: 881171f4e20c1a08c6cce5fc8de20d571f8e896645e9d73053429625371b11991bc7fe3f6b3d3ad105160913457030b9e7625251c5ae96e58cf302c7b9d47e91
|
data/Gemfile
CHANGED
@@ -25,7 +25,7 @@ module Spree
|
|
25
25
|
|
26
26
|
def map_nested_attributes_keys(klass, attributes)
|
27
27
|
nested_keys = klass.nested_attributes_options.keys
|
28
|
-
attributes.inject({}) do |h, (k,v)|
|
28
|
+
attributes.to_h.inject({}) do |h, (k,v)|
|
29
29
|
key = nested_keys.include?(k.to_sym) ? "#{k}_attributes" : k
|
30
30
|
h[key] = v
|
31
31
|
h
|
@@ -89,7 +89,7 @@ module Spree
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def unprocessable_entity(message)
|
92
|
-
render
|
92
|
+
render plain: { exception: message }.to_json, status: 422
|
93
93
|
end
|
94
94
|
|
95
95
|
def gateway_error(exception)
|
@@ -15,7 +15,7 @@ module Spree
|
|
15
15
|
inventory_unit.transaction do
|
16
16
|
if inventory_unit.update_attributes(inventory_unit_params)
|
17
17
|
fire
|
18
|
-
render :show, :
|
18
|
+
render :show, status: 200
|
19
19
|
else
|
20
20
|
invalid_resource!(inventory_unit)
|
21
21
|
end
|
@@ -35,8 +35,8 @@ module Spree
|
|
35
35
|
|
36
36
|
unless inventory_unit.respond_to?(can_event) &&
|
37
37
|
inventory_unit.send(can_event)
|
38
|
-
render :
|
39
|
-
:
|
38
|
+
render plain: { exception: "cannot transition to #{@event}" }.to_json,
|
39
|
+
status: 200
|
40
40
|
false
|
41
41
|
end
|
42
42
|
end
|
@@ -3,11 +3,17 @@ module Spree
|
|
3
3
|
module V1
|
4
4
|
class OptionTypesController < Spree::Api::BaseController
|
5
5
|
def index
|
6
|
-
if params[:ids]
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
@option_types = if params[:ids]
|
7
|
+
Spree::OptionType.
|
8
|
+
includes(:option_values).
|
9
|
+
accessible_by(current_ability, :read).
|
10
|
+
where(id: params[:ids].split(','))
|
11
|
+
else
|
12
|
+
Spree::OptionType.
|
13
|
+
includes(:option_values).
|
14
|
+
accessible_by(current_ability, :read).
|
15
|
+
load.ransack(params[:q]).result
|
16
|
+
end
|
11
17
|
respond_with(@option_types)
|
12
18
|
end
|
13
19
|
|
@@ -16,11 +22,14 @@ module Spree
|
|
16
22
|
respond_with(@option_type)
|
17
23
|
end
|
18
24
|
|
25
|
+
def new
|
26
|
+
end
|
27
|
+
|
19
28
|
def create
|
20
29
|
authorize! :create, Spree::OptionType
|
21
30
|
@option_type = Spree::OptionType.new(option_type_params)
|
22
31
|
if @option_type.save
|
23
|
-
render :show, :
|
32
|
+
render :show, status: 201
|
24
33
|
else
|
25
34
|
invalid_resource!(@option_type)
|
26
35
|
end
|
@@ -38,7 +47,7 @@ module Spree
|
|
38
47
|
def destroy
|
39
48
|
@option_type = Spree::OptionType.accessible_by(current_ability, :destroy).find(params[:id])
|
40
49
|
@option_type.destroy
|
41
|
-
render :
|
50
|
+
render plain: nil, status: 204
|
42
51
|
end
|
43
52
|
|
44
53
|
private
|
@@ -4,7 +4,7 @@ module Spree
|
|
4
4
|
class OptionValuesController < Spree::Api::BaseController
|
5
5
|
def index
|
6
6
|
if params[:ids]
|
7
|
-
@option_values = scope.where(:
|
7
|
+
@option_values = scope.where(id: params[:ids])
|
8
8
|
else
|
9
9
|
@option_values = scope.ransack(params[:q]).result.distinct
|
10
10
|
end
|
@@ -16,11 +16,14 @@ module Spree
|
|
16
16
|
respond_with(@option_value)
|
17
17
|
end
|
18
18
|
|
19
|
+
def new
|
20
|
+
end
|
21
|
+
|
19
22
|
def create
|
20
23
|
authorize! :create, Spree::OptionValue
|
21
24
|
@option_value = scope.new(option_value_params)
|
22
25
|
if @option_value.save
|
23
|
-
render :show, :
|
26
|
+
render :show, status: 201
|
24
27
|
else
|
25
28
|
invalid_resource!(@option_value)
|
26
29
|
end
|
@@ -38,7 +41,7 @@ module Spree
|
|
38
41
|
def destroy
|
39
42
|
@option_value = scope.accessible_by(current_ability, :destroy).find(params[:id])
|
40
43
|
@option_value.destroy
|
41
|
-
render :
|
44
|
+
render plain: nil, status: 204
|
42
45
|
end
|
43
46
|
|
44
47
|
private
|
@@ -27,38 +27,27 @@ module Spree
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def create
|
30
|
-
authorize! :create,
|
31
|
-
if
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
37
|
+
import_params = if @current_user_roles.include?("admin")
|
38
|
+
params[:order].present? ? params[:order].permit! : {}
|
48
39
|
else
|
49
|
-
|
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
|
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
|
59
48
|
authorize! :update, @order, order_token
|
60
49
|
@order.empty!
|
61
|
-
render
|
50
|
+
render plain: nil, status: 204
|
62
51
|
end
|
63
52
|
|
64
53
|
def index
|
@@ -11,14 +11,14 @@ module Spree
|
|
11
11
|
end
|
12
12
|
|
13
13
|
@products = @products.distinct.page(params[:page]).per(params[:per_page])
|
14
|
-
expires_in 15.minutes, :
|
14
|
+
expires_in 15.minutes, public: true
|
15
15
|
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
16
16
|
respond_with(@products)
|
17
17
|
end
|
18
18
|
|
19
19
|
def show
|
20
20
|
@product = find_product(params[:id])
|
21
|
-
expires_in 15.minutes, :
|
21
|
+
expires_in 15.minutes, public: true
|
22
22
|
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
23
23
|
headers['Surrogate-Key'] = "product_id=1"
|
24
24
|
respond_with(@product)
|
@@ -57,6 +57,9 @@ module Spree
|
|
57
57
|
# shipping_category: "Free Shipping Items"
|
58
58
|
# }
|
59
59
|
#
|
60
|
+
def new
|
61
|
+
end
|
62
|
+
|
60
63
|
def create
|
61
64
|
authorize! :create, Product
|
62
65
|
params[:product][:available_on] ||= Time.current
|
@@ -66,7 +69,7 @@ module Spree
|
|
66
69
|
@product = Core::Importer::Product.new(nil, product_params, options).create
|
67
70
|
|
68
71
|
if @product.persisted?
|
69
|
-
respond_with(@product, :
|
72
|
+
respond_with(@product, status: 201, default_template: :show)
|
70
73
|
else
|
71
74
|
invalid_resource!(@product)
|
72
75
|
end
|
@@ -80,7 +83,7 @@ module Spree
|
|
80
83
|
@product = Core::Importer::Product.new(@product, product_params, options).update
|
81
84
|
|
82
85
|
if @product.errors.empty?
|
83
|
-
respond_with(@product.reload, :
|
86
|
+
respond_with(@product.reload, status: 200, default_template: :show)
|
84
87
|
else
|
85
88
|
invalid_resource!(@product)
|
86
89
|
end
|
@@ -90,7 +93,7 @@ module Spree
|
|
90
93
|
@product = find_product(params[:id])
|
91
94
|
authorize! :destroy, @product
|
92
95
|
@product.destroy
|
93
|
-
respond_with(@product, :
|
96
|
+
respond_with(@product, status: 204)
|
94
97
|
end
|
95
98
|
|
96
99
|
private
|
@@ -64,7 +64,7 @@ module Spree
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def scope
|
67
|
-
includes = {:
|
67
|
+
includes = { variant: [{ option_values: :option_type }, :product] }
|
68
68
|
@stock_location.stock_items.accessible_by(current_ability, :read).includes(includes)
|
69
69
|
end
|
70
70
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class TagsController < Spree::Api::BaseController
|
5
|
+
def index
|
6
|
+
@tags =
|
7
|
+
if params[:ids]
|
8
|
+
Tag.where(id: params[:ids].split(",").flatten)
|
9
|
+
else
|
10
|
+
Tag.ransack(params[:q]).result
|
11
|
+
end
|
12
|
+
|
13
|
+
@tags = @tags.page(params[:page]).per(params[:per_page])
|
14
|
+
|
15
|
+
expires_in 15.minutes, public: true
|
16
|
+
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
17
|
+
respond_with(@tags)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def tags_params
|
23
|
+
params.require(:tag).permit(permitted_tags_attributes)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -16,11 +16,14 @@ module Spree
|
|
16
16
|
show
|
17
17
|
end
|
18
18
|
|
19
|
+
def new
|
20
|
+
end
|
21
|
+
|
19
22
|
def create
|
20
23
|
authorize! :create, Taxonomy
|
21
24
|
@taxonomy = Taxonomy.new(taxonomy_params)
|
22
25
|
if @taxonomy.save
|
23
|
-
respond_with(@taxonomy, :
|
26
|
+
respond_with(@taxonomy, status: 201, default_template: :show)
|
24
27
|
else
|
25
28
|
invalid_resource!(@taxonomy)
|
26
29
|
end
|
@@ -29,7 +32,7 @@ module Spree
|
|
29
32
|
def update
|
30
33
|
authorize! :update, taxonomy
|
31
34
|
if taxonomy.update_attributes(taxonomy_params)
|
32
|
-
respond_with(taxonomy, :
|
35
|
+
respond_with(taxonomy, status: 200, default_template: :show)
|
33
36
|
else
|
34
37
|
invalid_resource!(taxonomy)
|
35
38
|
end
|
@@ -38,13 +41,13 @@ module Spree
|
|
38
41
|
def destroy
|
39
42
|
authorize! :destroy, taxonomy
|
40
43
|
taxonomy.destroy
|
41
|
-
respond_with(taxonomy, :
|
44
|
+
respond_with(taxonomy, status: 204)
|
42
45
|
end
|
43
46
|
|
44
47
|
private
|
45
48
|
|
46
49
|
def taxonomies
|
47
|
-
@taxonomies = Taxonomy.accessible_by(current_ability, :read).order('name').includes(:
|
50
|
+
@taxonomies = Taxonomy.accessible_by(current_ability, :read).order('name').includes(root: :children).
|
48
51
|
ransack(params[:q]).result.
|
49
52
|
page(params[:page]).per(params[:per_page])
|
50
53
|
end
|
@@ -26,6 +26,9 @@ module Spree
|
|
26
26
|
show
|
27
27
|
end
|
28
28
|
|
29
|
+
def new
|
30
|
+
end
|
31
|
+
|
29
32
|
def create
|
30
33
|
authorize! :create, Taxon
|
31
34
|
@taxon = Spree::Taxon.new(taxon_params)
|
@@ -33,7 +36,7 @@ module Spree
|
|
33
36
|
taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])
|
34
37
|
|
35
38
|
if taxonomy.nil?
|
36
|
-
@taxon.errors
|
39
|
+
@taxon.errors.add(:taxonomy_id, I18n.t('spree.api.invalid_taxonomy_id'))
|
37
40
|
invalid_resource!(@taxon) and return
|
38
41
|
end
|
39
42
|
|
@@ -7,6 +7,8 @@ module Spree
|
|
7
7
|
|
8
8
|
def index
|
9
9
|
@users = Spree.user_class.accessible_by(current_ability,:read).ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
10
|
+
expires_in 15.minutes, public: true
|
11
|
+
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
10
12
|
respond_with(@users)
|
11
13
|
end
|
12
14
|
|
@@ -21,7 +23,7 @@ module Spree
|
|
21
23
|
authorize! :create, Spree.user_class
|
22
24
|
@user = Spree.user_class.new(user_params)
|
23
25
|
if @user.save
|
24
|
-
respond_with(@user, :
|
26
|
+
respond_with(@user, status: 201, default_template: :show)
|
25
27
|
else
|
26
28
|
invalid_resource!(@user)
|
27
29
|
end
|
@@ -30,7 +32,7 @@ module Spree
|
|
30
32
|
def update
|
31
33
|
authorize! :update, user
|
32
34
|
if user.update_attributes(user_params)
|
33
|
-
respond_with(user, :
|
35
|
+
respond_with(user, status: 200, default_template: :show)
|
34
36
|
else
|
35
37
|
invalid_resource!(user)
|
36
38
|
end
|
@@ -39,7 +41,7 @@ module Spree
|
|
39
41
|
def destroy
|
40
42
|
authorize! :destroy, user
|
41
43
|
user.destroy
|
42
|
-
respond_with(user, :
|
44
|
+
respond_with(user, status: 204)
|
43
45
|
end
|
44
46
|
|
45
47
|
private
|