spree_api 2.0.13 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +99 -1
- data/app/controllers/spree/api/addresses_controller.rb +5 -2
- data/app/controllers/spree/api/base_controller.rb +14 -21
- data/app/controllers/spree/api/checkouts_controller.rb +30 -27
- data/app/controllers/spree/api/config_controller.rb +6 -0
- data/app/controllers/spree/api/countries_controller.rb +7 -7
- data/app/controllers/spree/api/images_controller.rb +10 -8
- data/app/controllers/spree/api/inventory_units_controller.rb +7 -4
- data/app/controllers/spree/api/line_items_controller.rb +14 -14
- data/app/controllers/spree/api/option_types_controller.rb +14 -11
- data/app/controllers/spree/api/option_values_controller.rb +13 -11
- data/app/controllers/spree/api/orders_controller.rb +56 -53
- data/app/controllers/spree/api/payments_controller.rb +25 -33
- data/app/controllers/spree/api/product_properties_controller.rb +20 -13
- data/app/controllers/spree/api/products_controller.rb +11 -58
- data/app/controllers/spree/api/properties_controller.rb +19 -16
- data/app/controllers/spree/api/return_authorizations_controller.rb +30 -25
- data/app/controllers/spree/api/shipments_controller.rb +24 -19
- data/app/controllers/spree/api/states_controller.rb +9 -7
- data/app/controllers/spree/api/stock_items_controller.rb +9 -11
- data/app/controllers/spree/api/stock_locations_controller.rb +9 -7
- data/app/controllers/spree/api/stock_movements_controller.rb +7 -5
- data/app/controllers/spree/api/taxonomies_controller.rb +14 -8
- data/app/controllers/spree/api/taxons_controller.rb +25 -20
- data/app/controllers/spree/api/users_controller.rb +7 -5
- data/app/controllers/spree/api/variants_controller.rb +35 -33
- data/app/controllers/spree/api/zones_controller.rb +18 -17
- data/app/helpers/spree/api/api_helpers.rb +7 -6
- data/app/models/spree/option_value_decorator.rb +0 -4
- data/app/models/spree/order_decorator.rb +33 -54
- data/app/views/spree/api/adjustments/show.v1.rabl +2 -1
- data/app/views/spree/api/config/money.v1.rabl +6 -0
- data/app/views/spree/api/config/show.v1.rabl +2 -0
- data/app/views/spree/api/images/show.v1.rabl +0 -1
- data/app/views/spree/api/line_items/show.v1.rabl +3 -0
- data/app/views/spree/api/orders/index.v1.rabl +1 -1
- data/app/views/spree/api/orders/order.v1.rabl +6 -0
- data/app/views/spree/api/orders/payment.v1.rabl +1 -1
- data/app/views/spree/api/orders/show.v1.rabl +1 -1
- data/app/views/spree/api/payments/credit_over_limit.v1.rabl +1 -1
- data/app/views/spree/api/payments/new.v1.rabl +1 -0
- data/app/views/spree/api/products/index.v1.rabl +2 -2
- data/app/views/spree/api/products/show.v1.rabl +1 -0
- data/app/views/spree/api/shipments/show.v1.rabl +22 -5
- data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -0
- data/app/views/spree/api/taxons/index.v1.rabl +2 -4
- data/app/views/spree/api/variants/index.v1.rabl +1 -1
- data/config/locales/en.yml +1 -3
- data/config/routes.rb +4 -1
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- data/lib/spree/api/testing_support/helpers.rb +5 -0
- data/spec/controllers/spree/api/addresses_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +32 -22
- data/spec/controllers/spree/api/config_controller_spec.rb +27 -0
- data/spec/controllers/spree/api/images_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +28 -24
- data/spec/controllers/spree/api/line_items_controller_spec.rb +25 -27
- data/spec/controllers/spree/api/option_types_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/option_values_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/orders_controller_spec.rb +130 -119
- data/spec/controllers/spree/api/payments_controller_spec.rb +77 -118
- data/spec/controllers/spree/api/products_controller_spec.rb +13 -143
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +4 -19
- data/spec/controllers/spree/api/shipments_controller_spec.rb +3 -3
- data/spec/controllers/spree/api/states_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -62
- data/spec/controllers/spree/api/stock_locations_controller_spec.rb +29 -56
- data/spec/controllers/spree/api/stock_movements_controller_spec.rb +27 -51
- data/spec/controllers/spree/api/taxons_controller_spec.rb +18 -48
- data/spec/controllers/spree/api/users_controller_spec.rb +4 -6
- data/spec/controllers/spree/api/variants_controller_spec.rb +21 -38
- data/spec/controllers/spree/api/zones_controller_spec.rb +2 -2
- data/spec/models/spree/order_spec.rb +19 -111
- data/spec/spec_helper.rb +2 -26
- data/spec/support/controller_hacks.rb +1 -1
- data/spree_api.gemspec +1 -1
- metadata +19 -15
- data/app/models/spree/line_item_decorator.rb +0 -3
- data/app/views/spree/api/payments/update_forbidden.v1.rabl +0 -2
- data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +0 -7
@@ -1,91 +1,94 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class OrdersController < Spree::Api::BaseController
|
4
|
-
respond_to :json
|
5
4
|
|
6
|
-
|
5
|
+
# Dynamically defines our stores checkout steps to ensure we check authorization on each step.
|
6
|
+
Order.checkout_steps.keys.each do |step|
|
7
|
+
define_method step do
|
8
|
+
find_order
|
9
|
+
authorize! :update, @order, params[:token]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def cancel
|
14
|
+
find_order
|
15
|
+
authorize! :update, @order, params[:token]
|
16
|
+
@order.cancel!
|
17
|
+
render :show
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
authorize! :create, Order
|
22
|
+
@order = Order.build_from_api(current_api_user, order_params)
|
23
|
+
respond_with(@order, default_template: :show, status: 201)
|
24
|
+
end
|
25
|
+
|
26
|
+
def empty
|
27
|
+
find_order
|
28
|
+
@order.empty!
|
29
|
+
@order.update!
|
30
|
+
render text: nil, status: 200
|
31
|
+
end
|
7
32
|
|
8
33
|
def index
|
9
|
-
|
10
|
-
raise CanCan::AccessDenied unless current_api_user.has_spree_role?("admin")
|
34
|
+
authorize! :index, Order
|
11
35
|
@orders = Order.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
12
36
|
respond_with(@orders)
|
13
37
|
end
|
14
38
|
|
15
39
|
def show
|
40
|
+
find_order
|
41
|
+
method = "before_#{@order.state}"
|
42
|
+
send(method) if respond_to?(method, true)
|
16
43
|
respond_with(@order)
|
17
44
|
end
|
18
45
|
|
19
|
-
def create
|
20
|
-
nested_params[:line_items_attributes] = sanitize_line_items(nested_params[:line_items_attributes])
|
21
|
-
@order = Order.build_from_api(current_api_user, nested_params)
|
22
|
-
respond_with(@order, :default_template => :show, :status => 201)
|
23
|
-
end
|
24
|
-
|
25
46
|
def update
|
47
|
+
find_order
|
26
48
|
# Parsing line items through as an update_attributes call in the API will result in
|
27
49
|
# many line items for the same variant_id being created. We must be smarter about this,
|
28
50
|
# hence the use of the update_line_items method, defined within order_decorator.rb.
|
29
|
-
|
30
|
-
if @order.update_attributes(
|
31
|
-
@order.update_line_items(
|
51
|
+
order_params.delete("line_items_attributes")
|
52
|
+
if @order.update_attributes(order_params)
|
53
|
+
@order.update_line_items(params[:order][:line_items])
|
32
54
|
@order.line_items.reload
|
33
55
|
@order.update!
|
34
|
-
respond_with(@order, :
|
56
|
+
respond_with(@order, default_template: :show)
|
35
57
|
else
|
36
58
|
invalid_resource!(@order)
|
37
59
|
end
|
38
60
|
end
|
39
61
|
|
40
|
-
def cancel
|
41
|
-
@order.cancel!
|
42
|
-
render :show
|
43
|
-
end
|
44
|
-
|
45
|
-
def empty
|
46
|
-
@order.empty!
|
47
|
-
@order.update!
|
48
|
-
render :text => nil, :status => 200
|
49
|
-
end
|
50
|
-
|
51
62
|
private
|
52
63
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
64
|
+
def order_params
|
65
|
+
if params[:order]
|
66
|
+
params[:order][:line_items_attributes] = params[:order][:line_items]
|
67
|
+
params[:order][:ship_address_attributes] = params[:order][:ship_address] if params[:order][:ship_address]
|
68
|
+
params[:order][:bill_address_attributes] = params[:order][:bill_address] if params[:order][:bill_address]
|
69
|
+
params.require(:order).permit(permitted_order_attributes)
|
70
|
+
else
|
71
|
+
{}
|
72
|
+
end
|
73
|
+
end
|
61
74
|
|
62
|
-
|
63
|
-
if
|
64
|
-
|
75
|
+
def next!(options={})
|
76
|
+
if @order.valid? && @order.next
|
77
|
+
render :show, status: options[:status] || 200
|
65
78
|
else
|
66
|
-
|
79
|
+
render :could_not_transition, status: 422
|
67
80
|
end
|
68
81
|
end
|
69
|
-
line_item_attributes = Hash[line_item_attributes].delete_if { |k,v| v.empty? }
|
70
|
-
end
|
71
82
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
83
|
+
def find_order
|
84
|
+
@order = Spree::Order.find_by!(number: params[:id])
|
85
|
+
authorize! :update, @order, params[:order_token]
|
86
|
+
end
|
76
87
|
|
77
|
-
|
78
|
-
|
79
|
-
render :show, :status => options[:status] || 200
|
80
|
-
else
|
81
|
-
render :could_not_transition, :status => 422
|
88
|
+
def before_delivery
|
89
|
+
@order.create_proposed_shipments
|
82
90
|
end
|
83
|
-
end
|
84
91
|
|
85
|
-
def find_and_authorize!
|
86
|
-
find_order(true)
|
87
|
-
authorize! :read, @order
|
88
|
-
end
|
89
92
|
end
|
90
93
|
end
|
91
94
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class PaymentsController < Spree::Api::BaseController
|
4
|
-
respond_to :json
|
5
4
|
|
6
5
|
before_filter :find_order
|
7
|
-
before_filter :find_payment, only: [:
|
6
|
+
before_filter :find_payment, only: [:show, :authorize, :purchase, :capture, :void, :credit]
|
8
7
|
|
9
8
|
def index
|
10
9
|
@payments = @order.payments.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
@@ -12,25 +11,14 @@ module Spree
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def new
|
15
|
-
@payment_methods = Spree::PaymentMethod.where(:
|
14
|
+
@payment_methods = Spree::PaymentMethod.where(environment: Rails.env)
|
16
15
|
respond_with(@payment_method)
|
17
16
|
end
|
18
17
|
|
19
18
|
def create
|
20
|
-
@payment = @order.payments.build(
|
19
|
+
@payment = @order.payments.build(payment_params)
|
21
20
|
if @payment.save
|
22
|
-
respond_with(@payment, :
|
23
|
-
else
|
24
|
-
invalid_resource!(@payment)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def update
|
29
|
-
authorize! params[:action], @payment
|
30
|
-
if !@payment.pending?
|
31
|
-
render 'update_forbidden', status: 403
|
32
|
-
elsif @payment.update_attributes(params[:payment])
|
33
|
-
respond_with(@payment, default_template: :show)
|
21
|
+
respond_with(@payment, status: 201, default_template: :show)
|
34
22
|
else
|
35
23
|
invalid_resource!(@payment)
|
36
24
|
end
|
@@ -58,7 +46,7 @@ module Spree
|
|
58
46
|
|
59
47
|
def credit
|
60
48
|
if params[:amount].to_f > @payment.credit_allowed
|
61
|
-
render 'credit_over_limit', status: 422
|
49
|
+
render 'spree/api/payments/credit_over_limit', status: 422
|
62
50
|
else
|
63
51
|
perform_payment_action(:credit, params[:amount])
|
64
52
|
end
|
@@ -66,26 +54,30 @@ module Spree
|
|
66
54
|
|
67
55
|
private
|
68
56
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
57
|
+
def find_order
|
58
|
+
@order = Spree::Order.find_by(number: params[:order_id])
|
59
|
+
authorize! :read, @order
|
60
|
+
end
|
73
61
|
|
74
|
-
|
75
|
-
|
76
|
-
|
62
|
+
def find_payment
|
63
|
+
@payment = @order.payments.find(params[:id])
|
64
|
+
end
|
77
65
|
|
78
|
-
|
79
|
-
|
66
|
+
def perform_payment_action(action, *args)
|
67
|
+
authorize! action, Payment
|
80
68
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
69
|
+
begin
|
70
|
+
@payment.send("#{action}!", *args)
|
71
|
+
respond_with(@payment, :default_template => :show)
|
72
|
+
rescue Spree::Core::GatewayError => e
|
73
|
+
@error = e.message
|
74
|
+
render 'spree/api/errors/gateway_error', status: 422
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def payment_params
|
79
|
+
params.require(:payment).permit(permitted_payment_attributes)
|
87
80
|
end
|
88
|
-
end
|
89
81
|
end
|
90
82
|
end
|
91
83
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class ProductPropertiesController < Spree::Api::BaseController
|
4
|
-
respond_to :json
|
5
4
|
|
6
5
|
before_filter :find_product
|
7
|
-
before_filter :product_property, :
|
6
|
+
before_filter :product_property, only: [:show, :update, :destroy]
|
8
7
|
|
9
8
|
def index
|
10
|
-
@product_properties = @product.product_properties.
|
9
|
+
@product_properties = @product.product_properties.accessible_by(current_ability, :read).
|
11
10
|
ransack(params[:q]).result.
|
12
11
|
page(params[:page]).per(params[:per_page])
|
13
12
|
respond_with(@product_properties)
|
@@ -22,44 +21,52 @@ module Spree
|
|
22
21
|
|
23
22
|
def create
|
24
23
|
authorize! :create, ProductProperty
|
25
|
-
@product_property = @product.product_properties.new(
|
24
|
+
@product_property = @product.product_properties.new(product_property_params)
|
26
25
|
if @product_property.save
|
27
|
-
respond_with(@product_property, :
|
26
|
+
respond_with(@product_property, status: 201, default_template: :show)
|
28
27
|
else
|
29
28
|
invalid_resource!(@product_property)
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
32
|
def update
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
if @product_property
|
34
|
+
authorize! :update, @product_property
|
35
|
+
@product_property.update_attributes(product_property_params)
|
36
|
+
respond_with(@product_property, status: 200, default_template: :show)
|
37
37
|
else
|
38
38
|
invalid_resource!(@product_property)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def destroy
|
43
|
-
|
44
|
-
|
43
|
+
if @product_property
|
44
|
+
authorize! :destroy, @product_property
|
45
45
|
@product_property.destroy
|
46
|
-
respond_with(@product_property, :
|
46
|
+
respond_with(@product_property, status: 204)
|
47
47
|
else
|
48
48
|
invalid_resource!(@product_property)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
private
|
53
|
+
|
53
54
|
def find_product
|
54
55
|
@product = super(params[:product_id])
|
56
|
+
authorize! :read, @product
|
55
57
|
end
|
56
58
|
|
57
59
|
def product_property
|
58
60
|
if @product
|
59
|
-
@product_property ||= @product.product_properties.
|
60
|
-
@product_property ||= @product.product_properties.
|
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
|
61
64
|
end
|
62
65
|
end
|
66
|
+
|
67
|
+
def product_property_params
|
68
|
+
params.require(:product_property).permit(permitted_product_properties_attributes)
|
69
|
+
end
|
63
70
|
end
|
64
71
|
end
|
65
72
|
end
|
@@ -1,22 +1,20 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class ProductsController < Spree::Api::BaseController
|
4
|
-
respond_to :json
|
5
4
|
|
6
5
|
def index
|
7
6
|
if params[:ids]
|
8
|
-
@products = product_scope.where(:id => params[:ids]
|
7
|
+
@products = product_scope.where(:id => params[:ids])
|
9
8
|
else
|
10
9
|
@products = product_scope.ransack(params[:q]).result
|
11
10
|
end
|
12
11
|
|
13
12
|
@products = @products.page(params[:page]).per(params[:per_page])
|
14
|
-
|
15
|
-
respond_with(@products)
|
16
13
|
end
|
17
14
|
|
18
15
|
def show
|
19
16
|
@product = find_product(params[:id])
|
17
|
+
expires_in 3.minutes
|
20
18
|
respond_with(@product)
|
21
19
|
end
|
22
20
|
|
@@ -26,28 +24,9 @@ module Spree
|
|
26
24
|
def create
|
27
25
|
authorize! :create, Product
|
28
26
|
params[:product][:available_on] ||= Time.now
|
29
|
-
|
30
|
-
variants_attributes = params[:product].delete(:variants_attributes) || []
|
31
|
-
option_type_attributes = params[:product].delete(:option_types) || []
|
32
|
-
set_up_shipping_category
|
33
|
-
|
34
|
-
@product = Product.new(params[:product])
|
35
27
|
begin
|
28
|
+
@product = Product.new(product_params)
|
36
29
|
if @product.save
|
37
|
-
variants_attributes.each do |variant_attribute|
|
38
|
-
variant = @product.variants.new
|
39
|
-
variant.update_attributes(variant_attribute)
|
40
|
-
end
|
41
|
-
|
42
|
-
option_type_attributes.each do |name|
|
43
|
-
option_type = OptionType.where(name: name).first_or_initialize do |option_type|
|
44
|
-
option_type.presentation = name
|
45
|
-
option_type.save!
|
46
|
-
end
|
47
|
-
|
48
|
-
@product.option_types << option_type unless @product.option_types.include?(option_type)
|
49
|
-
end
|
50
|
-
|
51
30
|
respond_with(@product, :status => 201, :default_template => :show)
|
52
31
|
else
|
53
32
|
invalid_resource!(@product)
|
@@ -56,36 +35,12 @@ module Spree
|
|
56
35
|
@product.permalink = nil
|
57
36
|
retry
|
58
37
|
end
|
59
|
-
end
|
38
|
+
end
|
60
39
|
|
61
40
|
def update
|
62
|
-
authorize! :update, Product
|
63
|
-
|
64
|
-
variants_attributes = params[:product].delete(:variants_attributes) || []
|
65
|
-
option_type_attributes = params[:product].delete(:option_types) || []
|
66
|
-
set_up_shipping_category
|
67
|
-
|
68
41
|
@product = find_product(params[:id])
|
69
|
-
|
70
|
-
|
71
|
-
# update the variant if the id is present in the payload
|
72
|
-
if variant_attribute['id'].present?
|
73
|
-
@product.variants.find(variant_attribute['id'].to_i).update_attributes(variant_attribute)
|
74
|
-
else
|
75
|
-
variant = @product.variants.new
|
76
|
-
variant.update_attributes(variant_attribute)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
option_type_attributes.each do |name|
|
81
|
-
option_type = OptionType.where(name: name).first_or_initialize do |option_type|
|
82
|
-
option_type.presentation = name
|
83
|
-
option_type.save!
|
84
|
-
end
|
85
|
-
|
86
|
-
@product.option_types << option_type unless @product.option_types.include?(option_type)
|
87
|
-
end
|
88
|
-
|
42
|
+
authorize! :update, @product
|
43
|
+
if @product.update_attributes(product_params)
|
89
44
|
respond_with(@product, :status => 200, :default_template => :show)
|
90
45
|
else
|
91
46
|
invalid_resource!(@product)
|
@@ -93,18 +48,16 @@ module Spree
|
|
93
48
|
end
|
94
49
|
|
95
50
|
def destroy
|
96
|
-
authorize! :delete, Product
|
97
51
|
@product = find_product(params[:id])
|
98
|
-
@product
|
52
|
+
authorize! :destroy, @product
|
53
|
+
@product.update_attribute(:deleted_at, Time.now)
|
54
|
+
@product.variants_including_master.update_all(:deleted_at => Time.now)
|
99
55
|
respond_with(@product, :status => 204)
|
100
56
|
end
|
101
57
|
|
102
58
|
private
|
103
|
-
def
|
104
|
-
|
105
|
-
id = ShippingCategory.find_or_create_by_name(shipping_category).id
|
106
|
-
params[:product][:shipping_category_id] = id
|
107
|
-
end
|
59
|
+
def product_params
|
60
|
+
params.require(:product).permit(permitted_product_attributes)
|
108
61
|
end
|
109
62
|
end
|
110
63
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class PropertiesController < Spree::Api::BaseController
|
4
|
-
respond_to :json
|
5
4
|
|
6
|
-
before_filter :find_property, :
|
5
|
+
before_filter :find_property, only: [:show, :update, :destroy]
|
7
6
|
|
8
7
|
def index
|
9
|
-
@properties = Spree::Property.
|
8
|
+
@properties = Spree::Property.accessible_by(current_ability, :read).
|
10
9
|
ransack(params[:q]).result.
|
11
10
|
page(params[:page]).per(params[:per_page])
|
12
11
|
respond_with(@properties)
|
@@ -21,28 +20,29 @@ module Spree
|
|
21
20
|
|
22
21
|
def create
|
23
22
|
authorize! :create, Property
|
24
|
-
@property = Spree::Property.new(
|
23
|
+
@property = Spree::Property.new(property_params)
|
25
24
|
if @property.save
|
26
|
-
respond_with(@property, :
|
25
|
+
respond_with(@property, status: 201, default_template: :show)
|
27
26
|
else
|
28
27
|
invalid_resource!(@property)
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
31
|
def update
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
if @property
|
33
|
+
authorize! :update, @property
|
34
|
+
@property.update_attributes(property_params)
|
35
|
+
respond_with(@property, status: 200, default_template: :show)
|
36
36
|
else
|
37
37
|
invalid_resource!(@property)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def destroy
|
42
|
-
|
43
|
-
|
42
|
+
if @property
|
43
|
+
authorize! :destroy, @property
|
44
44
|
@property.destroy
|
45
|
-
respond_with(@property, :
|
45
|
+
respond_with(@property, status: 204)
|
46
46
|
else
|
47
47
|
invalid_resource!(@property)
|
48
48
|
end
|
@@ -50,12 +50,15 @@ module Spree
|
|
50
50
|
|
51
51
|
private
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
def find_property
|
54
|
+
@property = Spree::Property.accessible_by(current_ability, :read).find(params[:id])
|
55
|
+
rescue ActiveRecord::RecordNotFound
|
56
|
+
@property = Spree::Property.accessible_by(current_ability, :read).find_by!(name: params[:id])
|
57
|
+
end
|
58
58
|
|
59
|
+
def property_params
|
60
|
+
params.require(:property).permit(permitted_property_attributes)
|
61
|
+
end
|
59
62
|
end
|
60
63
|
end
|
61
64
|
end
|
@@ -1,46 +1,50 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class ReturnAuthorizationsController < Spree::Api::BaseController
|
4
|
-
respond_to :json
|
5
4
|
|
6
|
-
|
5
|
+
def create
|
6
|
+
authorize! :create, ReturnAuthorization
|
7
|
+
@return_authorization = order.return_authorizations.build(return_authorization_params)
|
8
|
+
if @return_authorization.save
|
9
|
+
respond_with(@return_authorization, status: 201, default_template: :show)
|
10
|
+
else
|
11
|
+
invalid_resource!(@return_authorization)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy
|
16
|
+
@return_authorization = order.return_authorizations.accessible_by(current_ability, :destroy).find(params[:id])
|
17
|
+
@return_authorization.destroy
|
18
|
+
respond_with(@return_authorization, status: 204)
|
19
|
+
end
|
7
20
|
|
8
21
|
def index
|
9
|
-
|
22
|
+
authorize! :admin, ReturnAuthorization
|
23
|
+
@return_authorizations = order.return_authorizations.accessible_by(current_ability, :read).
|
10
24
|
ransack(params[:q]).result.
|
11
25
|
page(params[:page]).per(params[:per_page])
|
12
26
|
respond_with(@return_authorizations)
|
13
27
|
end
|
14
28
|
|
15
|
-
def
|
16
|
-
|
17
|
-
respond_with(@return_authorization)
|
29
|
+
def new
|
30
|
+
authorize! :admin, ReturnAuthorization
|
18
31
|
end
|
19
32
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
else
|
25
|
-
invalid_resource!(@return_authorization)
|
26
|
-
end
|
33
|
+
def show
|
34
|
+
authorize! :admin, ReturnAuthorization
|
35
|
+
@return_authorization = order.return_authorizations.accessible_by(current_ability, :read).find(params[:id])
|
36
|
+
respond_with(@return_authorization)
|
27
37
|
end
|
28
38
|
|
29
39
|
def update
|
30
|
-
@return_authorization = order.return_authorizations.find(params[:id])
|
31
|
-
if @return_authorization.update_attributes(
|
32
|
-
respond_with(@return_authorization, :
|
40
|
+
@return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
|
41
|
+
if @return_authorization.update_attributes(return_authorization_params)
|
42
|
+
respond_with(@return_authorization, default_template: :show)
|
33
43
|
else
|
34
44
|
invalid_resource!(@return_authorization)
|
35
45
|
end
|
36
46
|
end
|
37
47
|
|
38
|
-
def destroy
|
39
|
-
@return_authorization = order.return_authorizations.find(params[:id])
|
40
|
-
@return_authorization.destroy
|
41
|
-
respond_with(@return_authorization, :status => 204)
|
42
|
-
end
|
43
|
-
|
44
48
|
def add
|
45
49
|
@return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
|
46
50
|
@return_authorization.add_variant params[:variant_id].to_i, params[:quantity].to_i
|
@@ -72,11 +76,12 @@ module Spree
|
|
72
76
|
private
|
73
77
|
|
74
78
|
def order
|
75
|
-
@order ||= Order.
|
79
|
+
@order ||= Spree::Order.find_by!(number: params[:order_id])
|
80
|
+
authorize! :read, @order
|
76
81
|
end
|
77
82
|
|
78
|
-
def
|
79
|
-
|
83
|
+
def return_authorization_params
|
84
|
+
params.require(:return_authorization).permit(permitted_return_authorization_attributes)
|
80
85
|
end
|
81
86
|
end
|
82
87
|
end
|