Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fixed the remaining review comments on seller file rules
Damian Legawiec3018d56ec37f
diff --git a/docs/api-reference/admin.yaml b/docs/api-reference/admin.yamlindex 19a295d948..c5558a15a0 100644--- a/docs/api-reference/admin.yaml+++ b/docs/api-reference/admin.yaml@@ -79319,7 +79319,7 @@ components:description: 'A `signed_id` from `files.upload()` with `visibility: ''private''`.On update it replaces the file for everyone who already bought it. A seller''sfile must be of a content type the marketplace accepts, checked against- the file''s own signature.'+ the file''s own signature where it has one.'variant_id:type: stringdescription: On create, defaults to the product's default variant when omitted.@@ -79348,7 +79348,7 @@ components:description: 'A `signed_id` from `files.upload()` with `visibility: ''private''`.On update it replaces the file for everyone who already bought it. A seller''sfile must be of a content type the marketplace accepts, checked against- the file''s own signature.'+ the file''s own signature where it has one.'variant_id:type: stringdescription: On create, defaults to the product's default variant when omitted.@@ -83690,8 +83690,9 @@ components:items:type: stringdescription: The content types a seller's file may have, checked against- the file's own signature where it has one. The operator's own uploads- are not restricted.+ the file's own signature where it has one. An entry names one type or,+ with `*` as the subtype, a whole family. The operator's own uploads are+ not restricted.example:- application/pdf- application/zipdiff --git a/docs/api-reference/seller.yaml b/docs/api-reference/seller.yamlindex fc09dc13c2..694ebbab9c 100644--- a/docs/api-reference/seller.yaml+++ b/docs/api-reference/seller.yaml@@ -31922,7 +31922,7 @@ components:description: 'A `signed_id` from `files.upload()` with `visibility: ''private''`.On update it replaces the file for everyone who already bought it. A seller''sfile must be of a content type the marketplace accepts, checked against- the file''s own signature.'+ the file''s own signature where it has one.'variant_id:type: stringdescription: On create, defaults to the product's default variant when omitted.@@ -31945,7 +31945,7 @@ components:description: 'A `signed_id` from `files.upload()` with `visibility: ''private''`.On update it replaces the file for everyone who already bought it. A seller''sfile must be of a content type the marketplace accepts, checked against- the file''s own signature.'+ the file''s own signature where it has one.'variant_id:type: stringdescription: On create, defaults to the product's default variant when omitted.diff --git a/docs/developer/how-to/sell-digital-products.mdx b/docs/developer/how-to/sell-digital-products.mdxindex e6e9437371..65ee2bc6c9 100644--- a/docs/developer/how-to/sell-digital-products.mdx+++ b/docs/developer/how-to/sell-digital-products.mdx@@ -65,7 +65,7 @@ Sellers upload files only. A [custom digital asset provider](/developer/how-to/cSeller uploads are **off until you turn them on**, under Settings → Marketplace → Seller files, because a file a buyer downloads under your name is one you vouch for. Three settings shape them:- **Let sellers upload digital files** (`seller_digital_assets_enabled`). Off, the seller panel shows the files you attached and nothing else.-- **Accepted file types for sellers** (`seller_digital_asset_content_types`). Checked against the file's own signature where it has one, not its name, so a renamed executable does not pass as a PDF; a format with no signature, such as plain text, is taken at the type the upload declared. The default covers documents, ebooks, archives, audio, video, images and plain text; add `application/octet-stream` only if your sellers trade in a format nothing recognises, since it admits anything unknown. Your own uploads are never restricted.+- **Accepted file types for sellers** (`seller_digital_asset_content_types`). Checked against the file's own signature where it has one, not its name, so a renamed executable does not pass as a PDF; a format with no signature, such as plain text, is taken at the type the upload declared. An entry names one type, or a whole family with `*` as the subtype (`audio/*`). The default covers documents, ebooks, archives, audio, video, images and plain text; add `application/octet-stream` only if your sellers trade in a format nothing recognises, since it admits anything unknown. Your own uploads are never restricted.- **Review file changes on products already on sale** (`review_seller_digital_asset_changes`, on by default). A seller adding or replacing a file on an approved product sends it back to [review](/developer/core-concepts/products#submitting-as-a-seller) and off sale until you approve it again; the new submission says why. Changing download limits does not. The setting does nothing when seller products publish automatically.<Warning>diff --git a/docs/plans/decisions.md b/docs/plans/decisions.mdindex 3c87f21213..254cb2977d 100644--- a/docs/plans/decisions.md+++ b/docs/plans/decisions.md@@ -2,7 +2,7 @@**Context:** With sellers able to attach downloadable files to their products (the entry below), any approved seller can put a file on the marketplace's domain that buyers download trusting the marketplace's brand. Nothing in Spree scans a file's contents, and before this there was no way to keep seller uploads off, to narrow what they may be, or to re-check an approved listing whose file changed. Digital asset writes were also plain model saves in two places, so a host had no point at which to refuse an upload.-**Decision:** Three store settings, shown on the dashboard's Marketplace settings page. `seller_digital_assets_enabled` is off by default, like the two auto-approve settings: what a buyer downloads under the marketplace's name is something the marketplace vouches for, and that should be a choice. `seller_digital_asset_content_types` is an allowlist checked against the signature Marcel reads from the bytes where the format has one, never the file name (plain text has none and keeps its declared type); its default covers the formats digital goods usually come in and leaves out executables, scripts, SVG and unrecognised binaries. The operator's own uploads are not restricted. `review_seller_digital_asset_changes` is on by default: a seller adding or replacing a file on a listing already on sale sends it back to review, off sale until approved again; changing limits or deleting does not, and the rule is moot when seller products auto-approve. Turning uploads off also stops a seller removing the marketplace's own files from their product. `Products::Propose` admits an active product when told a `reason`, recorded on the submission row with who made the change. All digital asset writes now run through `Spree::DigitalAssets::Create` and `Update` — both endpoints and the nested list on a product write — with `validate` and `after_*` hooks; the seller rules are steps in them, applied when the caller names a `seller:`. A host that scans uploads registers on `digital_assets.create.validate`, where the bytes are already in storage, or queues a scan from `after_create`. Core ships no scanner. The seller `/me` response carries the two settings the panel needs under `store`.+**Decision:** Three store settings, shown on the dashboard's Marketplace settings page. `seller_digital_assets_enabled` is off by default, like the two auto-approve settings: what a buyer downloads under the marketplace's name is something the marketplace vouches for, and that should be a choice. Off, a seller can neither add, replace nor remove files on their products. `seller_digital_asset_content_types` is an allowlist checked against the file's own signature where the format has one, never the file name; a signature-less format such as plain text keeps its declared type. Its default covers the formats digital goods usually come in and leaves out executables, scripts, SVG and unrecognised binaries. The operator's own uploads are not restricted. `review_seller_digital_asset_changes` is on by default: a seller adding or replacing a file on a listing already on sale sends it back to review, off sale until approved again; changing limits or deleting does not, and the rule is moot when seller products auto-approve. The submission row records the reason and who made the change, and the seller panel says so before the seller acts. Every digital asset write, from either endpoint or nested in a product write, runs through one workflow with hooks, so a host that scans uploads has a single place to refuse a file before it is attached. Core ships no scanner. The seller `/me` response carries the settings the panel needs under `store`.**Consequences:** A marketplace that reviews listings will see approved products drop off sale for a file swap until it approves them again; the alternative, holding the new file in quarantine while the old one keeps serving, needs file versioning and is deferred to the uploads scanning work. ZIP is on the default list, so the allowlist is a policy, not protection. Opening uploads to sellers is now an explicit step in setting up a marketplace, documented beside the auto-approve settings. The 6.1 upload-scanning design (a scanner registry with a no-op default, a verdict on the blob, delivery refused while pending) builds on these hooks rather than on the controllers.diff --git a/packages/admin-sdk/src/types/params/DigitalAssetCreateParams.ts b/packages/admin-sdk/src/types/params/DigitalAssetCreateParams.tsindex 266aec2ffe..6d3092f297 100644--- a/packages/admin-sdk/src/types/params/DigitalAssetCreateParams.ts+++ b/packages/admin-sdk/src/types/params/DigitalAssetCreateParams.ts@@ -4,7 +4,7 @@ export type DigitalAssetCreateParams = {/*** A `signed_id` from `files.upload()` with `visibility: 'private'`. On update it replaces the* file for everyone who already bought it. A seller's file must be of a content type the- * marketplace accepts, checked against the file's own signature.+ * marketplace accepts, checked against the file's own signature where it has one.*/signed_id?: string/**diff --git a/packages/admin-sdk/src/types/params/DigitalAssetUpdateParams.ts b/packages/admin-sdk/src/types/params/DigitalAssetUpdateParams.tsindex 32c95e4a42..871c60f95c 100644--- a/packages/admin-sdk/src/types/params/DigitalAssetUpdateParams.ts+++ b/packages/admin-sdk/src/types/params/DigitalAssetUpdateParams.ts@@ -4,7 +4,7 @@ export type DigitalAssetUpdateParams = {/*** A `signed_id` from `files.upload()` with `visibility: 'private'`. On update it replaces the* file for everyone who already bought it. A seller's file must be of a content type the- * marketplace accepts, checked against the file's own signature.+ * marketplace accepts, checked against the file's own signature where it has one.*/signed_id?: string/**diff --git a/packages/admin-sdk/src/types/params/StoreUpdateParams.ts b/packages/admin-sdk/src/types/params/StoreUpdateParams.tsindex e4a851f9e9..185a538b81 100644--- a/packages/admin-sdk/src/types/params/StoreUpdateParams.ts+++ b/packages/admin-sdk/src/types/params/StoreUpdateParams.ts@@ -78,7 +78,8 @@ export type StoreUpdateParams = {seller_digital_assets_enabled?: boolean/*** The content types a seller's file may have, checked against the file's own signature where it- * has one. The operator's own uploads are not restricted.+ * has one. An entry names one type or, with `*` as the subtype, a whole family. The operator's+ * own uploads are not restricted.*/seller_digital_asset_content_types?: string[]/**diff --git a/packages/seller-sdk/src/types/params/DigitalAssetCreateParams.ts b/packages/seller-sdk/src/types/params/DigitalAssetCreateParams.tsindex 5a1ef25d21..43cd4401c6 100644--- a/packages/seller-sdk/src/types/params/DigitalAssetCreateParams.ts+++ b/packages/seller-sdk/src/types/params/DigitalAssetCreateParams.ts@@ -4,7 +4,7 @@ export type DigitalAssetCreateParams = {/*** A `signed_id` from `files.upload()` with `visibility: 'private'`. On update it replaces the* file for everyone who already bought it. A seller's file must be of a content type the- * marketplace accepts, checked against the file's own signature.+ * marketplace accepts, checked against the file's own signature where it has one.*/signed_id: string/**diff --git a/packages/seller-sdk/src/types/params/DigitalAssetUpdateParams.ts b/packages/seller-sdk/src/types/params/DigitalAssetUpdateParams.tsindex 992c8676de..ba96fbf79a 100644--- a/packages/seller-sdk/src/types/params/DigitalAssetUpdateParams.ts+++ b/packages/seller-sdk/src/types/params/DigitalAssetUpdateParams.ts@@ -4,7 +4,7 @@ export type DigitalAssetUpdateParams = {/*** A `signed_id` from `files.upload()` with `visibility: 'private'`. On update it replaces the* file for everyone who already bought it. A seller's file must be of a content type the- * marketplace accepts, checked against the file's own signature.+ * marketplace accepts, checked against the file's own signature where it has one.*/signed_id?: string/**diff --git a/spree/api/app/controllers/spree/api/v3/admin/store_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/store_controller.rbindex 27ea531e25..e8a8fd9d7e 100644--- a/spree/api/app/controllers/spree/api/v3/admin/store_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/admin/store_controller.rb@@ -69,7 +69,7 @@ module Spreedescription: 'Lets sellers attach downloadable files to their own products.'body.attribute :seller_digital_asset_content_types, :array, of: :string,example: %w[application/pdf application/zip],- description: "The content types a seller's file may have, checked against the file's own signature where it has one. The operator's own uploads are not restricted."+ description: "The content types a seller's file may have, checked against the file's own signature where it has one. An entry names one type or, with `*` as the subtype, a whole family. The operator's own uploads are not restricted."body.attribute :review_seller_digital_asset_changes, :boolean,description: 'Sends a seller product already on sale back to review when the seller adds or replaces a file on it.'body.attribute :send_seller_transactional_emails, :boolean,diff --git a/spree/api/app/controllers/spree/api/v3/seller/me_controller.rb b/spree/api/app/controllers/spree/api/v3/seller/me_controller.rbindex f366738ed9..9d8e8aa060 100644--- a/spree/api/app/controllers/spree/api/v3/seller/me_controller.rb+++ b/spree/api/app/controllers/spree/api/v3/seller/me_controller.rb@@ -61,7 +61,7 @@ module Spree# The marketplace's own settings that shape what the panel lets a# seller do, read before any seller is chosen since there is one# store per installation.- store: Spree.api.seller_store_serializer.new(current_store, params: serializer_params).to_h,+ store: Spree.api.seller_store_serializer.new(serializer_params[:store], params: serializer_params).to_h,# Both shapes, exactly as the admin `/me`: the panel's `<Can>`# reads CanCanCan rules, the key gate reads keys. Sending only# keys left `<Can>` answering false for everything on the sellerdiff --git a/spree/api/app/request_schemas/spree/api/v3/digital_asset_request_schema.rb b/spree/api/app/request_schemas/spree/api/v3/digital_asset_request_schema.rbindex 9584381412..7cd0127be9 100644--- a/spree/api/app/request_schemas/spree/api/v3/digital_asset_request_schema.rb+++ b/spree/api/app/request_schemas/spree/api/v3/digital_asset_request_schema.rb@@ -7,7 +7,7 @@ module Spree# Names a blob rather than a column, so it is attached separately.attribute :signed_id, :string,permit: false,- description: "A `signed_id` from `files.upload()` with `visibility: 'private'`. On update it replaces the file for everyone who already bought it. A seller's file must be of a content type the marketplace accepts, checked against the file's own signature."+ description: "A `signed_id` from `files.upload()` with `visibility: 'private'`. On update it replaces the file for everyone who already bought it. A seller's file must be of a content type the marketplace accepts, checked against the file's own signature where it has one."# Resolved through the parent rather than assigned, so an asset can't# be pointed at a variant of another product or store.attribute :variant_id, :id,diff --git a/spree/api/spec/controllers/spree/api/v3/seller/products/digital_assets_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/seller/products/digital_assets_controller_spec.rbindex 6dbb3a4a0d..25da9c1f79 100644--- a/spree/api/spec/controllers/spree/api/v3/seller/products/digital_assets_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/seller/products/digital_assets_controller_spec.rb@@ -216,6 +216,14 @@ RSpec.describe Spree::Api::V3::Seller::Products::DigitalAssetsController, type:expect(Spree::DigitalAsset.count).to eq(0)end+ it 'accepts a whole family named with a wildcard' do+ stub_store_preferences(seller_digital_asset_content_types: %w[image/*])++ post :create, params: { product_id: product.prefixed_id, signed_id: blob.signed_id }, as: :json++ expect(response).to have_http_status(:created)+ end+it 'leaves the limits editable when the type is no longer accepted' dodigital_asset = create(:digital_asset, variant: variant)stub_store_preferences(seller_digital_asset_content_types: %w[application/pdf])diff --git a/spree/core/app/models/spree/store.rb b/spree/core/app/models/spree/store.rbindex ee87222b4e..97463b549c 100644--- a/spree/core/app/models/spree/store.rb+++ b/spree/core/app/models/spree/store.rb@@ -83,7 +83,8 @@ module Spree# is something the marketplace vouches for, and that should be a choice.preference :seller_digital_assets_enabled, :boolean, default: false# What a seller's file may be, checked against the file's own signature- # rather than its name. The operator's own uploads are not restricted.+ # rather than its name. An entry names one type or, with `*` as the+ # subtype, a whole family. The operator's own uploads are not restricted.preference :seller_digital_asset_content_types, :array, of: :string,default: Spree::DigitalAsset::DEFAULT_SELLER_CONTENT_TYPES# A typo here would refuse every seller upload with a message about thediff --git a/spree/core/app/workflows/spree/digital_assets/writing.rb b/spree/core/app/workflows/spree/digital_assets/writing.rbindex eb01ce7cb5..ca5a286a89 100644--- a/spree/core/app/workflows/spree/digital_assets/writing.rb+++ b/spree/core/app/workflows/spree/digital_assets/writing.rb@@ -62,11 +62,17 @@ module Spree# renamed executable cannot pass as a PDF; a format with no signature# (plain text) keeps the type the client declared.blob.identify_without_saving- return if store.preferred_seller_digital_asset_content_types.include?(blob.content_type)+ return if content_type_accepted?(blob.content_type)refuse(:digital_assets_content_type_not_accepted, content_type: blob.content_type)end+ # An entry names one type (`audio/mpeg`) or a whole family (`audio/*`).+ def content_type_accepted?(content_type)+ family = "#{content_type.to_s.split('/').first}/*"+ store.preferred_seller_digital_asset_content_types.any? { |accepted| accepted.casecmp?(content_type.to_s) || accepted == family }+ end+def attach_uploaddigital_asset.attachment.attach(blob) if blobend