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,61 +1,58 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class ShipmentsController < Spree::Api::BaseController
|
4
|
-
respond_to :json
|
5
4
|
|
6
5
|
before_filter :find_order
|
7
|
-
before_filter :find_and_update_shipment, :
|
6
|
+
before_filter :find_and_update_shipment, only: [:ship, :ready, :add, :remove]
|
8
7
|
|
9
8
|
def create
|
9
|
+
authorize! :create, Shipment
|
10
10
|
variant = Spree::Variant.find(params[:variant_id])
|
11
11
|
quantity = params[:quantity].to_i
|
12
|
-
@shipment = @order.shipments.create(:
|
12
|
+
@shipment = @order.shipments.create(stock_location_id: params[:stock_location_id])
|
13
13
|
@order.contents.add(variant, quantity, nil, @shipment)
|
14
14
|
|
15
15
|
@shipment.refresh_rates
|
16
16
|
@shipment.save!
|
17
17
|
|
18
|
-
respond_with(@shipment.reload, :
|
18
|
+
respond_with(@shipment.reload, default_template: :show)
|
19
19
|
end
|
20
20
|
|
21
21
|
def update
|
22
|
-
|
23
|
-
|
24
|
-
params[:shipment] ||= []
|
22
|
+
@shipment = @order.shipments.accessible_by(current_ability, :update).find_by!(number: params[:id])
|
23
|
+
|
25
24
|
unlock = params[:shipment].delete(:unlock)
|
26
25
|
|
27
26
|
if unlock == 'yes'
|
28
27
|
@shipment.adjustment.open
|
29
28
|
end
|
30
29
|
|
31
|
-
@shipment.update_attributes(
|
30
|
+
@shipment.update_attributes(shipment_params)
|
32
31
|
|
33
32
|
if unlock == 'yes'
|
34
33
|
@shipment.adjustment.close
|
35
34
|
end
|
36
35
|
|
37
36
|
@shipment.reload
|
38
|
-
respond_with(@shipment, :
|
37
|
+
respond_with(@shipment, default_template: :show)
|
39
38
|
end
|
40
39
|
|
41
40
|
def ready
|
42
|
-
authorize! :read, Shipment
|
43
41
|
unless @shipment.ready?
|
44
42
|
if @shipment.can_ready?
|
45
43
|
@shipment.ready!
|
46
44
|
else
|
47
|
-
render
|
45
|
+
render 'spree/api/shipments/cannot_ready_shipment', status: 422 and return
|
48
46
|
end
|
49
47
|
end
|
50
|
-
respond_with(@shipment, :
|
48
|
+
respond_with(@shipment, default_template: :show)
|
51
49
|
end
|
52
50
|
|
53
51
|
def ship
|
54
|
-
authorize! :read, Shipment
|
55
52
|
unless @shipment.shipped?
|
56
53
|
@shipment.ship!
|
57
54
|
end
|
58
|
-
respond_with(@shipment, :
|
55
|
+
respond_with(@shipment, default_template: :show)
|
59
56
|
end
|
60
57
|
|
61
58
|
def add
|
@@ -64,7 +61,7 @@ module Spree
|
|
64
61
|
|
65
62
|
@order.contents.add(variant, quantity, nil, @shipment)
|
66
63
|
|
67
|
-
respond_with(@shipment, :
|
64
|
+
respond_with(@shipment, default_template: :show)
|
68
65
|
end
|
69
66
|
|
70
67
|
def remove
|
@@ -73,21 +70,29 @@ module Spree
|
|
73
70
|
|
74
71
|
@order.contents.remove(variant, quantity, @shipment)
|
75
72
|
@shipment.reload if @shipment.persisted?
|
76
|
-
respond_with(@shipment, :
|
73
|
+
respond_with(@shipment, default_template: :show)
|
77
74
|
end
|
78
75
|
|
79
76
|
private
|
80
77
|
|
81
78
|
def find_order
|
82
|
-
@order = Spree::Order.
|
79
|
+
@order = Spree::Order.find_by!(number: params[:order_id])
|
83
80
|
authorize! :read, @order
|
84
81
|
end
|
85
82
|
|
86
83
|
def find_and_update_shipment
|
87
|
-
@shipment = @order.shipments.
|
88
|
-
@shipment.update_attributes(
|
84
|
+
@shipment = @order.shipments.accessible_by(current_ability, :update).find_by!(number: params[:id])
|
85
|
+
@shipment.update_attributes(shipment_params)
|
89
86
|
@shipment.reload
|
90
87
|
end
|
88
|
+
|
89
|
+
def shipment_params
|
90
|
+
if params[:shipment] && !params[:shipment].empty?
|
91
|
+
params.require(:shipment).permit(permitted_shipment_attributes)
|
92
|
+
else
|
93
|
+
{}
|
94
|
+
end
|
95
|
+
end
|
91
96
|
end
|
92
97
|
end
|
93
98
|
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class StatesController < Spree::Api::BaseController
|
4
|
-
skip_before_filter :
|
5
|
-
skip_before_filter :authenticate_user
|
4
|
+
skip_before_filter :set_expiry
|
6
5
|
|
7
6
|
def index
|
8
7
|
@states = scope.ransack(params[:q]).result.
|
9
|
-
|
8
|
+
includes(:country).order('name ASC')
|
10
9
|
|
11
10
|
if params[:page] || params[:per_page]
|
12
11
|
@states = @states.page(params[:page]).per(params[:per_page])
|
13
12
|
end
|
14
13
|
|
15
|
-
|
14
|
+
state = @states.last
|
15
|
+
if stale?(state)
|
16
|
+
respond_with(@states)
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
20
|
def show
|
@@ -23,10 +25,10 @@ module Spree
|
|
23
25
|
private
|
24
26
|
def scope
|
25
27
|
if params[:country_id]
|
26
|
-
@country = Country.find(params[:country_id])
|
27
|
-
return @country.states
|
28
|
+
@country = Country.accessible_by(current_ability, :read).find(params[:country_id])
|
29
|
+
return @country.states.accessible_by(current_ability, :read)
|
28
30
|
else
|
29
|
-
return State.
|
31
|
+
return State.accessible_by(current_ability, :read)
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -4,13 +4,11 @@ module Spree
|
|
4
4
|
before_filter :stock_location, except: [:update, :destroy]
|
5
5
|
|
6
6
|
def index
|
7
|
-
authorize! :read, StockItem
|
8
7
|
@stock_items = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
9
8
|
respond_with(@stock_items)
|
10
9
|
end
|
11
10
|
|
12
11
|
def show
|
13
|
-
authorize! :read, StockItem
|
14
12
|
@stock_item = scope.find(params[:id])
|
15
13
|
respond_with(@stock_item)
|
16
14
|
end
|
@@ -21,10 +19,9 @@ module Spree
|
|
21
19
|
count_on_hand = 0
|
22
20
|
if params[:stock_item].has_key?(:count_on_hand)
|
23
21
|
count_on_hand = params[:stock_item][:count_on_hand].to_i
|
24
|
-
params[:stock_item].delete(:count_on_hand)
|
25
22
|
end
|
26
23
|
|
27
|
-
@stock_item = scope.new(
|
24
|
+
@stock_item = scope.new(stock_item_params)
|
28
25
|
if @stock_item.save
|
29
26
|
@stock_item.adjust_count_on_hand(count_on_hand)
|
30
27
|
respond_with(@stock_item, status: 201, default_template: :show)
|
@@ -34,8 +31,7 @@ module Spree
|
|
34
31
|
end
|
35
32
|
|
36
33
|
def update
|
37
|
-
|
38
|
-
@stock_item = StockItem.find(params[:id])
|
34
|
+
@stock_item = StockItem.accessible_by(current_ability, :update).find(params[:id])
|
39
35
|
|
40
36
|
count_on_hand = 0
|
41
37
|
if params[:stock_item].has_key?(:count_on_hand)
|
@@ -54,8 +50,7 @@ module Spree
|
|
54
50
|
end
|
55
51
|
|
56
52
|
def destroy
|
57
|
-
|
58
|
-
@stock_item = StockItem.find(params[:id])
|
53
|
+
@stock_item = StockItem.accessible_by(current_ability, :destroy).find(params[:id])
|
59
54
|
@stock_item.destroy
|
60
55
|
respond_with(@stock_item, status: 204)
|
61
56
|
end
|
@@ -64,12 +59,15 @@ module Spree
|
|
64
59
|
|
65
60
|
def stock_location
|
66
61
|
render 'spree/api/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
|
67
|
-
@stock_location ||= StockLocation.find(params[:stock_location_id])
|
62
|
+
@stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
|
68
63
|
end
|
69
64
|
|
70
65
|
def scope
|
71
|
-
|
72
|
-
|
66
|
+
@stock_location.stock_items.accessible_by(current_ability, :read).includes(:variant => :product)
|
67
|
+
end
|
68
|
+
|
69
|
+
def stock_item_params
|
70
|
+
params.require(:stock_item).permit(permitted_stock_item_attributes)
|
73
71
|
end
|
74
72
|
end
|
75
73
|
end
|
@@ -2,19 +2,17 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
class StockLocationsController < Spree::Api::BaseController
|
4
4
|
def index
|
5
|
-
authorize! :read, StockLocation
|
6
5
|
@stock_locations = StockLocation.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
7
6
|
respond_with(@stock_locations)
|
8
7
|
end
|
9
8
|
|
10
9
|
def show
|
11
|
-
authorize! :read, StockLocation
|
12
10
|
respond_with(stock_location)
|
13
11
|
end
|
14
12
|
|
15
13
|
def create
|
16
14
|
authorize! :create, StockLocation
|
17
|
-
@stock_location = StockLocation.new(
|
15
|
+
@stock_location = StockLocation.new(stock_location_params)
|
18
16
|
if @stock_location.save
|
19
17
|
respond_with(@stock_location, status: 201, default_template: :show)
|
20
18
|
else
|
@@ -23,8 +21,8 @@ module Spree
|
|
23
21
|
end
|
24
22
|
|
25
23
|
def update
|
26
|
-
authorize! :update,
|
27
|
-
if stock_location.update_attributes(
|
24
|
+
authorize! :update, stock_location
|
25
|
+
if stock_location.update_attributes(stock_location_params)
|
28
26
|
respond_with(stock_location, status: 200, default_template: :show)
|
29
27
|
else
|
30
28
|
invalid_resource!(stock_location)
|
@@ -32,7 +30,7 @@ module Spree
|
|
32
30
|
end
|
33
31
|
|
34
32
|
def destroy
|
35
|
-
authorize! :
|
33
|
+
authorize! :destroy, stock_location
|
36
34
|
stock_location.destroy
|
37
35
|
respond_with(stock_location, :status => 204)
|
38
36
|
end
|
@@ -40,7 +38,11 @@ module Spree
|
|
40
38
|
private
|
41
39
|
|
42
40
|
def stock_location
|
43
|
-
@stock_location ||= StockLocation.find(params[:id])
|
41
|
+
@stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:id])
|
42
|
+
end
|
43
|
+
|
44
|
+
def stock_location_params
|
45
|
+
params.require(:stock_location).permit(permitted_stock_location_attributes)
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -4,20 +4,18 @@ module Spree
|
|
4
4
|
before_filter :stock_location, except: [:update, :destroy]
|
5
5
|
|
6
6
|
def index
|
7
|
-
authorize! :read, StockMovement
|
8
7
|
@stock_movements = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
9
8
|
respond_with(@stock_movements)
|
10
9
|
end
|
11
10
|
|
12
11
|
def show
|
13
|
-
authorize! :read, StockMovement
|
14
12
|
@stock_movement = scope.find(params[:id])
|
15
13
|
respond_with(@stock_movement)
|
16
14
|
end
|
17
15
|
|
18
16
|
def create
|
19
17
|
authorize! :create, StockMovement
|
20
|
-
@stock_movement = scope.new(
|
18
|
+
@stock_movement = scope.new(stock_movement_params)
|
21
19
|
if @stock_movement.save
|
22
20
|
respond_with(@stock_movement, status: 201, default_template: :show)
|
23
21
|
else
|
@@ -29,11 +27,15 @@ module Spree
|
|
29
27
|
|
30
28
|
def stock_location
|
31
29
|
render 'spree/api/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
|
32
|
-
@stock_location ||= StockLocation.find(params[:stock_location_id])
|
30
|
+
@stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
|
33
31
|
end
|
34
32
|
|
35
33
|
def scope
|
36
|
-
@stock_location.stock_movements
|
34
|
+
@stock_location.stock_movements.accessible_by(current_ability, :read)
|
35
|
+
end
|
36
|
+
|
37
|
+
def stock_movement_params
|
38
|
+
params.require(:stock_movement).permit(permitted_stock_movement_attributes)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
@@ -1,17 +1,16 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class TaxonomiesController < Spree::Api::BaseController
|
4
|
-
respond_to :json
|
5
4
|
|
6
5
|
def index
|
7
|
-
@taxonomies = Taxonomy.order('name').includes(:root => :children).
|
6
|
+
@taxonomies = Taxonomy.accessible_by(current_ability, :read).order('name').includes(:root => :children).
|
8
7
|
ransack(params[:q]).result.
|
9
8
|
page(params[:page]).per(params[:per_page])
|
10
9
|
respond_with(@taxonomies)
|
11
10
|
end
|
12
11
|
|
13
12
|
def show
|
14
|
-
@taxonomy = Taxonomy.find(params[:id])
|
13
|
+
@taxonomy = Taxonomy.accessible_by(current_ability, :read).find(params[:id])
|
15
14
|
respond_with(@taxonomy)
|
16
15
|
end
|
17
16
|
|
@@ -22,7 +21,7 @@ module Spree
|
|
22
21
|
|
23
22
|
def create
|
24
23
|
authorize! :create, Taxonomy
|
25
|
-
@taxonomy = Taxonomy.new(
|
24
|
+
@taxonomy = Taxonomy.new(taxonomy_params)
|
26
25
|
if @taxonomy.save
|
27
26
|
respond_with(@taxonomy, :status => 201, :default_template => :show)
|
28
27
|
else
|
@@ -31,8 +30,8 @@ module Spree
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def update
|
34
|
-
authorize! :update,
|
35
|
-
if taxonomy.update_attributes(
|
33
|
+
authorize! :update, taxonomy
|
34
|
+
if taxonomy.update_attributes(taxonomy_params)
|
36
35
|
respond_with(taxonomy, :status => 200, :default_template => :show)
|
37
36
|
else
|
38
37
|
invalid_resource!(taxonomy)
|
@@ -40,7 +39,7 @@ module Spree
|
|
40
39
|
end
|
41
40
|
|
42
41
|
def destroy
|
43
|
-
authorize! :
|
42
|
+
authorize! :destroy, taxonomy
|
44
43
|
taxonomy.destroy
|
45
44
|
respond_with(taxonomy, :status => 204)
|
46
45
|
end
|
@@ -48,9 +47,16 @@ module Spree
|
|
48
47
|
private
|
49
48
|
|
50
49
|
def taxonomy
|
51
|
-
@taxonomy ||= Taxonomy.find(params[:id])
|
50
|
+
@taxonomy ||= Taxonomy.accessible_by(current_ability, :read).find(params[:id])
|
52
51
|
end
|
53
52
|
|
53
|
+
def taxonomy_params
|
54
|
+
if params[:taxonomy] && !params[:taxonomy].empty?
|
55
|
+
params.require(:taxonomy).permit(permitted_taxonomy_attributes)
|
56
|
+
else
|
57
|
+
{}
|
58
|
+
end
|
59
|
+
end
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
@@ -1,16 +1,14 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class TaxonsController < Spree::Api::BaseController
|
4
|
-
respond_to :json
|
5
|
-
|
6
4
|
def index
|
7
5
|
if taxonomy
|
8
6
|
@taxons = taxonomy.root.children
|
9
7
|
else
|
10
8
|
if params[:ids]
|
11
|
-
@taxons = Taxon.accessible_by(current_ability, :read).where(:
|
9
|
+
@taxons = Spree::Taxon.accessible_by(current_ability, :read).where(id: params[:ids].split(','))
|
12
10
|
else
|
13
|
-
@taxons = Taxon.accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
|
11
|
+
@taxons = Spree::Taxon.accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
@@ -29,51 +27,58 @@ module Spree
|
|
29
27
|
|
30
28
|
def create
|
31
29
|
authorize! :create, Taxon
|
32
|
-
@taxon = Taxon.new(
|
30
|
+
@taxon = Spree::Taxon.new(taxon_params)
|
33
31
|
@taxon.taxonomy_id = params[:taxonomy_id]
|
34
|
-
taxonomy = Taxonomy.
|
32
|
+
taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])
|
35
33
|
|
36
34
|
if taxonomy.nil?
|
37
|
-
@taxon.errors[:taxonomy_id] = I18n.t(:invalid_taxonomy_id, :
|
35
|
+
@taxon.errors[:taxonomy_id] = I18n.t(:invalid_taxonomy_id, scope: 'spree.api')
|
38
36
|
invalid_resource!(@taxon) and return
|
39
37
|
end
|
40
38
|
|
41
39
|
@taxon.parent_id = taxonomy.root.id unless params[:taxon][:parent_id]
|
42
40
|
|
43
41
|
if @taxon.save
|
44
|
-
respond_with(@taxon, :
|
42
|
+
respond_with(@taxon, status: 201, default_template: :show)
|
45
43
|
else
|
46
44
|
invalid_resource!(@taxon)
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
50
48
|
def update
|
51
|
-
authorize! :update,
|
52
|
-
if taxon.update_attributes(
|
53
|
-
respond_with(taxon, :
|
49
|
+
authorize! :update, taxon
|
50
|
+
if taxon.update_attributes(taxon_params)
|
51
|
+
respond_with(taxon, status: 200, default_template: :show)
|
54
52
|
else
|
55
53
|
invalid_resource!(taxon)
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
59
57
|
def destroy
|
60
|
-
authorize! :
|
58
|
+
authorize! :destroy, taxon
|
61
59
|
taxon.destroy
|
62
|
-
respond_with(taxon, :
|
60
|
+
respond_with(taxon, status: 204)
|
63
61
|
end
|
64
62
|
|
65
63
|
private
|
66
64
|
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
def taxonomy
|
66
|
+
if params[:taxonomy_id].present?
|
67
|
+
@taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:taxonomy_id])
|
68
|
+
end
|
70
69
|
end
|
71
|
-
end
|
72
70
|
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
def taxon
|
72
|
+
@taxon ||= taxonomy.taxons.accessible_by(current_ability, :read).find(params[:id])
|
73
|
+
end
|
76
74
|
|
75
|
+
def taxon_params
|
76
|
+
if params[:taxon] && !params[:taxon].empty?
|
77
|
+
params.require(:taxon).permit(permitted_taxon_attributes)
|
78
|
+
else
|
79
|
+
{}
|
80
|
+
end
|
81
|
+
end
|
77
82
|
end
|
78
83
|
end
|
79
84
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class UsersController < Spree::Api::BaseController
|
4
|
-
respond_to :json
|
5
4
|
|
6
5
|
def index
|
7
6
|
@users = Spree.user_class.accessible_by(current_ability,:read).ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
@@ -9,7 +8,6 @@ module Spree
|
|
9
8
|
end
|
10
9
|
|
11
10
|
def show
|
12
|
-
authorize! :show, user
|
13
11
|
respond_with(user)
|
14
12
|
end
|
15
13
|
|
@@ -18,7 +16,7 @@ module Spree
|
|
18
16
|
|
19
17
|
def create
|
20
18
|
authorize! :create, Spree.user_class
|
21
|
-
@user = Spree.user_class.new(
|
19
|
+
@user = Spree.user_class.new(user_params)
|
22
20
|
if @user.save
|
23
21
|
respond_with(@user, :status => 201, :default_template => :show)
|
24
22
|
else
|
@@ -28,7 +26,7 @@ module Spree
|
|
28
26
|
|
29
27
|
def update
|
30
28
|
authorize! :update, user
|
31
|
-
if user.update_attributes(
|
29
|
+
if user.update_attributes(user_params)
|
32
30
|
respond_with(user, :status => 200, :default_template => :show)
|
33
31
|
else
|
34
32
|
invalid_resource!(user)
|
@@ -44,7 +42,11 @@ module Spree
|
|
44
42
|
private
|
45
43
|
|
46
44
|
def user
|
47
|
-
@user ||= Spree.user_class.find(params[:id])
|
45
|
+
@user ||= Spree.user_class.accessible_by(current_ability, :read).find(params[:id])
|
46
|
+
end
|
47
|
+
|
48
|
+
def user_params
|
49
|
+
params.require(:user).permit(permitted_user_attributes)
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
@@ -1,68 +1,66 @@
|
|
1
1
|
module Spree
|
2
2
|
module Api
|
3
3
|
class VariantsController < Spree::Api::BaseController
|
4
|
-
respond_to :json
|
5
4
|
|
6
5
|
before_filter :product
|
7
6
|
|
7
|
+
def create
|
8
|
+
authorize! :create, Variant
|
9
|
+
@variant = scope.new(variant_params)
|
10
|
+
if @variant.save
|
11
|
+
respond_with(@variant, status: 201, default_template: :show)
|
12
|
+
else
|
13
|
+
invalid_resource!(@variant)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy
|
18
|
+
@variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
|
19
|
+
@variant.destroy
|
20
|
+
respond_with(@variant, status: 204)
|
21
|
+
end
|
22
|
+
|
8
23
|
def index
|
9
|
-
@variants = scope.includes(:option_values
|
24
|
+
@variants = scope.includes(:option_values).ransack(params[:q]).result.
|
10
25
|
page(params[:page]).per(params[:per_page])
|
11
26
|
respond_with(@variants)
|
12
27
|
end
|
13
28
|
|
14
|
-
def show
|
15
|
-
@variant = scope.includes(:option_values).find(params[:id])
|
16
|
-
respond_with(@variant)
|
17
|
-
end
|
18
|
-
|
19
29
|
def new
|
20
30
|
end
|
21
31
|
|
22
|
-
def
|
23
|
-
|
24
|
-
@variant
|
25
|
-
if @variant.save
|
26
|
-
respond_with(@variant, :status => 201, :default_template => :show)
|
27
|
-
else
|
28
|
-
invalid_resource!(@variant)
|
29
|
-
end
|
32
|
+
def show
|
33
|
+
@variant = scope.includes(:option_values).find(params[:id])
|
34
|
+
respond_with(@variant)
|
30
35
|
end
|
31
36
|
|
32
37
|
def update
|
33
|
-
|
34
|
-
@variant
|
35
|
-
|
36
|
-
respond_with(@variant, :status => 200, :default_template => :show)
|
38
|
+
@variant = scope.accessible_by(current_ability, :update).find(params[:id])
|
39
|
+
if @variant.update_attributes(variant_params)
|
40
|
+
respond_with(@variant, status: 200, default_template: :show)
|
37
41
|
else
|
38
42
|
invalid_resource!(@product)
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
42
|
-
def destroy
|
43
|
-
authorize! :delete, Variant
|
44
|
-
@variant = scope.find(params[:id])
|
45
|
-
@variant.destroy
|
46
|
-
respond_with(@variant, :status => 204)
|
47
|
-
end
|
48
|
-
|
49
46
|
private
|
47
|
+
|
50
48
|
def product
|
51
|
-
@product ||= Spree::Product.
|
49
|
+
@product ||= Spree::Product.accessible_by(current_ability, :read).find_by(permalink: params[:product_id]) if params[:product_id]
|
52
50
|
end
|
53
51
|
|
54
52
|
def scope
|
55
53
|
if @product
|
56
|
-
unless current_api_user.has_spree_role?(
|
57
|
-
variants = @product.variants_including_master
|
54
|
+
unless current_api_user.has_spree_role?('admin') || params[:show_deleted]
|
55
|
+
variants = @product.variants_including_master.accessible_by(current_ability, :read)
|
58
56
|
else
|
59
|
-
variants = @product.variants_including_master.with_deleted
|
57
|
+
variants = @product.variants_including_master.with_deleted.accessible_by(current_ability, :read)
|
60
58
|
end
|
61
59
|
else
|
62
|
-
variants = Variant.
|
63
|
-
if current_api_user.has_spree_role?(
|
60
|
+
variants = Variant.accessible_by(current_ability, :read)
|
61
|
+
if current_api_user.has_spree_role?('admin')
|
64
62
|
unless params[:show_deleted]
|
65
|
-
variants = Variant.active
|
63
|
+
variants = Variant.accessible_by(current_ability, :read).active
|
66
64
|
end
|
67
65
|
else
|
68
66
|
variants = variants.active
|
@@ -70,6 +68,10 @@ module Spree
|
|
70
68
|
end
|
71
69
|
variants
|
72
70
|
end
|
71
|
+
|
72
|
+
def variant_params
|
73
|
+
params.require(:variant).permit(permitted_variant_attributes)
|
74
|
+
end
|
73
75
|
end
|
74
76
|
end
|
75
77
|
end
|
@@ -2,15 +2,6 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
class ZonesController < Spree::Api::BaseController
|
4
4
|
|
5
|
-
def index
|
6
|
-
@zones = Zone.order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
7
|
-
respond_with(@zones)
|
8
|
-
end
|
9
|
-
|
10
|
-
def show
|
11
|
-
respond_with(zone)
|
12
|
-
end
|
13
|
-
|
14
5
|
def create
|
15
6
|
authorize! :create, Zone
|
16
7
|
@zone = Zone.new(map_nested_attributes_keys(Spree::Zone, params[:zone]))
|
@@ -21,8 +12,23 @@ module Spree
|
|
21
12
|
end
|
22
13
|
end
|
23
14
|
|
15
|
+
def destroy
|
16
|
+
authorize! :destroy, zone
|
17
|
+
zone.destroy
|
18
|
+
respond_with(zone, :status => 204)
|
19
|
+
end
|
20
|
+
|
21
|
+
def index
|
22
|
+
@zones = Zone.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
23
|
+
respond_with(@zones)
|
24
|
+
end
|
25
|
+
|
26
|
+
def show
|
27
|
+
respond_with(zone)
|
28
|
+
end
|
29
|
+
|
24
30
|
def update
|
25
|
-
authorize! :update,
|
31
|
+
authorize! :update, zone
|
26
32
|
if zone.update_attributes(map_nested_attributes_keys(Spree::Zone, params[:zone]))
|
27
33
|
respond_with(zone, :status => 200, :default_template => :show)
|
28
34
|
else
|
@@ -30,15 +36,10 @@ module Spree
|
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
33
|
-
def destroy
|
34
|
-
authorize! :delete, Zone
|
35
|
-
zone.destroy
|
36
|
-
respond_with(zone, :status => 204)
|
37
|
-
end
|
38
|
-
|
39
39
|
private
|
40
|
+
|
40
41
|
def zone
|
41
|
-
@zone ||= Spree::Zone.find(params[:id])
|
42
|
+
@zone ||= Spree::Zone.accessible_by(current_ability, :read).find(params[:id])
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|