solidus_api 4.7.1 → 4.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92ccd1baa7331139315707fd902eeec5712a41d6563f713611c4c4c32beaff34
4
- data.tar.gz: 2b93ffdf94c871ec54eaabda3c9c4b46e5108283e1d2aa99686dba426e811cf2
3
+ metadata.gz: eccdd48bcff16941d9551a3033ae485cc07f7d44c5c20261649d8d81d5075b68
4
+ data.tar.gz: 3eeb7c3954e19d82dc3ee4b55a1c860845f03e8f4d9f5a5cdab46940c7220469
5
5
  SHA512:
6
- metadata.gz: d91812f69f054d0536f3bd0bc34a7c028ded3d4172917348d587fbeac25b2a5bb7e2eab28f38d6ae72f82a0a781137c4c53372005c876c42abaf6b115ba9a95f
7
- data.tar.gz: 2eb2ce76ec4d4a9892f7fa3fd99691f81376cdb0580f8ca39c227ba2f7c394ddb25b14c7e1180cbe931ad0c7f8d5d4d297988b576eabe7f5ca2e70451bbbc920
6
+ metadata.gz: 66b961c53c70065c4aa9d9678bf6af6592f9e66faa0821cac2fa362761483cae12f436dfd9754cf0de42c79df1bc86b301010ff6d4e45c7f6e0ff55c4771996e
7
+ data.tar.gz: 754d8fae5afee560ce720c863c15a02d2f21d12f85a4bff6e1b07c86b3cd0549e5a57bf4e7fa003fb2853bd79e042f4b93843b3edc62d6e32c2031ac5dd3337c
@@ -15,7 +15,7 @@ module Spree
15
15
  authorize! :update, @order, order_token
16
16
  find_address
17
17
 
18
- success = @order.update({"#{@order_source}_attributes" => address_params})
18
+ success = @order.contents.update_cart({"#{@order_source}_attributes" => address_params})
19
19
  @address = @order.send(@order_source)
20
20
 
21
21
  if success
@@ -105,10 +105,20 @@ module Spree
105
105
  end
106
106
 
107
107
  def update_order_state
108
- @order.state = params[:state] if params[:state]
108
+ return unless params[:state]
109
+
110
+ unless Spree::Api::Config.allow_arbitrary_state_in_checkout || valid_checkout_step?(params[:state])
111
+ return respond_with(@order, default_template: "spree/api/orders/invalid_state", status: 422)
112
+ end
113
+
114
+ @order.state = params[:state]
109
115
  state_callback(:before)
110
116
  end
111
117
 
118
+ def valid_checkout_step?(step)
119
+ @order.passed_checkout_step?(step) || @order.state == step
120
+ end
121
+
112
122
  def state_callback(before_or_after = :before)
113
123
  method_name = :"#{before_or_after}_#{@order.state}"
114
124
  send(method_name) if respond_to?(method_name, true)
@@ -119,6 +119,7 @@ module Spree
119
119
  if params[:order]
120
120
  normalize_params
121
121
  prevent_customer_metadata_update
122
+ prevent_line_item_variant_update
122
123
  params.require(:order).permit(permitted_order_attributes)
123
124
  else
124
125
  {}
@@ -131,6 +132,16 @@ module Spree
131
132
  params[:order]&.delete(:customer_metadata)
132
133
  end
133
134
 
135
+ def prevent_line_item_variant_update
136
+ line_items_attributes = params[:order][:line_items_attributes]
137
+ return unless line_items_attributes
138
+
139
+ line_items_attributes = line_items_attributes.values unless line_items_attributes.is_a?(Array)
140
+ line_items_attributes.each do |line_item_attributes|
141
+ line_item_attributes.delete(:variant_id) if line_item_attributes[:id].present?
142
+ end
143
+ end
144
+
134
145
  def normalize_params
135
146
  if params[:order][:payments]
136
147
  payments_params = params[:order].delete(:payments)
@@ -21,8 +21,7 @@ module Spree
21
21
  end
22
22
 
23
23
  @products = paginate(@products.distinct)
24
- expires_in 15.minutes, public: true
25
- headers["Surrogate-Control"] = "max-age=#{15.minutes}"
24
+ set_cache_headers
26
25
  respond_with(@products)
27
26
  end
28
27
 
@@ -31,9 +30,7 @@ module Spree
31
30
 
32
31
  def show
33
32
  @product = find_product(params[:id])
34
- expires_in 15.minutes, public: true
35
- headers["Surrogate-Control"] = "max-age=#{15.minutes}"
36
- headers["Surrogate-Key"] = "product_id=1"
33
+ set_cache_headers(surrogate_key: "product_id=#{@product.id}")
37
34
  respond_with(@product)
38
35
  end
39
36
 
@@ -108,6 +105,14 @@ module Spree
108
105
 
109
106
  private
110
107
 
108
+ def set_cache_headers(surrogate_key: nil)
109
+ return if current_api_user
110
+
111
+ expires_in 15.minutes, public: true
112
+ headers["Surrogate-Control"] = "max-age=#{15.minutes}"
113
+ headers["Surrogate-Key"] = surrogate_key if surrogate_key
114
+ end
115
+
111
116
  def product_params
112
117
  product_params = params.require(:product).permit(permitted_product_attributes)
113
118
  if product_params[:taxon_ids].present?
@@ -99,7 +99,10 @@ module Spree
99
99
  end
100
100
 
101
101
  def transfer_to_shipment
102
- @desired_shipment ||= Spree::Shipment.find_by!(number: params[:target_shipment_number])
102
+ unless @desired_shipment
103
+ @desired_shipment = @original_shipment.order.shipments.find_by!(number: params[:target_shipment_number])
104
+ authorize! :update, @desired_shipment
105
+ end
103
106
 
104
107
  fulfilment_changer = Spree::FulfilmentChanger.new(
105
108
  current_shipment: @original_shipment,
@@ -80,10 +80,16 @@ class Spree::Api::UsersController < Spree::Api::BaseController
80
80
  end
81
81
 
82
82
  def permitted_user_attributes
83
+ attributes = super
84
+
83
85
  if action_name == "create" || can?(:update_email, @user)
84
- super | [:email]
85
- else
86
- super
86
+ attributes |= [:email]
87
87
  end
88
+
89
+ unless action_name == "create" || @user == current_api_user || can?(:update_password, @user)
90
+ attributes -= [:password, :password_confirmation]
91
+ end
92
+
93
+ attributes
88
94
  end
89
95
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, line_item] do
3
+ json.cache! [I18n.locale, line_item, line_item_attributes, variant_attributes] do
4
4
  json.call(line_item, *line_item_attributes)
5
5
  json.single_display_amount(line_item.single_display_amount.to_s)
6
6
  json.display_amount(line_item.display_amount.to_s)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, order] do
3
+ json.cache! [I18n.locale, order, order_attributes] do
4
4
  json.call(order, *order_attributes)
5
5
  json.display_item_total(order.display_item_total.to_s)
6
6
  json.total_quantity(order.line_items.to_a.sum(&:quantity))
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ json.errors(state: [I18n.t(:invalid_state, scope: "spree.api.order")])
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, shipment] do
3
+ json.cache! [I18n.locale, shipment, shipment_attributes, line_item_attributes, order_attributes, variant_attributes] do
4
4
  json.call(shipment, *shipment_attributes)
5
5
  json.partial!("spree/api/shipments/small", shipment:)
6
6
  json.inventory_units(shipment.inventory_units) do |inventory_unit|
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, shipment] do
3
+ json.cache! [I18n.locale, shipment, shipment_attributes] do
4
4
  json.call(shipment, *shipment_attributes)
5
5
  json.order_id(shipment.order.number)
6
6
  json.stock_location_name(shipment.stock_location.name)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, @shipment] do
3
+ json.cache! [I18n.locale, @shipment, shipment_attributes, variant_attributes] do
4
4
  json.call(@shipment, *shipment_attributes)
5
5
  json.order_id(@shipment.order.number)
6
6
  json.stock_location_name(@shipment.stock_location.name)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, Spree::StockLocation.accessible_by(current_ability), variant] do
3
+ json.cache! [I18n.locale, Spree::StockLocation.accessible_by(current_ability), variant, variant_attributes] do
4
4
  json.call(variant, *variant_attributes)
5
5
  json.partial!("spree/api/variants/small", variant:)
6
6
  json.variant_properties(variant.variant_properties) do |variant_property|
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- json.cache! [I18n.locale, current_pricing_options, variant] do
3
+ json.cache! [I18n.locale, current_pricing_options, variant, variant_attributes] do
4
4
  json.call(variant, *variant_attributes)
5
5
  json.price(variant.price_for_options(current_pricing_options)&.amount)
6
6
  json.display_price(variant.price_for_options(current_pricing_options)&.money&.to_s)
@@ -12,6 +12,7 @@ en:
12
12
  order:
13
13
  expected_total_mismatch: Expected total does not match actual total.
14
14
  invalid_shipping_method: Invalid shipping method specified.
15
+ invalid_state: Invalid state specified.
15
16
  quantity_is_not_available: Quantity is not available for items in your order
16
17
  payment:
17
18
  credit_over_limit: This payment can only be credited up to %{limit}. Please specify an amount less than or equal to this number.
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Spree
4
4
  class ApiConfiguration < Preferences::Configuration
5
+ # @!attribute [rw] allow_arbitrary_state_in_api
6
+ # @return [Boolean] When true, the API will allow arbitrary state transitions on orders (default: +false+)
7
+ preference :allow_arbitrary_state_in_checkout, :boolean, default: false
8
+
5
9
  preference :requires_authentication, :boolean, default: true
6
10
 
7
11
  preference :product_attributes, :array, default: [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.1
4
+ version: 4.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
@@ -57,14 +57,14 @@ dependencies:
57
57
  requirements:
58
58
  - - '='
59
59
  - !ruby/object:Gem::Version
60
- version: 4.7.1
60
+ version: 4.7.3
61
61
  type: :runtime
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - '='
66
66
  - !ruby/object:Gem::Version
67
- version: 4.7.1
67
+ version: 4.7.3
68
68
  description: REST API for the Solidus e-commerce framework.
69
69
  email: contact@solidus.io
70
70
  executables: []
@@ -152,6 +152,7 @@ files:
152
152
  - app/views/spree/api/orders/expected_total_mismatch.json.jbuilder
153
153
  - app/views/spree/api/orders/index.json.jbuilder
154
154
  - app/views/spree/api/orders/invalid_shipping_method.json.jbuilder
155
+ - app/views/spree/api/orders/invalid_state.json.jbuilder
155
156
  - app/views/spree/api/orders/mine.json.jbuilder
156
157
  - app/views/spree/api/orders/show.json.jbuilder
157
158
  - app/views/spree/api/payments/credit_over_limit.json.jbuilder