solidus_api 4.4.2 → 4.5.1

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: ccb7042536c398b4ec1ac42d06e05569e5fbc21ca387fc76cb07079d373de638
4
- data.tar.gz: ac80c694f158a1e752fc12fb37252a188c4e723d985ab7f2c56f8f3d306c491b
3
+ metadata.gz: 2b3fd9044a23f9e90d975679f852a3d2d78de8ce247c0e2c0aa79aca920d2465
4
+ data.tar.gz: dcc797abebfe49d10d802dad0c7b7b7cae1d21b3aaf1a05455fa4a6a9dd48c17
5
5
  SHA512:
6
- metadata.gz: 80b96625d96147c50f662a84fbb87d922b93f910d9027219c42000bdd0e0a2427d6c0a39d70e7d9619e5adbfc4a813d79cb9fb9e43ec1ee394fd901fbb736bdb
7
- data.tar.gz: e169ef6eafb44a080369c95ae10d399decf22f9fab5a2cb05dc4592d8d0d87176fc35e2ab29916d7e7366fa437975ee58ac85c7ea481a4c1a4dfca8e55d39be6
6
+ metadata.gz: cb9130b933a3b5854cafb66610969e46e751fe612eb25d5fd10a9eaf3b98d1a2a0269ae018a625c69f48b48d1f90b36bd32f4264d323b1daccab3fa4003cddf2
7
+ data.tar.gz: 74185c1bd1d9cc5d032b0c18d4918b4da9dd0de47df0d69dd0b8a5d1f05c8d2b2159621acd184b85b7752ab9aefb27571636531add366d6ea9430737511d4ff4
@@ -18,6 +18,9 @@ module Spree
18
18
  class_attribute :admin_line_item_attributes
19
19
  self.admin_line_item_attributes = [:price, :variant_id, :sku]
20
20
 
21
+ class_attribute :admin_metadata_attributes
22
+ self.admin_metadata_attributes = [{ admin_metadata: {} }]
23
+
21
24
  attr_accessor :current_api_user
22
25
 
23
26
  before_action :load_user
@@ -35,15 +38,29 @@ module Spree
35
38
 
36
39
  private
37
40
 
41
+ Spree::Api::Config.metadata_permit_parameters.each do |resource|
42
+ define_method("permitted_#{resource.to_s.underscore}_attributes") do
43
+ if can?(:admin, "Spree::#{resource}".constantize)
44
+ super() + admin_metadata_attributes
45
+ else
46
+ super()
47
+ end
48
+ end
49
+ end
50
+
38
51
  # users should be able to set price when importing orders via api
39
52
  def permitted_line_item_attributes
40
53
  if can?(:admin, Spree::LineItem)
41
- super + admin_line_item_attributes
54
+ super + admin_line_item_attributes + admin_metadata_attributes
42
55
  else
43
56
  super
44
57
  end
45
58
  end
46
59
 
60
+ def permitted_user_attributes
61
+ can?(:admin, Spree.user_class) ? super + admin_metadata_attributes : super
62
+ end
63
+
47
64
  def load_user
48
65
  @current_api_user ||= Spree.user_class.find_by(spree_api_key: api_key.to_s)
49
66
  end
@@ -15,8 +15,10 @@ module Spree
15
15
  @line_item = @order.contents.add(
16
16
  variant,
17
17
  params[:line_item][:quantity] || 1,
18
- options: line_item_params[:options].to_h
18
+ options: line_item_params[:options].to_h,
19
+ **extract_metadata
19
20
  )
21
+
20
22
  respond_with(@line_item, status: 201, default_template: :show)
21
23
  rescue ActiveRecord::RecordInvalid => error
22
24
  invalid_resource!(error.record)
@@ -56,10 +58,21 @@ module Spree
56
58
  { line_items_attributes: {
57
59
  id: params[:id],
58
60
  quantity: params[:line_item][:quantity],
59
- options: line_item_params[:options] || {}
61
+ options: line_item_params[:options] || {},
62
+ **extract_metadata
60
63
  } }
61
64
  end
62
65
 
66
+ def extract_metadata
67
+ metadata = { customer_metadata: line_item_params[:customer_metadata] }
68
+
69
+ if @current_user_roles&.include?("admin")
70
+ metadata[:admin_metadata] = line_item_params[:admin_metadata]
71
+ end
72
+
73
+ metadata
74
+ end
75
+
63
76
  def line_item_params
64
77
  params.require(:line_item).permit(permitted_line_item_attributes)
65
78
  end
@@ -112,12 +112,19 @@ module Spree
112
112
  def order_params
113
113
  if params[:order]
114
114
  normalize_params
115
+ prevent_customer_metadata_update
115
116
  params.require(:order).permit(permitted_order_attributes)
116
117
  else
117
118
  {}
118
119
  end
119
120
  end
120
121
 
122
+ def prevent_customer_metadata_update
123
+ return unless @order&.completed? && cannot?(:admin, Spree::Order)
124
+
125
+ params[:order].delete(:customer_metadata) if params[:order]
126
+ end
127
+
121
128
  def normalize_params
122
129
  if params[:order][:payments]
123
130
  payments_params = params[:order].delete(:payments)
@@ -43,6 +43,16 @@ module Spree
43
43
  end
44
44
  end
45
45
 
46
+ Spree::Api::Config.metadata_api_parameters.each do |method_name, resource|
47
+ define_method("#{method_name}_attributes") do
48
+ authorized_attributes(resource, "#{method_name}_attributes")
49
+ end
50
+ end
51
+
52
+ def authorized_attributes(resource, config_attribute)
53
+ can?(:admin, resource) ? Spree::Api::Config.public_send(config_attribute) + [:admin_metadata] : Spree::Api::Config.public_send(config_attribute)
54
+ end
55
+
46
56
  def required_fields_for(model)
47
57
  required_fields = model._validators.select do |_field, validations|
48
58
  validations.any? { |validation| validation.is_a?(ActiveModel::Validations::PresenceValidator) }
@@ -7,13 +7,13 @@ module Spree
7
7
  preference :product_attributes, :array, default: [
8
8
  :id, :name, :description, :available_on,
9
9
  :slug, :meta_description, :meta_keywords, :shipping_category_id,
10
- :taxon_ids, :total_on_hand, :meta_title
10
+ :taxon_ids, :total_on_hand, :meta_title, :primary_taxon_id
11
11
  ]
12
12
 
13
13
  preference :product_property_attributes, :array, default: [:id, :product_id, :property_id, :value, :property_name]
14
14
 
15
15
  preference :variant_attributes, :array, default: [
16
- :id, :name, :sku, :weight, :height, :width, :depth, :is_master,
16
+ :id, :name, :sku, :gtin, :condition, :weight, :height, :width, :depth, :is_master,
17
17
  :slug, :description, :track_inventory
18
18
  ]
19
19
 
@@ -36,22 +36,44 @@ module Spree
36
36
  :covered_by_store_credit, :display_total_applicable_store_credit,
37
37
  :order_total_after_store_credit, :display_order_total_after_store_credit,
38
38
  :total_applicable_store_credit, :display_total_available_store_credit,
39
- :display_store_credit_remaining_after_capture, :canceler_id
39
+ :display_store_credit_remaining_after_capture, :canceler_id, :customer_metadata
40
40
  ]
41
41
 
42
- preference :line_item_attributes, :array, default: [:id, :quantity, :price, :variant_id]
42
+ preference :line_item_attributes, :array, default: [:id, :quantity, :price, :variant_id, :customer_metadata]
43
+
44
+ # Spree::Api::Config.metadata_api_parameters contains the models
45
+ # to which the admin_metadata attribute is added
46
+ preference :metadata_api_parameters, :array, default: [
47
+ [:order, 'Spree::Order'],
48
+ [:customer_return, 'Spree::CustomerReturn'],
49
+ [:payment, 'Spree::Payment'],
50
+ [:return_authorization, 'Spree::ReturnAuthorization'],
51
+ [:shipment, 'Spree::Shipment'],
52
+ [:user, 'Spree.user_class'],
53
+ [:line_item, 'Spree::LineItem']
54
+ ]
55
+
56
+ # Spree::Api::Config.metadata_permit_parameters contains the models
57
+ # to which the admin_metadata attribute is permitted
58
+ preference :metadata_permit_parameters, :array, default: [
59
+ :Order,
60
+ :CustomerReturn,
61
+ :Payment,
62
+ :ReturnAuthorization,
63
+ :Shipment
64
+ ]
43
65
 
44
66
  preference :option_type_attributes, :array, default: [:id, :name, :presentation, :position]
45
67
 
46
68
  preference :payment_attributes, :array, default: [
47
69
  :id, :source_type, :source_id, :amount, :display_amount,
48
70
  :payment_method_id, :state, :avs_response, :created_at,
49
- :updated_at
71
+ :updated_at, :customer_metadata
50
72
  ]
51
73
 
52
74
  preference :payment_method_attributes, :array, default: [:id, :name, :description]
53
75
 
54
- preference :shipment_attributes, :array, default: [:id, :tracking, :tracking_url, :number, :cost, :shipped_at, :state]
76
+ preference :shipment_attributes, :array, default: [:id, :tracking, :tracking_url, :number, :cost, :shipped_at, :state, :customer_metadata]
55
77
 
56
78
  preference :taxonomy_attributes, :array, default: [:id, :name]
57
79
 
@@ -81,11 +103,11 @@ module Spree
81
103
  ]
82
104
 
83
105
  preference :customer_return_attributes, :array, default: [
84
- :id, :number, :stock_location_id, :created_at, :updated_at
106
+ :id, :number, :stock_location_id, :created_at, :updated_at, :customer_metadata
85
107
  ]
86
108
 
87
109
  preference :return_authorization_attributes, :array, default: [
88
- :id, :number, :state, :order_id, :memo, :created_at, :updated_at
110
+ :id, :number, :state, :order_id, :memo, :created_at, :updated_at, :customer_metadata
89
111
  ]
90
112
 
91
113
  preference :creditcard_attributes, :array, default: [
@@ -96,7 +118,7 @@ module Spree
96
118
  :id, :month, :year, :cc_type, :last_digits, :name
97
119
  ]
98
120
 
99
- preference :user_attributes, :array, default: [:id, :email, :created_at, :updated_at]
121
+ preference :user_attributes, :array, default: [:id, :email, :created_at, :updated_at, :customer_metadata]
100
122
 
101
123
  preference :property_attributes, :array, default: [:id, :name, :presentation]
102
124
 
@@ -132,7 +154,7 @@ module Spree
132
154
 
133
155
  preference :store_credit_history_attributes, :array, default: [
134
156
  :display_amount, :display_user_total_amount, :display_action,
135
- :display_event_date, :display_remaining_amount
157
+ :display_event_date, :display_remaining_amount, :customer_metadata
136
158
  ]
137
159
 
138
160
  preference :variant_property_attributes, :array, default: [
@@ -74,6 +74,8 @@ paths:
74
74
  product:
75
75
  name: The Majestic Product
76
76
  price: '19.99'
77
+ gtin: 12345678
78
+ condition: new
77
79
  shipping_category_id: 8
78
80
  product_properties_attributes:
79
81
  - property_name: fabric
@@ -86,6 +88,8 @@ paths:
86
88
  - price: 19.99
87
89
  cost_price: 17
88
90
  sku: SKU-3
91
+ gtin: 12345678
92
+ condition: new
89
93
  track_inventory: true
90
94
  options:
91
95
  - name: size
@@ -1169,10 +1173,7 @@ paths:
1169
1173
  '422':
1170
1174
  $ref: '#/components/responses/delete-restriction'
1171
1175
  summary: Remove address from user address book
1172
- description: |-
1173
- Removes an address from a user's address book.
1174
-
1175
- **Note:** Rather than delete a `Spree::UserAddress` record this action set its `archived` attribute to `true`.
1176
+ description: Removes an address from a user's address book.
1176
1177
  operationId: remove-address-from-user-address-book
1177
1178
  tags:
1178
1179
  - Address books
@@ -1201,11 +1202,7 @@ paths:
1201
1202
  operationId: update-user-address-book
1202
1203
  tags:
1203
1204
  - Address books
1204
- description: |-
1205
- Updates a user's address book.
1206
-
1207
- **Note:** if the passed `id` matches an existing `address` a new `Spree::Address` record will be created and the matched `address` `archived` on `Spree::UserAddress`. For a similar logic, if the passed `id` matches an existing `address` which is in `archived` state, the `Spree::UserAddress#archived` record will be restored to `false`.
1208
- See `user_address_book.rb` for further information.
1205
+ description: Updates a user's address book.
1209
1206
  security:
1210
1207
  - api-key: []
1211
1208
  requestBody:
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.2
4
+ version: 4.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-09 00:00:00.000000000 Z
10
+ date: 2025-03-06 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: jbuilder
@@ -58,14 +57,14 @@ dependencies:
58
57
  requirements:
59
58
  - - '='
60
59
  - !ruby/object:Gem::Version
61
- version: 4.4.2
60
+ version: 4.5.1
62
61
  type: :runtime
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - '='
67
66
  - !ruby/object:Gem::Version
68
- version: 4.4.2
67
+ version: 4.5.1
69
68
  description: REST API for the Solidus e-commerce framework.
70
69
  email: contact@solidus.io
71
70
  executables: []
@@ -257,7 +256,6 @@ licenses:
257
256
  - BSD-3-Clause
258
257
  metadata:
259
258
  rubygems_mfa_required: 'true'
260
- post_install_message:
261
259
  rdoc_options: []
262
260
  require_paths:
263
261
  - lib
@@ -272,8 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
270
  - !ruby/object:Gem::Version
273
271
  version: 1.8.23
274
272
  requirements: []
275
- rubygems_version: 3.5.3
276
- signing_key:
273
+ rubygems_version: 3.6.5
277
274
  specification_version: 4
278
275
  summary: REST API for the Solidus e-commerce framework.
279
276
  test_files: []