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 review findings on seller digital assets
Damian Legawiec3d7eb4dacea0
diff --git a/docs/api-reference/store.yaml b/docs/api-reference/store.yamlindex 603740c3da..5fb2ff67b9 100644--- a/docs/api-reference/store.yaml+++ b/docs/api-reference/store.yaml@@ -1097,8 +1097,8 @@ paths:example:data:- id: prod_UkLWZg9DAJ- name: Product 3556979- slug: product-3556979+ name: Product 3476979+ slug: product-3476979meta_title:meta_description:meta_keywords:@@ -1390,8 +1390,8 @@ paths:example:data:- id: prod_UkLWZg9DAJ- name: Product 4039085- slug: product-4039085+ name: Product 3959085+ slug: product-3959085meta_title:meta_description:meta_keywords:@@ -1422,8 +1422,8 @@ paths:original_price:seller_id:- id: prod_gbHJdmfrXB- name: Product 4048209- slug: product-4048209+ name: Product 3968209+ slug: product-3968209meta_title:meta_description:meta_keywords:@@ -1552,8 +1552,8 @@ paths:application/json:example:id: prod_UkLWZg9DAJ- name: Product 4316885- slug: product-4316885+ name: Product 4236885+ slug: product-4236885meta_title:meta_description:meta_keywords:@@ -2190,7 +2190,7 @@ paths:content:application/json:example:- signed_id: eyJfcmFpbHMiOnsiZGF0YSI6MSwiZXhwIjoiMjAyNi0wMS0xNlQxMjowMDowMC4wMDBaIiwicHVyIjoiYmxvYl9pZCJ9fQ==--aacde269a0019661ac951ab66e97e4338f76c0e3+ signed_id: eyJfcmFpbHMiOnsiZGF0YSI6MSwiZXhwIjoiMjAyNi0wMS0xNlQxMjowMDowMC4wMDBaIiwicHVyIjoiYmxvYl9pZCJ9fQ==--a9cd29e72a70654182038480207bd929343f6a07filename: purchase-order.pdfcontent_type: application/pdfbyte_size: 48210@@ -2198,7 +2198,7 @@ paths:expires_at: '2026-01-16T12:00:00.000Z'upload:method: PUT- url: http://www.example.com/rails/active_storage/disk/eyJfcmFpbHMiOnsiZGF0YSI6eyJrZXkiOiIwc3NuNW5kM3RneWtwcWJndXdybGprZjNwbjc4IiwiY29udGVudF90eXBlIjoiYXBwbGljYXRpb24vcGRmIiwiY29udGVudF9sZW5ndGgiOjQ4MjEwLCJjaGVja3N1bSI6IjVXMjhrY2ZxcDlLMGY1djRZN2VyUkE9PSIsInNlcnZpY2VfbmFtZSI6InRlc3QifSwiZXhwIjoiMjAyNi0wMS0xNVQxMjowNTowMC4wMDBaIiwicHVyIjoiYmxvYl90b2tlbiJ9fQ==--ced4d1a9c43f0387228494e9c11aba005d86b325+ url: http://www.example.com/rails/active_storage/disk/eyJfcmFpbHMiOnsiZGF0YSI6eyJrZXkiOiIwc3NuNW5kM3RneWtwcWJndXdybGprZjNwbjc4IiwiY29udGVudF90eXBlIjoiYXBwbGljYXRpb24vcGRmIiwiY29udGVudF9sZW5ndGgiOjQ4MjEwLCJjaGVja3N1bSI6IjVXMjhrY2ZxcDlLMGY1djRZN2VyUkE9PSIsInNlcnZpY2VfbmFtZSI6InRlc3QifSwiZXhwIjoiMjAyNi0wMS0xNVQxMjowNTowMC4wMDBaIiwicHVyIjoiYmxvYl90b2tlbiJ9fQ==--d1ccdf3e94900f0c8f62feb07f43a3d33eb3b0dfheaders:Content-Type: application/pdfschema:@@ -2505,8 +2505,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 326715- slug: product-326715+ name: Product 318715+ slug: product-318715options_text: ''price: '10.00'display_price: "$10.00"@@ -2626,8 +2626,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3272171- slug: product-3272171+ name: Product 3192171+ slug: product-3192171options_text: ''price: '10.00'display_price: "$10.00"@@ -2915,7 +2915,7 @@ paths:total_quantity: 0warnings:- code: line_item_removed- message: Product 331307 was removed because it was sold out+ message: Product 323307 was removed because it was sold outline_item_id: li_UkLWZg9DAJvariant_id: variant_UkLWZg9DAJcoupon_code:@@ -3158,8 +3158,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3323263- slug: product-3323263+ name: Product 3243263+ slug: product-3243263options_text: ''price: '10.00'display_price: "$10.00"@@ -3382,8 +3382,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3348992- slug: product-3348992+ name: Product 3268992+ slug: product-3268992options_text: ''price: '10.00'display_price: "$10.00"@@ -3631,8 +3631,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3374794- slug: product-3374794+ name: Product 3294794+ slug: product-3294794options_text: ''price: '10.00'display_price: "$10.00"@@ -3952,8 +3952,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3702614- slug: product-3702614+ name: Product 3622614+ slug: product-3622614options_text: ''price: '10.00'display_price: "$10.00"@@ -4147,8 +4147,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3713461- slug: product-3713461+ name: Product 3633461+ slug: product-3633461options_text: ''price: '10.00'display_price: "$10.00"@@ -4336,8 +4336,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3738182- slug: product-3738182+ name: Product 3658182+ slug: product-3658182options_text: ''price: '10.00'display_price: "$10.00"@@ -4657,8 +4657,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3755702- slug: product-3755702+ name: Product 3675702+ slug: product-3675702options_text: ''price: '10.00'display_price: "$10.00"@@ -4901,8 +4901,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3799569- slug: product-3799569+ name: Product 3719569+ slug: product-3719569options_text: ''price: '10.00'display_price: "$10.00"@@ -5031,10 +5031,10 @@ paths:total_quantity: 2warnings:- code: delivery_unavailable- message: Product 38263 cannot be delivered to the selected address+ message: Product 37463 cannot be delivered to the selected addressline_item_id: li_UkLWZg9DAJ- code: delivery_unavailable- message: Product 383298 cannot be delivered to the selected address+ message: Product 375298 cannot be delivered to the selected addressline_item_id: li_gbHJdmfrXBcoupon_code:item_total: '29.99'@@ -5093,8 +5093,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 38263- slug: product-38263+ name: Product 37463+ slug: product-37463options_text: ''price: '10.00'display_price: "$10.00"@@ -5124,8 +5124,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 383298- slug: product-383298+ name: Product 375298+ slug: product-375298options_text: ''price: '19.99'display_price: "$19.99"@@ -5340,8 +5340,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3899165- slug: product-3899165+ name: Product 3819165+ slug: product-3819165options_text: ''price: '10.00'display_price: "$10.00"@@ -6148,8 +6148,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 4549789- slug: product-4549789+ name: Product 4469789+ slug: product-4469789options_text: ''price: '10.00'display_price: "$10.00"@@ -6333,8 +6333,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 456179- slug: product-456179+ name: Product 448179+ slug: product-448179options_text: ''price: '10.00'display_price: "$10.00"@@ -6694,8 +6694,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 393496- slug: product-393496+ name: Product 385496+ slug: product-385496options_text: ''price: '10.00'display_price: "$10.00"@@ -8074,8 +8074,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3575270- slug: product-3575270+ name: Product 3495270+ slug: product-3495270options_text: ''price: '10.00'display_price: "$10.00"@@ -8403,8 +8403,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3595633- slug: product-3595633+ name: Product 3515633+ slug: product-3515633options_text: ''price: '10.00'display_price: "$10.00"@@ -11238,7 +11238,7 @@ paths:variant:id: variant_gbHJdmfrXBproduct_id: prod_gbHJdmfrXB- sku: SKU-564+ sku: SKU-556options_text: ''track_inventory: truemedia_count: 0@@ -11324,7 +11324,7 @@ paths:variant:id: variant_UkLWZg9DAJproduct_id: prod_UkLWZg9DAJ- sku: SKU-565+ sku: SKU-557options_text: ''track_inventory: truemedia_count: 0@@ -12854,8 +12854,8 @@ paths:preorder_ships_at:quantity: 1currency: USD- name: Product 3565649- slug: product-3565649+ name: Product 3485649+ slug: product-3485649options_text: ''price: '10.00'display_price: "$10.00"diff --git a/packages/dashboard-core/src/products/digital-asset-edit-sheet.tsx b/packages/dashboard-core/src/products/digital-asset-edit-sheet.tsxindex 0bac5f0ffd..1ed3b8cacc 100644--- a/packages/dashboard-core/src/products/digital-asset-edit-sheet.tsx+++ b/packages/dashboard-core/src/products/digital-asset-edit-sheet.tsx@@ -38,6 +38,11 @@ interface Props {onOpenChange: (open: boolean) => void}+/** The name a variant goes by in the picker, or undefined when there is none. */+export function variantLabel(variant?: DigitalAssetVariantOption): string | undefined {+ return variant ? variant.options_text || variant.sku || variant.id : undefined+}+/** Blank means "use the store's setting", so an empty box is a real value. */function toInput(value: number | null | undefined): string {return value == null ? '' : String(value)@@ -132,7 +137,7 @@ export function DigitalAssetEditSheet({<SelectTrigger id="digital-asset-variant"><SelectValue>{(value) =>- variants?.find((v) => v.id === value)?.options_text ??+ variantLabel(variants?.find((v) => v.id === value)) ??t('admin.digital_assets.all_variants')}</SelectValue>@@ -140,7 +145,7 @@ export function DigitalAssetEditSheet({<SelectContent>{variants?.map((variant) => (<SelectItem key={variant.id} value={variant.id}>- {variant.options_text || variant.sku || variant.id}+ {variantLabel(variant)}</SelectItem>))}</SelectContent>diff --git a/packages/dashboard-core/src/products/digital-assets-card.tsx b/packages/dashboard-core/src/products/digital-assets-card.tsxindex af189de896..693622953b 100644--- a/packages/dashboard-core/src/products/digital-assets-card.tsx+++ b/packages/dashboard-core/src/products/digital-assets-card.tsx@@ -1,5 +1,5 @@import type { DigitalAssetProvider } from '@spree/admin-sdk'-import { formatFileSize, useFileUpload } from '@spree/dashboard-core'+import { formatFileSize, Subject, useFileUpload, usePermissions } from '@spree/dashboard-core'import {Button,Card,@@ -35,7 +35,11 @@ import {import { useRef, useState } from 'react'import { useTranslation } from 'react-i18next'import type { PanelDigitalAsset } from '../api-client'-import { DigitalAssetEditSheet, type DigitalAssetVariantOption } from './digital-asset-edit-sheet'+import {+ DigitalAssetEditSheet,+ type DigitalAssetVariantOption,+ variantLabel,+} from './digital-asset-edit-sheet'import { DigitalAssetProviderSheet } from './digital-asset-provider-sheet'import {useCreateDigitalAsset,@@ -53,6 +57,10 @@ export function DigitalAssetsCard({}) {const { t } = useTranslation()const confirm = useConfirm()+ // Files are part of the product, so changing them needs the product write+ // permission; a read-only role sees the list without the controls.+ const { permissions } = usePermissions()+ const canWrite = permissions.can('update', Subject.Product)const fileInputRef = useRef<HTMLInputElement>(null)const [uploading, setUploading] = useState(false)const [page, setPage] = useState(1)@@ -166,7 +174,7 @@ export function DigitalAssetsCard({</CardTitle>{/* The header action only appears once files exist — an empty cardinvites the first upload through its dropzone, not a button. */}- {assets.length > 0 && (+ {canWrite && assets.length > 0 && (<CardAction>{sourceProviders.length === 0 ? (<Button@@ -225,6 +233,8 @@ export function DigitalAssetsCard({{isLoading ? (<Skeleton className="h-24 w-full" />+ ) : assets.length === 0 && !canWrite ? (+ <p className="text-muted-foreground text-sm">{t('admin.digital_assets.empty')}</p>) : assets.length === 0 ? (<buttontype="button"@@ -282,7 +292,7 @@ export function DigitalAssetsCard({</TableCell>{hasVariants && (<TableCell className="text-muted-foreground">- {variants?.find((v) => v.id === asset.variant_id)?.options_text ?? '—'}+ {variantLabel(variants?.find((v) => v.id === asset.variant_id)) ?? '—'}</TableCell>)}<TableCell className="tabular-nums">@@ -304,9 +314,10 @@ export function DigitalAssetsCard({visible: Boolean(asset.download_url),onSelect: () => window.open(asset.download_url ?? '', '_blank'),},- { key: 'edit', onSelect: () => setEditing(asset) },+ { key: 'edit', visible: canWrite, onSelect: () => setEditing(asset) },{key: 'delete',+ visible: canWrite,destructive: true,onSelect: () => handleDelete(asset),},diff --git a/packages/seller-dashboard/src/pages/product.tsx b/packages/seller-dashboard/src/pages/product.tsxindex 8ae9d11e1c..a32fcaddce 100644--- a/packages/seller-dashboard/src/pages/product.tsx+++ b/packages/seller-dashboard/src/pages/product.tsx@@ -26,7 +26,7 @@ import type { ProductCreateParams } from '@spree/seller-sdk'import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'import { useNavigate, useParams } from '@tanstack/react-router'import { useEffect } from 'react'-import { FormProvider, useForm } from 'react-hook-form'+import { FormProvider, useForm, useWatch } from 'react-hook-form'import { useTranslation } from 'react-i18next'import { sellerClient } from '../api-client'import { CenteredMessage } from '../components/centered-message'@@ -97,6 +97,15 @@ export function ProductPage({ mode }: { mode: 'new' | 'edit' }) {defaultValues: { ...newProductFormDefaults(), ...extensionFormValues('seller.product', null) },})+ // A file is moved between variants as soon as its sheet saves, so it must+ // not be offered a variant the seller removed in the form but not yet saved:+ // saving would delete that variant and the file with it.+ const liveVariants = useWatch({ control: form.control, name: 'variants' })+ const liveVariantIds = new Set((liveVariants ?? []).map((variant) => variant.id).filter(Boolean))+ const assignableVariants = (product?.variants ?? []).filter((variant) =>+ liveVariantIds.has(variant.id),+ )+// Reset once the record arrives, so the inputs show what was last saved// rather than the blank defaults the form mounted with.//@@ -254,11 +263,7 @@ export function ProductPage({ mode }: { mode: 'new' | 'edit' }) {defaultCurrency={profile?.default_currency}/><InventoryCard form={form} />- {/* Writes on its own, file by file, so it needs a saved product- and stays outside the Save button's payload. */}- {productId && (- <DigitalAssetsCard productId={productId} variants={product?.variants ?? []} />- )}+ <DigitalAssetsCard productId={productId} variants={assignableVariants} /><Slot name="seller.product.form_main" context={{ product, mode }} /></>}diff --git a/spree/api/app/controllers/concerns/spree/api/v3/digital_asset_writes.rb b/spree/api/app/controllers/concerns/spree/api/v3/digital_asset_writes.rbindex ff0e48bd41..f09e2e3678 100644--- a/spree/api/app/controllers/concerns/spree/api/v3/digital_asset_writes.rb+++ b/spree/api/app/controllers/concerns/spree/api/v3/digital_asset_writes.rb@@ -56,8 +56,11 @@ module Spree[:variant, { attachment_attachment: :blob }]end+ # Not normalized: `provider_settings` carries the provider's own+ # values, which may look like prefixed ids. Extension attributes are+ # splatted in, the operator's or the seller's list by branch.def permitted_params- params.permit(*declared_permitted_attributes)+ params.permit(*declared_permitted_attributes, *model_additional_permitted_attributes)endprivatediff --git a/spree/api/app/serializers/concerns/spree/api/v3/digital_asset_details.rb b/spree/api/app/serializers/concerns/spree/api/v3/digital_asset_details.rbindex 8813ae6e4a..a0c9776d0f 100644--- a/spree/api/app/serializers/concerns/spree/api/v3/digital_asset_details.rb+++ b/spree/api/app/serializers/concerns/spree/api/v3/digital_asset_details.rb@@ -8,6 +8,12 @@ module Spreemodule DigitalAssetDetailsextend ActiveSupport::Concern+ # The request's store; the asset's own store covers serialization+ # outside a request.+ def self.store_for(digital_asset, params)+ params&.dig(:store) || Spree::Current.store || digital_asset.store+ end+included dotypelize byte_size: [:number, nullable: true],authorized_clicks: [:number, nullable: true],@@ -37,7 +43,7 @@ module Spreeattribute :download_url do |digital_asset, params|next nil unless digital_asset.downloadable?- store = params&.dig(:store) || Spree::Current.store || digital_asset.store+ store = DigitalAssetDetails.store_for(digital_asset, params)begindigital_asset.download_url(expires_in: store.preferred_digital_asset_link_expire_time.seconds)rescue ArgumentError@@ -45,17 +51,13 @@ module Spreeendend- # The limits actually applied, after the store-settings fallback. The- # request's store answers it; the asset's own store covers- # serialization outside a request.+ # The limits actually applied, after the store-settings fallback.attribute :effective_authorized_clicks do |digital_asset, params|- store = params&.dig(:store) || Spree::Current.store || digital_asset.store- digital_asset.effective_authorized_clicks(store)+ digital_asset.effective_authorized_clicks(DigitalAssetDetails.store_for(digital_asset, params))endattribute :effective_authorized_days do |digital_asset, params|- store = params&.dig(:store) || Spree::Current.store || digital_asset.store- digital_asset.effective_authorized_days(store)+ digital_asset.effective_authorized_days(DigitalAssetDetails.store_for(digital_asset, params))endendenddiff --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 c5361beda0..cae7da1523 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@@ -114,6 +114,37 @@ RSpec.describe Spree::Api::V3::Seller::Products::DigitalAssetsController, type:describe 'PATCH #update' dolet!(:digital_asset) { create(:digital_asset, variant: variant, authorized_days: 7) }+ context 'with attributes an extension opened' do+ around do |example|+ operator_attributes = Spree::DigitalAsset.additional_permitted_attributes+ seller_attributes = Spree::DigitalAsset.additional_seller_permitted_attributes+ example.run+ ensure+ Spree::DigitalAsset.additional_permitted_attributes = operator_attributes+ Spree::DigitalAsset.additional_seller_permitted_attributes = seller_attributes+ end++ it 'saves one opened to sellers' do+ Spree::DigitalAsset.additional_seller_permitted_attributes += [{ metadata: {} }]++ patch :update, params: { product_id: product.prefixed_id, id: digital_asset.prefixed_id,+ metadata: { 'note' => 'seller' } }, as: :json++ expect(response).to have_http_status(:ok)+ expect(digital_asset.reload.metadata).to include('note' => 'seller')+ end++ it 'ignores one opened to operators only' do+ Spree::DigitalAsset.additional_permitted_attributes += [{ metadata: {} }]++ patch :update, params: { product_id: product.prefixed_id, id: digital_asset.prefixed_id,+ metadata: { 'note' => 'operator' } }, as: :json++ expect(response).to have_http_status(:ok)+ expect(digital_asset.reload.metadata).not_to include('note')+ end+ end+it 'replaces the file and clears a limit back to the store default' dopatch :update, params: {product_id: product.prefixed_id,