spree_api 6.0.3 → 6.0.5

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -5
  3. data/app/controllers/concerns/spree/api/v3/idempotent.rb +10 -1
  4. data/app/controllers/concerns/spree/api/v3/security_headers.rb +3 -0
  5. data/app/controllers/concerns/spree/api/v3/storefront_gating.rb +4 -2
  6. data/app/controllers/spree/api/v3/admin/base_controller.rb +31 -0
  7. data/app/controllers/spree/api/v3/admin/categories_controller.rb +1 -1
  8. data/app/controllers/spree/api/v3/admin/companies/memberships_controller.rb +21 -4
  9. data/app/controllers/spree/api/v3/admin/diagnostics_controller.rb +46 -0
  10. data/app/controllers/spree/api/v3/admin/me_controller.rb +0 -13
  11. data/app/controllers/spree/api/v3/admin/media_controller.rb +10 -0
  12. data/app/controllers/spree/api/v3/admin/orders/items_controller.rb +6 -2
  13. data/app/controllers/spree/api/v3/admin/sellers/invitations_controller.rb +39 -3
  14. data/app/controllers/spree/api/v3/admin/sellers/team_controller.rb +1 -3
  15. data/app/controllers/spree/api/v3/admin/sellers_controller.rb +24 -1
  16. data/app/controllers/spree/api/v3/admin/stock_levels_controller.rb +15 -1
  17. data/app/controllers/spree/api/v3/admin/store_controller.rb +9 -1
  18. data/app/controllers/spree/api/v3/admin/updates_controller.rb +4 -15
  19. data/app/controllers/spree/api/v3/seller/option_types_controller.rb +41 -0
  20. data/app/controllers/spree/api/v3/seller/products/media_controller.rb +46 -0
  21. data/app/controllers/spree/api/v3/seller/products_controller.rb +39 -2
  22. data/app/controllers/spree/api/v3/seller/profile_controller.rb +13 -5
  23. data/app/controllers/spree/api/v3/store/carts/store_credits_controller.rb +7 -3
  24. data/app/controllers/spree/api/v3/store/carts_controller.rb +11 -8
  25. data/app/controllers/spree/api/v3/store/categories_controller.rb +1 -1
  26. data/app/controllers/spree/api/v3/store/companies/addresses_controller.rb +1 -1
  27. data/app/controllers/spree/api/v3/store/store_controller.rb +3 -2
  28. data/app/request_schemas/spree/api/v3/seller/variant_request_schema.rb +4 -0
  29. data/app/request_schemas/spree/api/v3/store/address_request_schema.rb +2 -2
  30. data/app/serializers/spree/api/v3/address_serializer.rb +3 -3
  31. data/app/serializers/spree/api/v3/admin/address_serializer.rb +1 -1
  32. data/app/serializers/spree/api/v3/admin/company_membership_serializer.rb +4 -0
  33. data/app/serializers/spree/api/v3/admin/diagnostics_serializer.rb +30 -0
  34. data/app/serializers/spree/api/v3/admin/line_item_serializer.rb +6 -1
  35. data/app/serializers/spree/api/v3/admin/market_serializer.rb +1 -1
  36. data/app/serializers/spree/api/v3/admin/refund_serializer.rb +1 -1
  37. data/app/serializers/spree/api/v3/admin/seller_serializer.rb +10 -0
  38. data/app/serializers/spree/api/v3/admin/stock_location_serializer.rb +1 -1
  39. data/app/serializers/spree/api/v3/admin/store_serializer.rb +0 -7
  40. data/app/serializers/spree/api/v3/base_serializer.rb +1 -1
  41. data/app/serializers/spree/api/v3/cart_serializer.rb +4 -3
  42. data/app/serializers/spree/api/v3/country_serializer.rb +1 -1
  43. data/app/serializers/spree/api/v3/currency_serializer.rb +3 -2
  44. data/app/serializers/spree/api/v3/locale_serializer.rb +1 -1
  45. data/app/serializers/spree/api/v3/market_serializer.rb +2 -2
  46. data/app/serializers/spree/api/v3/price_history_serializer.rb +1 -1
  47. data/app/serializers/spree/api/v3/price_serializer.rb +2 -2
  48. data/app/serializers/spree/api/v3/product_category_serializer.rb +26 -0
  49. data/app/serializers/spree/api/v3/product_collection_serializer.rb +26 -0
  50. data/app/serializers/spree/api/v3/refund_serializer.rb +2 -2
  51. data/app/serializers/spree/api/v3/seller/address_serializer.rb +1 -1
  52. data/app/serializers/spree/api/v3/seller/option_type_serializer.rb +18 -0
  53. data/app/serializers/spree/api/v3/seller/order_line_item_serializer.rb +2 -2
  54. data/app/serializers/spree/api/v3/seller/product_serializer.rb +1 -1
  55. data/app/serializers/spree/api/v3/seller/product_type_serializer.rb +8 -7
  56. data/app/serializers/spree/api/v3/seller/stock_location_serializer.rb +1 -1
  57. data/app/serializers/spree/api/v3/stock_location_serializer.rb +3 -3
  58. data/app/serializers/spree/api/v3/store_serializer.rb +17 -5
  59. data/app/services/spree/api/v3/request_schema.rb +1 -1
  60. data/config/routes.rb +9 -2
  61. data/lib/spree/api/agent_resource_map.rb +42 -7
  62. data/lib/spree/api/dependencies.rb +6 -6
  63. data/lib/spree/api/oauth.rb +8 -19
  64. data/lib/spree/api/openapi/path_sorter.rb +91 -74
  65. data/lib/spree/api/testing_support/openapi.rb +2 -1
  66. data/lib/spree/api/testing_support/sdk_method.rb +34 -0
  67. data/lib/spree/api/typelizer_generation.rb +1 -1
  68. data/openapi/admin.yaml +34498 -34007
  69. data/openapi/store.yaml +9144 -9102
  70. metadata +14 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f1aae2e30afb2db5577e3315cd2779ab8f273bfa114b7e369f7c0c8a519214d
4
- data.tar.gz: 15e89346921cf2a0f21bdccd6050e7f4854d0aea5d17d0ef666d853ea475f769
3
+ metadata.gz: f34f6665b12790e158bff2ef546d9d5b055e1c8e86c2e2331868dbcecda9285f
4
+ data.tar.gz: 64ca7895cf3891dbaf1c0ec665408a42eec99aa197b7788c13f7ce45be151611
5
5
  SHA512:
6
- metadata.gz: 555454b4f93a2ec776ebd7a1c6ea407bbc359b10493768c838d29617b0d58011a024168a2f384c4e2ad21a983a2f31e3989afce90d864c6f272f5bc13b7253ae
7
- data.tar.gz: 0f00cda28bba945fc65e7509cfd61bd5626af3c91957e2f6dea5819e078593a7aad38152e5439495019bfdaece73cfaf65751313a10604f6af4f864176f84cb1
6
+ metadata.gz: 95a763713fde3a71aa0f01e23761d6dd63a6662f50ca58a21e4c63a5492cb1938c206783d837ad5292fcd008bf4267beba2df7345a1c177d36a97781bb80f936
7
+ data.tar.gz: dea78274d81838b3bce43dbb0db6cf67b393819b1e9ac4ed790d184b95c3f7870c3c83e8f701dac85c9a5ca3ecab46a892b70a8e5869c24a589c77f355d1a07b
data/Rakefile CHANGED
@@ -28,10 +28,8 @@ namespace :rswag do
28
28
  t.rspec_opts = ['--format Rswag::Specs::SwaggerFormatter', '--order defined']
29
29
  end
30
30
 
31
- # rswag emits paths in spec-load order (alphabetical by filename), which doesn't
32
- # match the curated order in swagger_helper.rb's `tags:` array. Mintlify groups
33
- # sidebar sections by first-tag-appearance in `paths:`, so reorder paths here
34
- # so the sidebar follows the `tags:` array.
31
+ # Mintlify orders sidebar groups by first tag appearance in `paths:`, so sort
32
+ # the groups alphabetically (Authentication first).
35
33
  Rake::Task['rswag:specs:swaggerize'].enhance do
36
34
  $LOAD_PATH.unshift(File.expand_path('lib', __dir__))
37
35
  require 'spree/api/openapi/path_sorter'
@@ -42,7 +40,7 @@ namespace :rswag do
42
40
  next unless File.exist?(path)
43
41
 
44
42
  if Spree::Api::OpenAPI::PathSorter.sort_file!(path)
45
- puts "Reordered paths by tag → #{path}"
43
+ puts "Sorted paths and tags → #{path}"
46
44
  end
47
45
  end
48
46
  end
@@ -94,8 +94,17 @@ module Spree
94
94
  "spree:idempotency:#{digest}"
95
95
  end
96
96
 
97
+ # Binds replay to the method, path, body and exact query bytes.
98
+ # Separate fixed-length digests prevent query/body delimiter collisions;
99
+ # requests without a query retain their existing cached fingerprint.
100
+ #
101
+ # @return [String] SHA-256 request fingerprint
97
102
  def request_fingerprint
98
- Digest::SHA256.hexdigest("#{request.method}:#{request.path}:#{request.raw_post}")
103
+ fingerprint = Digest::SHA256.hexdigest("#{request.method}:#{request.path}:#{request.raw_post}")
104
+ return fingerprint if request.query_string.blank?
105
+
106
+ query_fingerprint = Digest::SHA256.hexdigest(request.query_string)
107
+ Digest::SHA256.hexdigest("#{fingerprint}:#{query_fingerprint}")
99
108
  end
100
109
  end
101
110
  end
@@ -14,6 +14,9 @@ module Spree
14
14
  response.headers['X-Content-Type-Options'] = 'nosniff'
15
15
  response.headers['X-Frame-Options'] = 'DENY'
16
16
  response.headers['X-Request-Id'] = request.request_id
17
+ # A dashboard on another origin reads the request ID for its
18
+ # developer inspector; browsers hide unlisted headers from scripts.
19
+ response.headers['Access-Control-Expose-Headers'] = 'X-Request-Id'
17
20
  response.headers['Referrer-Policy'] = 'strict-origin-when-cross-origin'
18
21
  response.headers['Permissions-Policy'] = 'camera=(), microphone=(), geolocation=()'
19
22
  response.headers['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains' if request.ssl?
@@ -43,10 +43,12 @@ module Spree
43
43
  # Renders a 401 with the shared +authentication_required+ error code.
44
44
  # @param message [String] translated error message
45
45
  # @param legacy_default [String, nil] deprecated: the two-argument form
46
- # (key under +spree.+, fallback text) is removed in Spree 6.1
46
+ # (key under +spree.+, fallback text) is removed in Spree 6.3
47
47
  def render_authentication_required(message, legacy_default = nil)
48
48
  unless legacy_default.nil?
49
- Spree::Deprecation.warn('render_authentication_required(key, default) is deprecated and will be removed in Spree 6.1. Pass the translated message instead.')
49
+ Spree::Deprecation.warn(
50
+ 'render_authentication_required(key, default) is deprecated and will be removed in Spree 6.3. Pass the translated message instead.'
51
+ )
50
52
  message = I18n.t("spree.#{message}", default: legacy_default)
51
53
  end
52
54
 
@@ -15,6 +15,37 @@ module Spree
15
15
  include Spree::Api::V3::StrictMoneyParams
16
16
  include Spree::Api::V3::Admin::ValidationDetails
17
17
  include Spree::Api::V3::Admin::EmbedPermissions
18
+
19
+ private
20
+
21
+ # For endpoints about the signed-in staffer rather than the store
22
+ # (/me, /updates, /diagnostics): a secret API key has no user, so it
23
+ # gets a 404 rather than a 500 from a nil user.
24
+ def require_current_user!
25
+ return if current_user
26
+
27
+ render_error(
28
+ code: ERROR_CODES[:record_not_found],
29
+ message: I18n.t('spree.me_no_current_user'),
30
+ status: :not_found
31
+ )
32
+ end
33
+
34
+ # For endpoints that reveal the running version and stack (/updates,
35
+ # /diagnostics): a staff member signed in to the dashboard and nobody
36
+ # else. A connected app acts as the admin who approved it, so it
37
+ # would pass every check written for that admin, whatever it was
38
+ # granted, and no scope stands for "fingerprint the deployment".
39
+ def require_staff_session!
40
+ return require_current_user! unless current_user
41
+ return if current_oauth_token.blank?
42
+
43
+ render_error(
44
+ code: ERROR_CODES[:access_denied],
45
+ message: 'This endpoint is for staff signed in to the dashboard, not for connected apps.',
46
+ status: :forbidden
47
+ )
48
+ end
18
49
  end
19
50
  end
20
51
  end
@@ -92,7 +92,7 @@ module Spree
92
92
 
93
93
  # Categories exclude automatic (rule-based) rows, which still live in
94
94
  # spree_categories until the Phase 4 migration moves them to Collections.
95
- # No-op after migration; the .manual scope is removed in 6.1.
95
+ # No-op after migration; the .manual scope is removed in 6.3.
96
96
  def scope
97
97
  super.manual
98
98
  end
@@ -14,18 +14,25 @@ module Spree
14
14
  before_action :authorize_parent_access!
15
15
 
16
16
  request_params :company_membership do |body|
17
+ body.attribute :customer_id, :string,
18
+ example: 'cus_UkLWZg9DAJ',
19
+ description: 'An existing customer, who becomes a member immediately. ' \
20
+ 'Send this or `customer_email`.'
17
21
  body.attribute :customer_email, :string,
18
- required: true, on: :create,
19
- example: 'buyer@example.com',
20
- description: 'An existing customer becomes a member immediately; an unknown email becomes an invitation, and the response is an invitation instead of a membership.'
22
+ example: 'buyer@example.com',
23
+ description: 'An existing customer becomes a member immediately; an unknown ' \
24
+ 'email becomes an invitation, and the response is an invitation ' \
25
+ 'instead of a membership. Send this or `customer_id`.'
21
26
  body.attribute :metadata, :hash
22
27
  end
23
28
 
24
29
  # POST /api/v3/admin/companies/:company_id/memberships
25
30
  def create
31
+ customer = member_customer
26
32
  result = Spree.company_add_member_service.call(
27
33
  company: @parent,
28
- email: params.require(:customer_email),
34
+ customer: customer,
35
+ email: customer ? nil : params.require(:customer_email),
29
36
  metadata: permitted_params[:metadata]
30
37
  )
31
38
 
@@ -43,6 +50,16 @@ module Spree
43
50
 
44
51
  protected
45
52
 
53
+ # Through the ability, like every customer lookup here: a customer
54
+ # this role cannot see 404s rather than joining the company.
55
+ def member_customer
56
+ return if params[:customer_id].blank?
57
+
58
+ Spree.customer_class.
59
+ accessible_by(current_ability, :show).
60
+ find_by_prefix_id!(params[:customer_id])
61
+ end
62
+
46
63
  def model_class
47
64
  Spree::CompanyMembership
48
65
  end
@@ -0,0 +1,46 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ module Admin
5
+ # The anonymised diagnostics report (Spree::Diagnostics) for bug
6
+ # reports. It reveals the running version and stack, so it answers
7
+ # signed-in staff who can manage the store and nobody else, like
8
+ # GET /updates: a secret API key gets a 404, a connected app a 403.
9
+ class DiagnosticsController < Admin::BaseController
10
+ skip_scope_check!
11
+
12
+ before_action :require_staff_session!
13
+
14
+ # Only a published @spree/* name and a version: anything else in
15
+ # the list is dropped rather than echoed into a public report.
16
+ PACKAGE = %r{\A(@spree/[a-z0-9-]{1,50})@(\d+\.\d+\.\d+[0-9A-Za-z.-]{0,20})\z}
17
+ PACKAGE_LIMIT = 20
18
+
19
+ # GET /api/v3/admin/diagnostics
20
+ def show
21
+ authorize! :manage, current_store
22
+
23
+ report = Spree::Diagnostics.report(store: current_store, extra_sections: dashboard_section + client_section)
24
+ render json: Spree.api.admin_diagnostics_serializer.new(report).to_h
25
+ end
26
+
27
+ private
28
+
29
+ # The caller's @spree/* packages, which the server can't see: the
30
+ # dashboard may be built and deployed apart from it.
31
+ def dashboard_section
32
+ rows = params[:packages].to_s.split(',').first(PACKAGE_LIMIT).filter_map { |package| PACKAGE.match(package)&.captures }
33
+ rows.any? ? [{ title: 'Dashboard', rows: rows.to_h }] : []
34
+ end
35
+
36
+ # The browser the report was opened in, which only this request knows.
37
+ def client_section
38
+ return [] if request.user_agent.blank?
39
+
40
+ [{ title: 'Client', rows: { 'User agent' => request.user_agent } }]
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -70,19 +70,6 @@ module Spree
70
70
  )
71
71
  end
72
72
 
73
- # A request authenticated by a secret API key has no Spree user to
74
- # describe/update, so it gets a 404 pointing at the key endpoint
75
- # rather than a 500 from a nil user — mirroring ApiKeysController#current.
76
- def require_current_user!
77
- return if current_user
78
-
79
- render_error(
80
- code: ERROR_CODES[:record_not_found],
81
- message: I18n.t('spree.me_no_current_user'),
82
- status: :not_found
83
- )
84
- end
85
-
86
73
  # /me describes the signed-in user rather than a store, and the
87
74
  # dashboard reads it before any store is selected. A user who holds
88
75
  # no role on any store (not yet given one, or removed from all of
@@ -55,6 +55,16 @@ module Spree
55
55
  Spree::Media
56
56
  end
57
57
 
58
+ # Sorting by file name or size orders by a subquery on the blob,
59
+ # which PostgreSQL rejects under SELECT DISTINCT. Nothing here can
60
+ # repeat a row: the filename filter joins each media row to its one
61
+ # attachment and that attachment's one blob, and every other filter,
62
+ # like the product scope's legacy default-variant branch, reads this
63
+ # table's own columns. The library inherits this.
64
+ def collection_distinct?
65
+ false
66
+ end
67
+
58
68
  def serializer_class
59
69
  Spree.api.admin_media_serializer
60
70
  end
@@ -56,12 +56,16 @@ module Spree
56
56
  # DELETE /api/v3/admin/orders/:order_id/items/:id
57
57
  def destroy
58
58
  with_order_lock do
59
- Spree.order_remove_line_item_service.call(
59
+ result = Spree.order_remove_line_item_service.call(
60
60
  order: @parent,
61
61
  line_item: @resource
62
62
  )
63
63
 
64
- head :no_content
64
+ if result.success?
65
+ head :no_content
66
+ else
67
+ render_order_item_error(result, default_code: ERROR_CODES[:processing_error])
68
+ end
65
69
  end
66
70
  end
67
71
 
@@ -10,15 +10,23 @@ module Spree
10
10
  # endpoint, and rooted the same way — at the seller's invitations, so
11
11
  # an id from another seller reads as missing rather than as denied.
12
12
  #
13
- # Creating one is the `invite` action on the seller itself; what is
14
- # here is the bookkeeping the operator needs when an offer went to
15
- # the wrong address or never arrived.
13
+ # Creating one here adds someone to the team and leaves the seller's
14
+ # status alone, so it works for a seller already trading. The
15
+ # `invite` action on the seller is the lifecycle step that opens a
16
+ # pending seller for its first owner.
16
17
  class InvitationsController < Admin::BaseController
17
18
  scoped_resource :sellers
18
19
 
19
20
  before_action :set_seller
21
+ # Every write hands out or withdraws a way onto the team, so it
22
+ # needs the same right as changing the seller.
23
+ before_action :authorize_seller_update, only: [:create, :destroy, :resend]
20
24
  before_action :set_invitation, only: [:destroy, :resend]
21
25
 
26
+ request_params 'SellerInvitationCreateParams', action: :create do |body|
27
+ body.attribute :email, :string, required: true, example: 'teammate@example.com'
28
+ end
29
+
22
30
  # Pending only: an accepted invitation is a team member, which the
23
31
  # team endpoint lists.
24
32
  def index
@@ -27,6 +35,30 @@ module Spree
27
35
  render json: { data: invitations.map { |invitation| serialize(invitation) } }
28
36
  end
29
37
 
38
+ # A seller the marketplace turned away has no team to join, the
39
+ # same line the seller's own `invite` action draws.
40
+ def create
41
+ if @seller.rejected?
42
+ return render_error(
43
+ code: ErrorHandler::ERROR_CODES[:processing_error],
44
+ message: I18n.t('spree.invitation_seller_rejected'),
45
+ status: :unprocessable_content
46
+ )
47
+ end
48
+
49
+ invitation = @seller.invitations.new(
50
+ email: params[:email],
51
+ role: @seller.default_user_role,
52
+ inviter: try_spree_current_user
53
+ )
54
+
55
+ if invitation.save
56
+ render json: serialize(invitation), status: :created
57
+ else
58
+ render_validation_error(invitation.errors)
59
+ end
60
+ end
61
+
30
62
  def destroy
31
63
  @invitation.destroy
32
64
  head :no_content
@@ -60,6 +92,10 @@ module Spree
60
92
  authorize! :show, @seller
61
93
  end
62
94
 
95
+ def authorize_seller_update
96
+ authorize! :update, @seller
97
+ end
98
+
63
99
  def set_invitation
64
100
  @invitation = @seller.invitations.pending.find_by_prefix_id!(params[:id])
65
101
  end
@@ -11,9 +11,7 @@ module Spree
11
11
  # person was invited — which a seller by definition cannot do from
12
12
  # inside their own panel.
13
13
  #
14
- # Inviting is not here: it is the `invite` action on the seller
15
- # itself, which is a lifecycle workflow rather than bookkeeping on a
16
- # team.
14
+ # Inviting someone is the invitations endpoint next to this one.
17
15
  class TeamController < Admin::BaseController
18
16
  scoped_resource :sellers
19
17
 
@@ -18,6 +18,11 @@ module Spree
18
18
 
19
19
  before_action :set_resource, only: [:show, :update, :destroy, :invite, :approve, :suspend, :reject,
20
20
  :onboarding, :reopen_onboarding]
21
+ before_action :authorize_returns_address!, only: [:create, :update]
22
+
23
+ RETURNS_ADDRESS_DESCRIPTION = "Where customers send returns, written inline. It is the address of the seller's " \
24
+ 'returns stock location, so it updates that location, or creates one for a seller ' \
25
+ 'who has none. Names and `label` are ignored: a location has none.'.freeze
21
26
 
22
27
  # Enumerated rather than borrowing the legacy global list, which
23
28
  # permits :id, :user_id and :deleted_at — the first of which would
@@ -64,6 +69,11 @@ module Spree
64
69
  description: "The seller's own billing address, written inline. There is no `billing_address_id`: an address belongs to whoever it was created for, so it is never referenced by id." do |billing_address|
65
70
  billing_address.include_attributes Spree::Api::V3::AddressRequestSchema
66
71
  end
72
+ body.attribute :returns_address, :object,
73
+ as: 'SellerAddressParams',
74
+ description: RETURNS_ADDRESS_DESCRIPTION do |returns_address|
75
+ returns_address.include_attributes Spree::Api::V3::AddressRequestSchema
76
+ end
67
77
  body.attribute :custom_fields, :array, of: Spree::Api::V3::CustomFieldValueRequestSchema,
68
78
  description: 'Custom field values, each validated against its definition.'
69
79
  end
@@ -78,7 +88,10 @@ module Spree
78
88
 
79
89
  request_params 'SellerApproveParams', action: :approve do |body|
80
90
  body.attribute :override_requirements, :boolean,
81
- description: 'Admits a seller whose onboarding checklist is unfinished: the operator\'s deliberate exception, which the `seller.approved` event records along with what was outstanding.'
91
+ description: "Admits a seller whose onboarding checklist is unfinished: the operator's " \
92
+ 'deliberate exception, which the `seller.approved` event records along with ' \
93
+ 'what was outstanding. Also admits a `pending` or `invited` seller who never ' \
94
+ 'started onboarding, which is refused without it.'
82
95
  end
83
96
 
84
97
  request_params 'SellerReopenOnboardingParams', action: :reopen_onboarding do |body|
@@ -235,6 +248,16 @@ module Spree
235
248
 
236
249
  @resource.roles.find_by_prefix_id!(params[:role_id])
237
250
  end
251
+
252
+ # The returns address is a stock location's, and writing a location
253
+ # needs `write_settings` (see StockLocationsController), which the
254
+ # `sellers` scope does not grant.
255
+ def authorize_returns_address!
256
+ return unless params.key?(:returns_address)
257
+ return if holds_permission?('write_settings')
258
+
259
+ render_missing_permission('write_settings')
260
+ end
238
261
  end
239
262
  end
240
263
  end
@@ -44,6 +44,10 @@ module Spree
44
44
  example: -3,
45
45
  description: 'A relative change, for feeds that report movements rather than levels. Each row needs `count_on_hand` or `adjustment`.'
46
46
  stock_level.attribute :backorderable, :boolean, nullable: true
47
+ stock_level.attribute :reason, :string,
48
+ nullable: true,
49
+ example: 'received',
50
+ description: 'Labels the movement in the stock history. Defaults to "Inventory feed".'
47
51
  end
48
52
  end
49
53
 
@@ -73,6 +77,15 @@ module Spree
73
77
  end
74
78
 
75
79
  result = Spree.stock_level_bulk_upsert_workflow.call(store: current_store, rows: rows)
80
+ if result.failure?
81
+ return render_error(
82
+ code: 'invalid_stock_levels',
83
+ message: result.error.to_s,
84
+ status: :unprocessable_content,
85
+ details: { rows: result.error.value[:rows] }
86
+ )
87
+ end
88
+
76
89
  render json: result.value
77
90
  end
78
91
 
@@ -173,7 +186,8 @@ module Spree
173
186
  stock_location_id: location_ids[row[:stock_location_id]],
174
187
  count_on_hand: row[:count_on_hand],
175
188
  adjustment: row[:adjustment],
176
- backorderable: row[:backorderable]
189
+ backorderable: row[:backorderable],
190
+ reason: row[:reason].presence
177
191
  }.compact
178
192
  end
179
193
  end
@@ -13,6 +13,14 @@ module Spree
13
13
  body.attribute :meta_description, :string,
14
14
  nullable: true,
15
15
  description: "The storefront's default meta description, in the store's default language."
16
+ body.attribute :meta_keywords, :string, nullable: true,
17
+ description: "The storefront's default meta keywords, comma-separated, in the default language."
18
+ body.attribute :facebook, :string, nullable: true, example: 'https://facebook.com/mystore',
19
+ description: 'The Facebook page: a handle or a full URL.'
20
+ body.attribute :twitter, :string, nullable: true, example: 'mystore',
21
+ description: 'The X (Twitter) account: a handle or a full URL.'
22
+ body.attribute :instagram, :string, nullable: true, example: 'mystore',
23
+ description: 'The Instagram account: a handle or a full URL.'
16
24
  body.attribute :admin_locale, :locale, nullable: true, example: 'en',
17
25
  description: 'The language the dashboard opens in for every staff member; null lets each use their own.'
18
26
  body.attribute :timezone, :time_zone, example: 'Europe/Berlin'
@@ -143,7 +151,7 @@ module Spree
143
151
  # all, so every signed-in staff member can read it regardless of
144
152
  # their permissions. Secret keys still need `read_settings`: a
145
153
  # scope-limited integration has no business reading operational
146
- # settings (support/notification emails, routing) it wasn't granted.
154
+ # settings (notification emails, routing) it wasn't granted.
147
155
  # Writing always requires `write_settings`.
148
156
  skip_scope_check! only: :show, jwt_only: true
149
157
 
@@ -7,12 +7,13 @@ module Spree
7
7
  #
8
8
  # The only place the Admin API reveals the running Spree version, so it
9
9
  # answers signed-in staff who can manage the store and nobody else. A
10
- # secret API key gets a 404, like GET /me: an integration key would
11
- # otherwise fingerprint the deployment for anyone matching CVEs.
10
+ # secret API key gets a 404, like GET /me, and a connected app a 403: an
11
+ # integration credential would otherwise fingerprint the deployment for
12
+ # anyone matching CVEs.
12
13
  class UpdatesController < Admin::BaseController
13
14
  skip_scope_check!
14
15
 
15
- before_action :require_current_user!
16
+ before_action :require_staff_session!
16
17
 
17
18
  # GET /api/v3/admin/updates
18
19
  def show
@@ -20,18 +21,6 @@ module Spree
20
21
 
21
22
  render json: Spree.api.admin_update_status_serializer.new(Spree::UpdateCheck.status).to_h
22
23
  end
23
-
24
- private
25
-
26
- def require_current_user!
27
- return if current_user
28
-
29
- render_error(
30
- code: ERROR_CODES[:record_not_found],
31
- message: I18n.t('spree.me_no_current_user'),
32
- status: :not_found
33
- )
34
- end
35
24
  end
36
25
  end
37
26
  end
@@ -0,0 +1,41 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ module Seller
5
+ # The marketplace's option types (Size, Colour) and their values, for
6
+ # the variants builder on a seller's product form.
7
+ #
8
+ # Read only: a seller builds their variants from the options the
9
+ # operator defines, and never adds a type or a value to that shared
10
+ # vocabulary (docs/plans/6.0-multi-vendor-marketplace.md).
11
+ #
12
+ # Gated on `read_products`, as delivery profiles are, rather than a key
13
+ # of its own: option types and values are resources of the `products`
14
+ # scope on both branches (the operator's endpoint uses it too), and
15
+ # this list exists only for the product form, so a key that may read
16
+ # products may read the vocabulary that form fills in.
17
+ #
18
+ # Option types belong to the store rather than to a seller, so this is
19
+ # not rooted in `current_seller` — the store comes from the seller,
20
+ # which is what keeps it scoped.
21
+ class OptionTypesController < Seller::ResourceController
22
+ scoped_resource :products
23
+
24
+ protected
25
+
26
+ def model_class
27
+ Spree::OptionType
28
+ end
29
+
30
+ def serializer_class
31
+ Spree.api.seller_option_type_serializer
32
+ end
33
+
34
+ def scope
35
+ model_class.for_store(current_store).preload_associations_lazily.i18n
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,46 @@
1
+ module Spree
2
+ module Api
3
+ module V3
4
+ module Seller
5
+ module Products
6
+ # Removing a file from one of this seller's own products.
7
+ #
8
+ # Delete only: the gallery's other writes ride the product update,
9
+ # which never removes a file it was not sent — so a form holding
10
+ # stale state cannot wipe a seller's pictures. Like the rest of a
11
+ # gallery edit, removal does not send an approved listing back to
12
+ # review.
13
+ class MediaController < Seller::ResourceController
14
+ scoped_resource :products
15
+
16
+ protected
17
+
18
+ def model_class
19
+ Spree::Media
20
+ end
21
+
22
+ # Rooted in the seller's own catalog, so another seller's product
23
+ # is a 404. Changing a product's gallery is a change to the
24
+ # product, so it needs `:update` on it.
25
+ def set_parent
26
+ @parent = current_seller.products.find_by_prefix_id!(params[:product_id])
27
+ authorize_parent!(@parent)
28
+ end
29
+
30
+ # The product's gallery, plus any file still pinned to its default
31
+ # variant from before galleries moved to the product — the same
32
+ # rows the product shows.
33
+ def scope
34
+ Spree::Media.where(viewable: @parent).or(
35
+ Spree::Media.where(viewable_type: 'Spree::Variant', viewable_id: @parent.default_variant&.id)
36
+ )
37
+ end
38
+
39
+ # The product's own authorization above is the check.
40
+ def authorize_resource!(resource = @resource, action = action_name.to_sym); end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end