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.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +17 -21
- data/app/controllers/spree/api/v1/countries_controller.rb +2 -4
- data/app/controllers/spree/api/v1/credit_cards_controller.rb +9 -10
- data/app/controllers/spree/api/v1/images_controller.rb +1 -2
- data/app/controllers/spree/api/v1/inventory_units_controller.rb +2 -2
- data/app/controllers/spree/api/v1/line_items_controller.rb +24 -28
- data/app/controllers/spree/api/v1/option_types_controller.rb +5 -5
- data/app/controllers/spree/api/v1/option_values_controller.rb +16 -17
- data/app/controllers/spree/api/v1/orders_controller.rb +39 -49
- data/app/controllers/spree/api/v1/payments_controller.rb +15 -17
- data/app/controllers/spree/api/v1/product_properties_controller.rb +2 -3
- data/app/controllers/spree/api/v1/products_controller.rb +24 -25
- data/app/controllers/spree/api/v1/promotions_controller.rb +9 -8
- data/app/controllers/spree/api/v1/properties_controller.rb +14 -16
- data/app/controllers/spree/api/v1/return_authorizations_controller.rb +0 -1
- data/app/controllers/spree/api/v1/shipments_controller.rb +17 -26
- data/app/controllers/spree/api/v1/states_controller.rb +9 -10
- data/app/controllers/spree/api/v1/stock_items_controller.rb +2 -2
- data/app/controllers/spree/api/v1/stores_controller.rb +0 -1
- data/app/controllers/spree/api/v1/tags_controller.rb +1 -1
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +1 -3
- data/app/controllers/spree/api/v1/taxons_controller.rb +15 -16
- data/app/controllers/spree/api/v1/users_controller.rb +1 -4
- data/app/controllers/spree/api/v1/variants_controller.rb +22 -22
- data/app/controllers/spree/api/v1/zones_controller.rb +0 -1
- data/app/helpers/spree/api/api_helpers.rb +5 -5
- data/app/views/spree/api/errors/gateway_error.v1.rabl +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/addresses/show.v1.rabl +2 -2
- data/app/views/spree/api/v1/credit_cards/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/images/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/images/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/line_items/show.v1.rabl +3 -3
- data/app/views/spree/api/v1/option_types/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/option_types/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/option_values/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/option_values/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/could_not_transition.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/index.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/mine.v1.rabl +1 -1
- data/app/views/spree/api/v1/orders/order.v1.rabl +5 -5
- data/app/views/spree/api/v1/orders/show.v1.rabl +7 -7
- data/app/views/spree/api/v1/product_properties/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/product_properties/new.v1.rabl +1 -1
- data/app/views/spree/api/v1/products/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/products/show.v1.rabl +5 -5
- data/app/views/spree/api/v1/return_authorizations/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/shared/stock_location_required.v1.rabl +1 -1
- data/app/views/spree/api/v1/shipments/big.v1.rabl +8 -8
- data/app/views/spree/api/v1/shipments/cannot_ready_shipment.v1.rabl +1 -1
- data/app/views/spree/api/v1/shipments/mine.v1.rabl +1 -1
- data/app/views/spree/api/v1/shipments/show.v1.rabl +5 -5
- data/app/views/spree/api/v1/shipments/small.v1.rabl +5 -5
- data/app/views/spree/api/v1/shipping_rates/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/states/index.v1.rabl +1 -3
- data/app/views/spree/api/v1/stock_items/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/stock_locations/show.v1.rabl +2 -2
- data/app/views/spree/api/v1/stock_movements/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/taxonomies/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/taxonomies/jstree.rabl +2 -3
- data/app/views/spree/api/v1/taxonomies/nested.v1.rabl +1 -1
- data/app/views/spree/api/v1/taxonomies/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/taxons/index.v1.rabl +1 -3
- data/app/views/spree/api/v1/taxons/jstree.rabl +3 -4
- data/app/views/spree/api/v1/taxons/taxons.v1.rabl +1 -1
- data/app/views/spree/api/v1/users/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/users/show.v1.rabl +3 -3
- data/app/views/spree/api/v1/variants/big.v1.rabl +1 -1
- data/app/views/spree/api/v1/variants/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/variants/show.v1.rabl +1 -1
- data/app/views/spree/api/v1/variants/small.v1.rabl +7 -7
- data/config/routes.rb +3 -3
- data/lib/spree/api/controller_setup.rb +2 -2
- data/lib/spree/api/engine.rb +3 -3
- data/lib/spree/api/responders/rabl_template.rb +1 -3
- data/lib/spree/api/testing_support/caching.rb +3 -3
- data/lib/spree/api/testing_support/helpers.rb +4 -4
- data/lib/spree/api/testing_support/setup.rb +2 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caba802b7afa26a82233bfc0febb57c3c17e40b2
|
4
|
+
data.tar.gz: 440f5f7989eec445403422c946090c78eb67acc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
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?(
|
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
|
38
|
-
|
39
|
-
when
|
40
|
-
|
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[
|
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
|
68
|
+
render 'spree/api/errors/invalid_api_key', status: 401
|
69
69
|
end
|
70
70
|
|
71
71
|
def must_specify_api_key
|
72
|
-
render
|
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
|
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
|
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
|
113
|
+
render 'spree/api/errors/invalid_resource', status: 422
|
114
114
|
end
|
115
115
|
|
116
116
|
def api_key
|
117
|
-
request.headers[
|
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[
|
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?(
|
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
|
-
|
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(
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
@@ -34,7 +34,7 @@ module Spree
|
|
34
34
|
can_event = "can_#{@event}?"
|
35
35
|
|
36
36
|
unless inventory_unit.respond_to?(can_event) &&
|
37
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
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,
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
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
|
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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
params
|
130
|
-
|
131
|
-
|
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
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
139
|
-
|
140
|
-
|
124
|
+
def find_order(lock = false)
|
125
|
+
@order = Spree::Order.lock(lock).find_by!(number: params[:id])
|
126
|
+
end
|
141
127
|
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|