Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Fix: stop offering seller-only permissions to staff roles (#14640)

Damian Legawiec8e9a969d177e
diff --git a/docs/api-reference/admin.yaml b/docs/api-reference/admin.yaml
index c5a66906c4..2af55c0824 100644
--- a/docs/api-reference/admin.yaml
+++ b/docs/api-reference/admin.yaml
@@ -342,6 +342,9 @@ paths:
- all
has_conditions: false
permission_keys:
+ - read_dashboard
+ - read_reports
+ - write_reports
- read_orders
- write_orders
- read_payments
@@ -350,10 +353,6 @@ paths:
- write_fulfillments
- read_refunds
- write_refunds
- - read_gift_cards
- - write_gift_cards
- - read_store_credits
- - write_store_credits
- read_products
- write_products
- read_product_types
@@ -370,10 +369,20 @@ paths:
- write_stock
- read_purchasing
- write_purchasing
- - read_promotions
- - write_promotions
- read_customers
- write_customers
+ - read_sellers
+ - write_sellers
+ - read_commissions
+ - write_commissions
+ - read_payouts
+ - write_payouts
+ - read_gift_cards
+ - write_gift_cards
+ - read_store_credits
+ - write_store_credits
+ - read_promotions
+ - write_promotions
- read_settings
- write_settings
- read_delivery_methods
@@ -388,18 +397,6 @@ paths:
- write_api_keys
- read_staff
- write_staff
- - read_sellers
- - write_sellers
- - read_commissions
- - write_commissions
- - read_payouts
- - write_payouts
- - read_seller_profile
- - write_seller_profile
- - read_seller_earnings
- - read_dashboard
- - read_reports
- - write_reports
schema:
"$ref": "#/components/schemas/MeResponse"
'401':
@@ -482,6 +479,9 @@ paths:
- all
has_conditions: false
permission_keys:
+ - read_dashboard
+ - read_reports
+ - write_reports
- read_orders
- write_orders
- read_payments
@@ -490,10 +490,6 @@ paths:
- write_fulfillments
- read_refunds
- write_refunds
- - read_gift_cards
- - write_gift_cards
- - read_store_credits
- - write_store_credits
- read_products
- write_products
- read_product_types
@@ -510,10 +506,20 @@ paths:
- write_stock
- read_purchasing
- write_purchasing
- - read_promotions
- - write_promotions
- read_customers
- write_customers
+ - read_sellers
+ - write_sellers
+ - read_commissions
+ - write_commissions
+ - read_payouts
+ - write_payouts
+ - read_gift_cards
+ - write_gift_cards
+ - read_store_credits
+ - write_store_credits
+ - read_promotions
+ - write_promotions
- read_settings
- write_settings
- read_delivery_methods
@@ -528,18 +534,6 @@ paths:
- write_api_keys
- read_staff
- write_staff
- - read_sellers
- - write_sellers
- - read_commissions
- - write_commissions
- - read_payouts
- - write_payouts
- - read_seller_profile
- - write_seller_profile
- - read_seller_earnings
- - read_dashboard
- - read_reports
- - write_reports
schema:
"$ref": "#/components/schemas/MeResponse"
requestBody:
@@ -24452,6 +24446,27 @@ paths:
application/json:
example:
data:
+ - key: read_dashboard
+ resource: dashboard
+ kind: read
+ group: analytics
+ group_label: Analytics
+ label: Analytics dashboard
+ description: Sales and performance analytics
+ - key: read_reports
+ resource: reports
+ kind: read
+ group: analytics
+ group_label: Analytics
+ label: Reports
+ description: ''
+ - key: write_reports
+ resource: reports
+ kind: write
+ group: analytics
+ group_label: Analytics
+ label: Reports
+ description: ''
- key: read_orders
resource: orders
kind: read
@@ -24508,34 +24523,6 @@ paths:
group_label: Orders
label: Refunds
description: Issue and view refunds
- - key: read_gift_cards
- resource: gift_cards
- kind: read
- group: loyalty
- group_label: Loyalty
- label: Gift cards
- description: Gift cards and gift card batches
- - key: write_gift_cards
- resource: gift_cards
- kind: write
- group: loyalty
- group_label: Loyalty
- label: Gift cards
- description: Gift cards and gift card batches
- - key: read_store_credits
- resource: store_credits
- kind: read
- group: loyalty
- group_label: Loyalty
- label: Store credits
- description: Customer store credit balances
- - key: write_store_credits
- resource: store_credits
- kind: write
- group: loyalty
- group_label: Loyalty
- label: Store credits
- description: Customer store credit balances
- key: read_products
resource: products
kind: read
@@ -24648,20 +24635,6 @@ paths:
group_label: Catalog
label: Purchasing
description: Suppliers and purchase orders
- - key: read_promotions
- resource: promotions
- kind: read
- group: marketing
- group_label: Marketing
- label: Promotions
- description: Promotions, rules and coupon codes
- - key: write_promotions
- resource: promotions
- kind: write
- group: marketing
- group_label: Marketing
- label: Promotions
- description: Promotions, rules and coupon codes
- key: read_customers
resource: customers
kind: read
@@ -24676,6 +24649,90 @@ paths:
group_label: Customers
label: Customers
description: Customer accounts, addresses, cards and groups
+ - key: read_sellers
+ resource: sellers
+ kind: read
+ group: sellers
+ group_label: Sellers
+ label: Sellers
+ description: ''
+ - key: write_sellers
+ resource: sellers
+ kind: write
+ group: sellers
+ group_label: Sellers
+ label: Sellers
+ description: ''
+ - key: read_commissions
+ resource: commissions
+ kind: read
+ group: sellers
+ group_label: Sellers
+ label: Commissions
+ description: ''
+ - key: write_commissions
+ resource: commissions
+ kind: write
+ group: sellers
+ group_label: Sellers
+ label: Commissions
+ description: ''
+ - key: read_payouts
+ resource: payouts
+ kind: read
+ group: sellers
+ group_label: Sellers
+ label: Payouts
+ description: ''
+ - key: write_payouts
+ resource: payouts
+ kind: write
+ group: sellers
+ group_label: Sellers
+ label: Payouts
+ description: ''
+ - key: read_gift_cards
+ resource: gift_cards
+ kind: read
+ group: loyalty
+ group_label: Loyalty
+ label: Gift cards
+ description: Gift cards and gift card batches
+ - key: write_gift_cards
+ resource: gift_cards
+ kind: write
+ group: loyalty
+ group_label: Loyalty
+ label: Gift cards
+ description: Gift cards and gift card batches
+ - key: read_store_credits
+ resource: store_credits
+ kind: read
+ group: loyalty
+ group_label: Loyalty
+ label: Store credits
+ description: Customer store credit balances
+ - key: write_store_credits
+ resource: store_credits
+ kind: write
+ group: loyalty
+ group_label: Loyalty
+ label: Store credits
+ description: Customer store credit balances
+ - key: read_promotions
+ resource: promotions
+ kind: read
+ group: marketing
+ group_label: Marketing
+ label: Promotions
+ description: Promotions, rules and coupon codes
+ - key: write_promotions
+ resource: promotions
+ kind: write
+ group: marketing
+ group_label: Marketing
+ label: Promotions
+ description: Promotions, rules and coupon codes
- key: read_settings
resource: settings
kind: read
@@ -24774,92 +24831,8 @@ paths:
group_label: Access
label: Staff & roles
description: Team members, invitations, roles and their permissions
- - key: read_sellers
- resource: sellers
- kind: read
- group: access
- group_label: Access
- label: Sellers
- description: ''
- - key: write_sellers
- resource: sellers
- kind: write
- group: access
- group_label: Access
- label: Sellers
- description: ''
- - key: read_commissions
- resource: commissions
- kind: read
- group: access
- group_label: Access
- label: Commissions
- description: ''
- - key: write_commissions
- resource: commissions
- kind: write
- group: access
- group_label: Access
- label: Commissions
- description: ''
- - key: read_payouts
- resource: payouts
- kind: read
- group: access
- group_label: Access
- label: Payouts
- description: ''
- - key: write_payouts
- resource: payouts
- kind: write
- group: access
- group_label: Access
- label: Payouts
- description: ''
- - key: read_seller_profile
- resource: seller_profile
- kind: read
- group: access
- group_label: Access
- label: Seller profile
- description: ''
- - key: write_seller_profile
- resource: seller_profile
- kind: write
- group: access
- group_label: Access
- label: Seller profile
- description: ''
- - key: read_seller_earnings
- resource: seller_earnings
- kind: read
- group: access
- group_label: Access
- label: Seller earnings
- description: ''
- - key: read_dashboard
- resource: dashboard
- kind: read
- group: analytics
- group_label: Analytics
- label: Analytics dashboard
- description: Sales and performance analytics
- - key: read_reports
- resource: reports
- kind: read
- group: analytics
- group_label: Analytics
- label: Reports
- description: ''
- - key: write_reports
- resource: reports
- kind: write
- group: analytics
- group_label: Analytics
- label: Reports
- description: ''
meta:
- count: 58
+ count: 55
"/api/v3/admin/roles":
get:
summary: List roles
@@ -24911,6 +24884,9 @@ paths:
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
permissions:
+ - read_dashboard
+ - read_reports
+ - write_reports
- read_orders
- write_orders
- read_payments
@@ -24919,10 +24895,6 @@ paths:
- write_fulfillments
- read_refunds
- write_refunds
- - read_gift_cards
- - write_gift_cards
- - read_store_credits
- - write_store_credits
- read_products
- write_products
- read_product_types
@@ -24939,10 +24911,20 @@ paths:
- write_stock
- read_purchasing
- write_purchasing
- - read_promotions
- - write_promotions
- read_customers
- write_customers
+ - read_sellers
+ - write_sellers
+ - read_commissions
+ - write_commissions
+ - read_payouts
+ - write_payouts
+ - read_gift_cards
+ - write_gift_cards
+ - read_store_credits
+ - write_store_credits
+ - read_promotions
+ - write_promotions
- read_settings
- write_settings
- read_delivery_methods
@@ -24957,18 +24939,6 @@ paths:
- write_api_keys
- read_staff
- write_staff
- - read_sellers
- - write_sellers
- - read_commissions
- - write_commissions
- - read_payouts
- - write_payouts
- - read_seller_profile
- - write_seller_profile
- - read_seller_earnings
- - read_dashboard
- - read_reports
- - write_reports
mutable: false
users_count: 1
meta:
@@ -25046,12 +25016,16 @@ paths:
example:
error:
code: validation_error
- message: 'Permissions contains unknown permissions: write_bogus'
+ message: 'Permissions contains unknown permissions: write_bogus
+ and Permissions cannot be granted to a store role: write_bogus'
details:
permissions:
- code: role_permissions_unknown
message: 'contains unknown permissions: write_bogus'
specific: false
+ - code: role_permissions_not_grantable_for_audience
+ message: 'cannot be granted to a store role: write_bogus'
+ specific: false
requestBody:
content:
application/json:
@@ -32792,13 +32766,13 @@ paths:
video_embed_url:
video_url:
poster_url:
- original_url: http://localhost:3000/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/thinking-cat.jpg
- mini_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjgsMTI4XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--6e0b00316ff259ca72f01e5fa8c0e6d47d44f586/thinking-cat.jpg
- small_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyNTYsMjU2XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--4e4737de3b9d8c5ab3ac3e9cfa1647ec2755dbda/thinking-cat.jpg
- medium_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls0MDAsNDAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--8f824e6b0b17ff6477085f6cc361191c98eb8266/thinking-cat.jpg
- large_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls3MjAsNzIwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--18a44632ea7357cee0359d0c2bed39b733e923c4/thinking-cat.jpg
- xlarge_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyMDAwLDIwMDBdLCJzYXZlciI6eyJzdHJpcCI6dHJ1ZSwicXVhbGl0eSI6NzUsImxvc3NsZXNzIjpmYWxzZSwiYWxwaGFfcSI6ODUsInJlZHVjdGlvbl9lZmZvcnQiOjYsInNtYXJ0X3N1YnNhbXBsZSI6dHJ1ZX19LCJwdXIiOiJ2YXJpYXRpb24ifX0=--548b44418f7b10929a5bf25fbd9a6a643b513ab5/thinking-cat.jpg
- og_image_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjAwLDYzMF0sInNhdmVyIjp7InN0cmlwIjp0cnVlLCJxdWFsaXR5Ijo3NSwibG9zc2xlc3MiOmZhbHNlLCJhbHBoYV9xIjo4NSwicmVkdWN0aW9uX2VmZm9ydCI6Niwic21hcnRfc3Vic2FtcGxlIjp0cnVlfX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--7bea325100367a1a8ce37b150c65c79b604be719/thinking-cat.jpg
+ original_url: http://localhost:3000/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/thinking-cat.jpg
+ mini_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjgsMTI4XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--84a47660df029c84dcf872b76a3cf4cef3d783ad/thinking-cat.jpg
+ small_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyNTYsMjU2XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--2f34545691e57f6845e1a927bc06aa81970f54a7/thinking-cat.jpg
+ medium_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls0MDAsNDAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--79634827de815bd922ada0dbc9e4401e56b63185/thinking-cat.jpg
+ large_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls3MjAsNzIwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--0ea5e4d32e7aad46e5690041fb5e72158deb2276/thinking-cat.jpg
+ xlarge_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyMDAwLDIwMDBdLCJzYXZlciI6eyJzdHJpcCI6dHJ1ZSwicXVhbGl0eSI6NzUsImxvc3NsZXNzIjpmYWxzZSwiYWxwaGFfcSI6ODUsInJlZHVjdGlvbl9lZmZvcnQiOjYsInNtYXJ0X3N1YnNhbXBsZSI6dHJ1ZX19LCJwdXIiOiJ2YXJpYXRpb24ifX0=--628f4260bc36defd4641a34a961355bd8f7396eb/thinking-cat.jpg
+ og_image_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjAwLDYzMF0sInNhdmVyIjp7InN0cmlwIjp0cnVlLCJxdWFsaXR5Ijo3NSwibG9zc2xlc3MiOmZhbHNlLCJhbHBoYV9xIjo4NSwicmVkdWN0aW9uX2VmZm9ydCI6Niwic21hcnRfc3Vic2FtcGxlIjp0cnVlfX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--0f0ac5549f5ab938bbb805b975fb12f879dd89dc/thinking-cat.jpg
external_references: {}
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
@@ -32806,10 +32780,10 @@ paths:
filename: thinking-cat.jpg
content_type: image/jpeg
byte_size: 18090
- embed_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2xpbWl0IjpbMTIwMCwxMjAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--6eb647891da8012a06b60e1989bb7af4f68b0ec0/thinking-cat.jpg
- signed_id: eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1
+ embed_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2xpbWl0IjpbMTIwMCwxMjAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--09e4cae87a6b15694e5f2c53890f1e8c8c3dd98a/thinking-cat.jpg
+ signed_id: eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354
viewable_id: prod_UkLWZg9DAJ
- download_url: http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/thinking-cat.jpg?disposition=attachment
+ download_url: http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/thinking-cat.jpg?disposition=attachment
metadata: {}
viewable_type: product
meta:
@@ -32880,13 +32854,13 @@ paths:
video_embed_url:
video_url:
poster_url:
- original_url: http://localhost:3000/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--c44cdefef8e662078a349557e3a1371a62f56057/library-upload.jpg
- mini_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--c44cdefef8e662078a349557e3a1371a62f56057/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjgsMTI4XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--6e0b00316ff259ca72f01e5fa8c0e6d47d44f586/library-upload.jpg
- small_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--c44cdefef8e662078a349557e3a1371a62f56057/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyNTYsMjU2XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--4e4737de3b9d8c5ab3ac3e9cfa1647ec2755dbda/library-upload.jpg
- medium_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--c44cdefef8e662078a349557e3a1371a62f56057/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls0MDAsNDAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--8f824e6b0b17ff6477085f6cc361191c98eb8266/library-upload.jpg
- large_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--c44cdefef8e662078a349557e3a1371a62f56057/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls3MjAsNzIwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--18a44632ea7357cee0359d0c2bed39b733e923c4/library-upload.jpg
- xlarge_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--c44cdefef8e662078a349557e3a1371a62f56057/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyMDAwLDIwMDBdLCJzYXZlciI6eyJzdHJpcCI6dHJ1ZSwicXVhbGl0eSI6NzUsImxvc3NsZXNzIjpmYWxzZSwiYWxwaGFfcSI6ODUsInJlZHVjdGlvbl9lZmZvcnQiOjYsInNtYXJ0X3N1YnNhbXBsZSI6dHJ1ZX19LCJwdXIiOiJ2YXJpYXRpb24ifX0=--548b44418f7b10929a5bf25fbd9a6a643b513ab5/library-upload.jpg
- og_image_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--c44cdefef8e662078a349557e3a1371a62f56057/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjAwLDYzMF0sInNhdmVyIjp7InN0cmlwIjp0cnVlLCJxdWFsaXR5Ijo3NSwibG9zc2xlc3MiOmZhbHNlLCJhbHBoYV9xIjo4NSwicmVkdWN0aW9uX2VmZm9ydCI6Niwic21hcnRfc3Vic2FtcGxlIjp0cnVlfX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--7bea325100367a1a8ce37b150c65c79b604be719/library-upload.jpg
+ original_url: http://localhost:3000/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--8ff72e91870a04a53281fbf0de80d9b8d9d2bca2/library-upload.jpg
+ mini_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--8ff72e91870a04a53281fbf0de80d9b8d9d2bca2/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjgsMTI4XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--84a47660df029c84dcf872b76a3cf4cef3d783ad/library-upload.jpg
+ small_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--8ff72e91870a04a53281fbf0de80d9b8d9d2bca2/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyNTYsMjU2XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--2f34545691e57f6845e1a927bc06aa81970f54a7/library-upload.jpg
+ medium_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--8ff72e91870a04a53281fbf0de80d9b8d9d2bca2/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls0MDAsNDAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--79634827de815bd922ada0dbc9e4401e56b63185/library-upload.jpg
+ large_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--8ff72e91870a04a53281fbf0de80d9b8d9d2bca2/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls3MjAsNzIwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--0ea5e4d32e7aad46e5690041fb5e72158deb2276/library-upload.jpg
+ xlarge_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--8ff72e91870a04a53281fbf0de80d9b8d9d2bca2/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyMDAwLDIwMDBdLCJzYXZlciI6eyJzdHJpcCI6dHJ1ZSwicXVhbGl0eSI6NzUsImxvc3NsZXNzIjpmYWxzZSwiYWxwaGFfcSI6ODUsInJlZHVjdGlvbl9lZmZvcnQiOjYsInNtYXJ0X3N1YnNhbXBsZSI6dHJ1ZX19LCJwdXIiOiJ2YXJpYXRpb24ifX0=--628f4260bc36defd4641a34a961355bd8f7396eb/library-upload.jpg
+ og_image_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--8ff72e91870a04a53281fbf0de80d9b8d9d2bca2/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjAwLDYzMF0sInNhdmVyIjp7InN0cmlwIjp0cnVlLCJxdWFsaXR5Ijo3NSwibG9zc2xlc3MiOmZhbHNlLCJhbHBoYV9xIjo4NSwicmVkdWN0aW9uX2VmZm9ydCI6Niwic21hcnRfc3Vic2FtcGxlIjp0cnVlfX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--0f0ac5549f5ab938bbb805b975fb12f879dd89dc/library-upload.jpg
external_references: {}
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
@@ -32894,10 +32868,10 @@ paths:
filename: library-upload.jpg
content_type: image/jpeg
byte_size: 18090
- embed_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--c44cdefef8e662078a349557e3a1371a62f56057/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2xpbWl0IjpbMTIwMCwxMjAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--6eb647891da8012a06b60e1989bb7af4f68b0ec0/library-upload.jpg
- signed_id: eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--c44cdefef8e662078a349557e3a1371a62f56057
+ embed_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--8ff72e91870a04a53281fbf0de80d9b8d9d2bca2/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2xpbWl0IjpbMTIwMCwxMjAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--09e4cae87a6b15694e5f2c53890f1e8c8c3dd98a/library-upload.jpg
+ signed_id: eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--8ff72e91870a04a53281fbf0de80d9b8d9d2bca2
viewable_id:
- download_url: http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--c44cdefef8e662078a349557e3a1371a62f56057/library-upload.jpg?disposition=attachment
+ download_url: http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MiwicHVyIjoiYmxvYl9pZCJ9fQ==--8ff72e91870a04a53281fbf0de80d9b8d9d2bca2/library-upload.jpg?disposition=attachment
metadata: {}
viewable_type:
schema:
@@ -33054,13 +33028,13 @@ paths:
video_embed_url:
video_url:
poster_url:
- original_url: http://localhost:3000/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/thinking-cat.jpg
- mini_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjgsMTI4XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--6e0b00316ff259ca72f01e5fa8c0e6d47d44f586/thinking-cat.jpg
- small_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyNTYsMjU2XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--4e4737de3b9d8c5ab3ac3e9cfa1647ec2755dbda/thinking-cat.jpg
- medium_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls0MDAsNDAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--8f824e6b0b17ff6477085f6cc361191c98eb8266/thinking-cat.jpg
- large_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls3MjAsNzIwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--18a44632ea7357cee0359d0c2bed39b733e923c4/thinking-cat.jpg
- xlarge_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyMDAwLDIwMDBdLCJzYXZlciI6eyJzdHJpcCI6dHJ1ZSwicXVhbGl0eSI6NzUsImxvc3NsZXNzIjpmYWxzZSwiYWxwaGFfcSI6ODUsInJlZHVjdGlvbl9lZmZvcnQiOjYsInNtYXJ0X3N1YnNhbXBsZSI6dHJ1ZX19LCJwdXIiOiJ2YXJpYXRpb24ifX0=--548b44418f7b10929a5bf25fbd9a6a643b513ab5/thinking-cat.jpg
- og_image_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjAwLDYzMF0sInNhdmVyIjp7InN0cmlwIjp0cnVlLCJxdWFsaXR5Ijo3NSwibG9zc2xlc3MiOmZhbHNlLCJhbHBoYV9xIjo4NSwicmVkdWN0aW9uX2VmZm9ydCI6Niwic21hcnRfc3Vic2FtcGxlIjp0cnVlfX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--7bea325100367a1a8ce37b150c65c79b604be719/thinking-cat.jpg
+ original_url: http://localhost:3000/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/thinking-cat.jpg
+ mini_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjgsMTI4XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--84a47660df029c84dcf872b76a3cf4cef3d783ad/thinking-cat.jpg
+ small_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyNTYsMjU2XSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--2f34545691e57f6845e1a927bc06aa81970f54a7/thinking-cat.jpg
+ medium_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls0MDAsNDAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--79634827de815bd922ada0dbc9e4401e56b63185/thinking-cat.jpg
+ large_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOls3MjAsNzIwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--0ea5e4d32e7aad46e5690041fb5e72158deb2276/thinking-cat.jpg
+ xlarge_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsyMDAwLDIwMDBdLCJzYXZlciI6eyJzdHJpcCI6dHJ1ZSwicXVhbGl0eSI6NzUsImxvc3NsZXNzIjpmYWxzZSwiYWxwaGFfcSI6ODUsInJlZHVjdGlvbl9lZmZvcnQiOjYsInNtYXJ0X3N1YnNhbXBsZSI6dHJ1ZX19LCJwdXIiOiJ2YXJpYXRpb24ifX0=--628f4260bc36defd4641a34a961355bd8f7396eb/thinking-cat.jpg
+ og_image_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2ZpbGwiOlsxMjAwLDYzMF0sInNhdmVyIjp7InN0cmlwIjp0cnVlLCJxdWFsaXR5Ijo3NSwibG9zc2xlc3MiOmZhbHNlLCJhbHBoYV9xIjo4NSwicmVkdWN0aW9uX2VmZm9ydCI6Niwic21hcnRfc3Vic2FtcGxlIjp0cnVlfX0sInB1ciI6InZhcmlhdGlvbiJ9fQ==--0f0ac5549f5ab938bbb805b975fb12f879dd89dc/thinking-cat.jpg
external_references: {}
created_at: '2026-01-15T12:00:00.000Z'
updated_at: '2026-01-15T12:00:00.000Z'
@@ -33068,10 +33042,10 @@ paths:
filename: thinking-cat.jpg
content_type: image/jpeg
byte_size: 18090
- embed_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2xpbWl0IjpbMTIwMCwxMjAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--6eb647891da8012a06b60e1989bb7af4f68b0ec0/thinking-cat.jpg
- signed_id: eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1
+ embed_url: http://localhost:3000/rails/active_storage/representations/proxy/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/eyJfcmFpbHMiOnsiZGF0YSI6eyJmb3JtYXQiOiJ3ZWJwIiwicmVzaXplX3RvX2xpbWl0IjpbMTIwMCwxMjAwXSwic2F2ZXIiOnsic3RyaXAiOnRydWUsInF1YWxpdHkiOjc1LCJsb3NzbGVzcyI6ZmFsc2UsImFscGhhX3EiOjg1LCJyZWR1Y3Rpb25fZWZmb3J0Ijo2LCJzbWFydF9zdWJzYW1wbGUiOnRydWV9fSwicHVyIjoidmFyaWF0aW9uIn19--09e4cae87a6b15694e5f2c53890f1e8c8c3dd98a/thinking-cat.jpg
+ signed_id: eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354
viewable_id: prod_gbHJdmfrXB
- download_url: http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--5126cb202a4e0cdc0b7adc65de495e3a09aa56f1/thinking-cat.jpg?disposition=attachment
+ download_url: http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MSwicHVyIjoiYmxvYl9pZCJ9fQ==--7e8e4ef71e597b2153b11e0362cf201addb1c354/thinking-cat.jpg?disposition=attachment
metadata: {}
viewable_type: product
schema:
@@ -36066,6 +36040,7 @@ paths:
name: Accept terms
description: Read and accept the marketplace terms
preferences:
+ terms_body:
terms_effective_from:
terms_url:
custom_field_definition_ids: []
@@ -36289,6 +36264,9 @@ paths:
accepted_content_types: []
association_fields: []
preference_schema:
+ - key: terms_body
+ type: text
+ default:
- key: terms_effective_from
type: string
default:
diff --git a/docs/developer/customization/permissions.mdx b/docs/developer/customization/permissions.mdx
index 2dafadb918..229ec7cff0 100644
--- a/docs/developer/customization/permissions.mdx
+++ b/docs/developer/customization/permissions.mdx
@@ -23,20 +23,38 @@ A role with `mutable: false` (set from seeds or the console) renders read-only i
## Registering extension permissions
-Register your models as a catalog resource once; the keys appear in the role editor and become mintable API-key scopes with no further wiring:
+Register your models as a catalog scope once; the keys appear in the role editor and become mintable API-key scopes with no further wiring:
```ruby
# in your engine's initializer
-Spree.permissions.register_resource(:reviews, group: :catalog, subjects: -> {
+Spree.permissions.register_scope(:reviews, group: :catalog, resources: -> {
[SpreeReviews::Review]
})
```
-- `group` places the row in the permission pickers (`:orders`, `:catalog`, `:marketing`, `:customers`, `:settings`, `:access`, `:analytics` — or your own).
-- `subjects` is a lambda returning the CanCanCan subjects the keys grant; it resolves lazily, so load order does not matter.
-- Pass `write: false` for read-only resources.
+- `group` places the row in the permission pickers (`:analytics`, `:orders`, `:catalog`, `:customers`, `:sellers`, `:loyalty`, `:marketing`, `:settings`, `:access` — or your own). Rows render in registration order, so a scope registered from an initializer lands after core's.
+- `resources` is a lambda returning the CanCanCan subjects the keys grant; it resolves lazily, so load order does not matter.
+- Pass `write: false` for read-only scopes.
-Localize the labels in your engine's locale file under `spree.permissions_catalog.resources.<name>` (`label` and `description`), and declare the same resource on your admin controllers with `scoped_resource :reviews`.
+Localize the labels in your engine's locale file under `spree.permissions_catalog.resources.<name>` (`label` and `description`), and declare the same scope on your admin controllers with `scoped_resource :reviews`.
+
+## Who may hold a key
+
+`audiences` is the complete list of audiences whose roles may hold a scope's keys. The store's own back office is `:store`, and is the list when a registration names none — so the example above is grantable to staff and nobody else.
+
+```ruby
+# Staff configure the marketplace's; a seller configures their own.
+Spree.permissions.register_scope(:reviews, group: :catalog, audiences: %i[store seller], resources: -> {
+ [SpreeReviews::Review]
+})
+```
+
+Naming another audience exposes the scope to a principal outside the store's own staff, so it is always a deliberate act. Two consequences worth knowing:
+
+- **Leaving `:store` out** keeps the scope off the staff permission picker, out of `read_all` / `write_all`, and unmintable on a secret API key — which is how a seller panel's own scopes (`seller_profile`, `seller_earnings`) exist without a store role ever being offered them.
+- **`read_only_for: %i[seller]`** gives that audience the read key alone, for a vocabulary they consult but do not own.
+
+A key never decides *which rows* its holder reaches. That is the controller's job, through scope fetching — a seller holding `write_products` manages their own products because the seller API reads through `current_seller`, not because the key says so.
## Beyond the catalog
diff --git a/docs/developer/dashboard/customization/permissions.mdx b/docs/developer/dashboard/customization/permissions.mdx
index 18585043d8..ccf6e9c203 100644
--- a/docs/developer/dashboard/customization/permissions.mdx
+++ b/docs/developer/dashboard/customization/permissions.mdx
@@ -103,7 +103,7 @@ The same `permissions` object backs the nav registry's `if` predicate, so you ca
## Custom permissions
-If your customization introduces a new model on the backend, register it as a permission catalog resource there (`Spree.permissions.register_resource` in your engine's initializer). Its keys then appear in the role editor and the API-key scope picker, and any role granted them makes `permissions.can('read', 'MyApp::Report')` resolve in the dashboard exactly like a first-party check — the abilities ship with the current-user response (`GET /api/v3/admin/me`) at sign-in, alongside `permission_keys`, the flat key list the role editor grants from.
+If your customization introduces a new model on the backend, register it as a permission catalog scope there (`Spree.permissions.register_scope` in your engine's initializer). Its keys then appear in the role editor and the API-key scope picker, and any role granted them makes `permissions.can('read', 'MyApp::Report')` resolve in the dashboard exactly like a first-party check — the abilities ship with the current-user response (`GET /api/v3/admin/me`) at sign-in, alongside `permission_keys`, the flat key list the role editor grants from.
## Reference
diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdx
index 2791b46aaa..d4c35f8e4b 100644
--- a/docs/developer/upgrades/5.6-to-6.0.mdx
+++ b/docs/developer/upgrades/5.6-to-6.0.mdx
@@ -683,7 +683,7 @@ Spree::Role.find_or_create_by!(name: 'support')
Storefront customers are not part of this system: the old `:default` role and `DefaultCustomer` set are gone, customers never resolve roles, and the Store API no longer consults CanCanCan at all — customer authorization is ownership-scoped queries plus `Spree::Storefront::AccessPolicy` (swappable via `Spree::Dependencies.storefront_access_policy_class`). If an extension added storefront `can` rules, move them into an access-policy subclass or a checkout workflow `validate` hook. Extensions register their resources into the catalog once, which makes them grantable to roles **and** mintable as API-key scopes:
```ruby
-Spree.permissions.register_resource(:reviews, group: :catalog, subjects: -> { [SpreeReviews::Review] })
+Spree.permissions.register_scope(:reviews, group: :catalog, resources: -> { [SpreeReviews::Review] })
```
Two enforcement changes on the Admin API:
diff --git a/docs/plans/6.0-admin-rbac.md b/docs/plans/6.0-admin-rbac.md
index 5f4adf9deb..5c8de085db 100644
--- a/docs/plans/6.0-admin-rbac.md
+++ b/docs/plans/6.0-admin-rbac.md
@@ -1,6 +1,6 @@
# Admin RBAC and Permission Management
-**Status:** Implemented (2026-08-16, PR #14412 and follow-ups) — the permission catalog is the scope vocabulary (`Spree::Core::PermissionConfiguration` + `register_resource`), `Spree::PermissionSets` is deleted with no bridge, roles are pure data on `spree_roles` (`permissions` JSON + `description` + `mutable` + polymorphic `resource`), and the surface is live: `/admin/roles` CRUD, `GET /admin/permissions`, `permission_keys` on `/admin/me` and `/seller/me`, the dashboard roles page + shared `PermissionPicker`, locales in all six languages, `roles.spec.ts`, and a rewritten `docs/developer/customization/permissions.mdx`. **Remaining:** the plan's full-page role editor at `/settings/roles/$roleId` — the dashboard ships a single `settings/roles.tsx` page instead. **6.1:** evaluate removing CanCanCan from the admin path (step 11)
+**Status:** Implemented (2026-08-16, PR #14412 and follow-ups) — the permission catalog is the scope vocabulary (`Spree::Core::PermissionConfiguration` + `register_scope`), `Spree::PermissionSets` is deleted with no bridge, roles are pure data on `spree_roles` (`permissions` JSON + `description` + `mutable` + polymorphic `resource`), and the surface is live: `/admin/roles` CRUD, `GET /admin/permissions`, `permission_keys` on `/admin/me` and `/seller/me`, the dashboard roles page + shared `PermissionPicker`, locales in all six languages, `roles.spec.ts`, and a rewritten `docs/developer/customization/permissions.mdx`. **Remaining:** the plan's full-page role editor at `/settings/roles/$roleId` — the dashboard ships a single `settings/roles.tsx` page instead. **6.1:** evaluate removing CanCanCan from the admin path (step 11)
**Target:** Spree 6.0
**Depends on:** `5.5-admin-api-key-scopes.md` (shipped), `6.0-admin-api.md`, `6.0-admin-spa.md`, `6.0-platform-auth.md` (Customer/Staff split)
**Author:** Damian (from spree/spree#14164 by @caspianlwoods)
@@ -241,13 +241,13 @@ object), populated by core at boot and open to extensions:
```ruby
# core registration (engine initializer)
-Spree.permissions.register_resource(:orders, group: :orders, subjects: -> {
+Spree.permissions.register_scope(:orders, group: :orders, resources: -> {
[Spree::Order, Spree::LineItem, Spree::TaxLine, Spree::Discount, Spree::Fee,
Spree::Return, Spree::Exchange, Spree::Claim]
})
# an extension — one call yields the role-editor row AND mintable key scopes
-Spree.permissions.register_resource(:reviews, group: :catalog, subjects: -> {
+Spree.permissions.register_scope(:reviews, group: :catalog, resources: -> {
[SpreeReviews::Review]
})
```
@@ -518,7 +518,7 @@ all resolved 2026-08-07 and live in Key Decisions. Genuinely deferred:
seller-safe resources (products, orders, fulfillments, stock, analytics —
never `settings`, `staff`, `api_keys`); the editor filters the grid by
audience, and assignment / invitation guards pair audience with resource
- type. **Shipped 2026-08-16** as `register_resource(audiences: %i[seller])`
+ type. **Shipped 2026-08-16** as `register_scope(audiences: %i[store seller])`
— a list of the audiences *beyond staff* a resource opens up, rather than
a seller-specific boolean, so a third panel adds a value instead of a
column (decisions.md 2026-08-16). `Spree.permissions.grantable_keys(audience)`
diff --git a/docs/plans/6.0-inventory-operations.md b/docs/plans/6.0-inventory-operations.md
index a8193732fd..bcd0708fa7 100644
--- a/docs/plans/6.0-inventory-operations.md
+++ b/docs/plans/6.0-inventory-operations.md
@@ -128,7 +128,7 @@ plan written against 5.x idioms that 6.0 has since retired.
`spree:upgrade:purge_migrated_external_receives` removes them when a merchant is ready.
- **Suppliers and purchase orders are one new permission-catalog resource, `:purchasing`.**
`read_purchasing` / `write_purchasing`, registered in
- `PermissionConfiguration#register_default_resources` alongside `:stock`. The plan's earlier
+ `PermissionConfiguration::DefaultCatalog.register` alongside `:stock`. The plan's earlier
`read_inventory` / `write_inventory` would have put "Stock" and "Inventory" side by side on the
roles screen with nothing to tell a merchant which is which. Transfers stay under `stock`, whose
subject list gains `Spree::StockTransferItem`.
@@ -264,7 +264,7 @@ for the columns; Medusa's inventory module (persisted `stocked`/`reserved`/`inco
held back (damaged, QC, safety stock). A true bucket is a fourth counter with its own adjust
action and reason vocabulary; no reference validates it yet, so it is a separate plan item.
Rejections are surfaced where they live — on the purchase order and the receipt.
-- **Dashboard only.** The `stock` permission already carries `audiences: %i[seller]`; the seller
+- **Dashboard only.** The `stock` permission already carries `audiences: %i[store seller]`; the seller
panel gets the same table under a forced seller scope as a follow-up, per the
dashboard-is-the-reference rule. The counters and the endpoint are shared, so that follow-up is
a route and a scope, not a second implementation.
diff --git a/docs/plans/6.0-multi-vendor-marketplace.md b/docs/plans/6.0-multi-vendor-marketplace.md
index 688c63ad91..5b3625f275 100644
--- a/docs/plans/6.0-multi-vendor-marketplace.md
+++ b/docs/plans/6.0-multi-vendor-marketplace.md
@@ -352,7 +352,7 @@ end
- **Teams** = `Spree::RoleUser` rows with `resource: seller` and `user: Spree.admin_user_class`. Seller admins invite teammates through the same `Invitation` rail the store admin uses. No new membership model.
- **Authorization** (rewritten 2026-08-15 for the shipped RBAC — Decision 10): seller users are `Spree.admin_user_class` and sign in through the seller login surface (own strategy registry, own `seller_api` JWT audience). Authorization on the Seller API branch is the same two-axis model the admin branch uses:
- *Tenancy* is controller scoping — every seller endpoint scope-fetches through `current_seller` (resolved from `X-Spree-Seller-Id` + a `role_users` membership check on `resource: seller`; `current_store` is **derived** from `current_seller.store`, never taken from a header). Writes are force-stamped `seller_id`. Nothing tenancy-related lives in the ability.
- - *Capability* is the permission catalog — the same `read_*`/`write_*` vocabulary, through the same `ScopedAuthorization` key gate. Adopts the RBAC plan's settled direction: `Role#audience` (`staff` | `seller`); a **seller-grantable catalog subset** marked at `register_resource` (products, orders, fulfillments, stock, returns, exports/imports, analytics — never `settings`, `staff`, `api_keys`, commissions); the roles editor filters its grid by audience; assignment and invitation guards pair audience with resource type. Seller roles are defined by the operator (role names are globally unique — sellers assign their people to tiers, they do not define roles). Two seller-only catalog resources: `seller_profile` (own profile, branding, addresses, onboarding tasks) and read-only `payouts` (the seller's ledger view). `Spree::Ability` gains a `resource:` option (default the store) so the seller branch builds its ability from `role_users` where `resource: current_seller` — the "seller-side ability" the RBAC plan deferred here.
+ - *Capability* is the permission catalog — the same `read_*`/`write_*` vocabulary, through the same `ScopedAuthorization` key gate. Adopts the RBAC plan's settled direction: `Role#audience` (`staff` | `seller`); a **seller-grantable catalog subset** marked at `register_scope` (products, orders, fulfillments, stock, returns, exports/imports, analytics — never `settings`, `staff`, `api_keys`, commissions); the roles editor filters its grid by audience; assignment and invitation guards pair audience with resource type. Seller roles are defined by the operator (role names are globally unique — sellers assign their people to tiers, they do not define roles). Two seller-only catalog resources: `seller_profile` (own profile, branding, addresses, onboarding tasks) and read-only `payouts` (the seller's ledger view). `Spree::Ability` gains a `resource:` option (default the store) so the seller branch builds its ability from `role_users` where `resource: current_seller` — the "seller-side ability" the RBAC plan deferred here.
- The legacy `PermissionSets::SellerUser` baseline survives only as the **seeded default seller role's key set** (`write_products`, `write_orders`, `write_fulfillments`, `write_stock`, `write_returns`, `write_exports`, `write_seller_profile`, `read_payouts`). "No commission management / no channel publication / no self-approve / no stock-location create" are endpoints that do not exist on the seller branch, not ability rules. `#13323`'s "manage permissions (via code)" = seeds or the roles API, per the RBAC plan.
- `Spree::UserRoles` gains `has_many :sellers, through: :role_users, source: :resource, source_type: 'Spree::Seller'` beside `stores`; the seller branch's `/me` returns the seller memberships so a panel can pick its context. `AdminUserMethods#can_be_deleted?` reasons about `Store.current.users` — the seller branch needs its own "last owner of this seller" rule.
- **Onboarding checklist — superseded 2026-08-18 by `6.0-seller-onboarding-requirements.md`.** The "lightweight task registry" below became an operator-configured model (`Spree::SellerRequirement` rows over registered kinds, persisted `SellerRequirementSubmission` for attested/verified checks, `Sellers::SubmitForReview` + `Approve` as the only gates); the paragraph is kept for the intent it records. Original text: **Onboarding checklist — the registry is core, Enterprise contributes tasks.** Core ships a lightweight task registry (task key + completion check + required flag) and the core tasks: accept ToS, complete profile/branding, billing + returns addresses, at least one delivery method, at least one product. `submit_for_review` requires all required tasks complete (ports the legacy `onboarding_completed?` guard — without a checklist the guard has nothing to check, and sellers can't see what's missing). Extensions **register additional tasks** into the same registry: the monorepo Stripe gateway adds "connect your Stripe account" (Express onboarding); Enterprise adds KYC verification follow-through and Shopify/Woo store connection — the paid value is in *those tasks*, not in the tracker. The seller dashboard and the operator's onboarding-progress view (the n/m column in today's Enterprise) both render from the registry.
@@ -749,7 +749,7 @@ This is **new OSS code**, not a rename of existing core — there is no in-place
- Migrate the legacy Stripe transfer ledger → `spree_seller_transfers` (the per-order, on-fulfillment level) with `provider: 'stripe_connect'` and the Stripe transfer id in `reference`. The legacy module has no payout *records* (it delegated scheduling to Stripe), so there is nothing to backfill into `spree_seller_payouts` — historical Stripe payouts can optionally be reconstructed from Stripe's API, or simply start fresh from the cutover.
The Enterprise module then becomes a thin layer on top of core's new models, deleting its splitting + commission + transfer decorators. The basic `Spree::PayoutProvider::StripeConnect` ships in the monorepo with the pulled-in Stripe gateway (2026-07-15 amendment); Enterprise extends it (clawbacks, netting, KYC ops, reconciliation) and keeps Shopify/WooCommerce.
2. **Build order** (each phase shippable):
- - **Phase 0 — admin-branch hardening (ships first, no Seller model needed). IMPLEMENTED 2026-08-16.** Tighten `AdminAuthentication#current_user_member_of_store?` to `resource_type: 'Spree::Store'` + regression spec; `spree_refresh_tokens.audience` written at mint and enforced on refresh (admin + store surfaces stamp their own); `Role#audience` + the audience marker on `register_resource` (Decision 10 / RBAC plan). **Shipped as:** `audience` on refresh tokens (nullable; `for_audience` scope narrowing every refresh **and** logout lookup on both surfaces — ending a session belongs to the surface that started it; legacy NULL-audience rows match no surface and are rejected on refresh, costing their holders one login) and on roles (`null: false`, backfilled `staff`, immutable after create, `Spree::Role::AUDIENCES` the vocabulary); the catalog takes `audiences:` naming the audiences **beyond staff** a resource opens up, with `grantable_keys(audience)` (unknown audience ⇒ empty, never raises) — a generalization of the originally-planned `seller_grantable` boolean, so a third panel needs no schema change (decisions.md 2026-08-16); `orders`/`fulfillments`/`products`/`stock`/`dashboard` opened to `seller`. **Roles became store-owned** (`spree_roles.store_id`, `null: false`, via `SingleStoreResource`): they were global reference data, so two stores could never each define a "Manager" and the marketplace would have inherited that. Names are unique per `(store, name, audience)` — `Spree::UniqueName`'s global uniqueness is deliberately not used on Role — so one store holds a staff "Manager" beside a seller "Manager", and another store holds its own. `admin` is now one immutable role **per store** (`default_admin_role(store)`; `Seeds::Roles` moved after `Seeds::Stores`, since a role cannot exist before its store). The upgrade fans every existing role out per store and re-points assignments and invitations at the copy for the store they already named, so no grant changes hands. The audience bound is enforced **twice**: `Spree::Role` validates it on write, and `Spree::Ability` re-filters through `grantable_keys(role.audience)` at activation, since a catalog that changes after the role was saved would otherwise leave stale keys live. The staff surface is closed to foreign-audience roles at both ends — `Admin::RolesController#scope` lists only `Spree::Role.staff`, and `RoleGrantGuard` rejects assigning a non-staff role to store staff (invitations + admin_users). `Spree::Ability` takes `resource:` (defaults to the store) and reads `role_users` on it — the `admin` super-role and the implicit-admin fallback apply **only** on a store resource, and the staff baseline narrows `read Spree::Store` to the one store a non-store panel operates under. **The ability answers capability, never tenancy:** a seller holding `write_orders` gets `can :manage, Spree::Order` on the model class exactly as an admin does; which records it may touch is `current_seller` scope-fetching in the controller, so a seller-branch controller that authorizes without scope-fetching reads store-wide.
+ - **Phase 0 — admin-branch hardening (ships first, no Seller model needed). IMPLEMENTED 2026-08-16.** Tighten `AdminAuthentication#current_user_member_of_store?` to `resource_type: 'Spree::Store'` + regression spec; `spree_refresh_tokens.audience` written at mint and enforced on refresh (admin + store surfaces stamp their own); `Role#audience` + the audience marker on `register_scope` (Decision 10 / RBAC plan). **Shipped as:** `audience` on refresh tokens (nullable; `for_audience` scope narrowing every refresh **and** logout lookup on both surfaces — ending a session belongs to the surface that started it; legacy NULL-audience rows match no surface and are rejected on refresh, costing their holders one login) and on roles (`null: false`, backfilled `staff`, immutable after create, `Spree::Role::AUDIENCES` the vocabulary); the catalog takes `audiences:` naming **every** audience a scope is grantable to — the store's own back office is `:store`, and the default when none is named, so a scope shared with sellers says `%i[store seller]` and one for sellers alone says `%i[seller]`, with `grantable_keys(audience)` (unknown audience ⇒ empty, never raises) — a generalization of the originally-planned `seller_grantable` boolean, so a third panel needs no schema change (decisions.md 2026-08-16); `orders`/`fulfillments`/`products`/`stock`/`dashboard` opened to `seller`. **Roles became store-owned** (`spree_roles.store_id`, `null: false`, via `SingleStoreResource`): they were global reference data, so two stores could never each define a "Manager" and the marketplace would have inherited that. Names are unique per `(store, name, audience)` — `Spree::UniqueName`'s global uniqueness is deliberately not used on Role — so one store holds a staff "Manager" beside a seller "Manager", and another store holds its own. `admin` is now one immutable role **per store** (`default_admin_role(store)`; `Seeds::Roles` moved after `Seeds::Stores`, since a role cannot exist before its store). The upgrade fans every existing role out per store and re-points assignments and invitations at the copy for the store they already named, so no grant changes hands. The audience bound is enforced **twice**: `Spree::Role` validates it on write, and `Spree::Ability` re-filters through `grantable_keys(role.audience)` at activation, since a catalog that changes after the role was saved would otherwise leave stale keys live. The staff surface is closed to foreign-audience roles at both ends — `Admin::RolesController#scope` lists only `Spree::Role.staff`, and `RoleGrantGuard` rejects assigning a non-staff role to store staff (invitations + admin_users). `Spree::Ability` takes `resource:` (defaults to the store) and reads `role_users` on it — the `admin` super-role and the implicit-admin fallback apply **only** on a store resource, and the staff baseline narrows `read Spree::Store` to the one store a non-store panel operates under. **The ability answers capability, never tenancy:** a seller holding `write_orders` gets `can :manage, Spree::Order` on the model class exactly as an admin does; which records it may touch is `current_seller` scope-fetching in the controller, so a seller-branch controller that authorizes without scope-fetching reads store-wide.
- **Phase 1 — Seller identity.** `Spree::Seller` model (see Seller identity & teams: lifecycle, branding, ToS acceptance, holiday mode), onboarding task registry + core tasks, seller teams via `RoleUser`/`Invitation` (`resource: seller`) + `UserRoles#sellers`, self-serve application endpoint, core `Spree::SellerMailer` lifecycle emails (see Seller notifications), product ownership (`products.seller_id` + approval preference), Admin API Marketplace/sellers endpoints + Store API seller profiles, seller CSV import/export on the `Spree::Import` pipeline. **Phase 1b — the shared catalog (Decision 11). IMPLEMENTED 2026-08-16:** `variants.seller_id` + `variants.delivery_profile_id`, condition as an OptionType, the ownership filter on `Product#variants=`, first-party `default_variant` priority, the same-variant fix to option filtering, and the buy-box selection service the product rollups then answer through — see the Resolved Decisions entry for what shipped. Sequenced here rather than later because the split's partition key (Phase 3) and the commission line's identity (Phase 2) both read the seller off a line item, and on a shared product only the variant can answer. **The Seller API branch anchor** (`Seller::BaseController`/`ResourceController`, `seller_api` audience, `Spree.seller_authentication_strategies`, `/seller/auth/*`, `/seller/me`, `/seller/profile`, onboarding, team, seller-scope guard, `Spree::Ability` `resource:` option) + the seeded default seller role. Products/orders/fulfillments on the seller branch follow as each domain lands (products in Phase 1, orders/fulfillments/ledger reads in Phase 3). No splitting yet.
- **Phase 2 — Commission engine.** `CommissionRate` + `CommissionRule` + `CommissionLine`, resolution + calculation services (dimension-grouped matching, min/max clamps, `include_shipping`), commission-tax field, admin UI for rates. Compute-only (attach to single-seller orders, no split).
- **Phase 3 — Order splitting. IMPLEMENTED 2026-08-20** (the fund ledger follows as Phase 3a). `Spree::OrderGroup` + `Spree::PaymentSplit`, the split as named steps inside `Carts::Complete` (`Carts::PartitionBySeller` → `Carts::SplitBySeller` → `OrderGroups::AllocatePayments`), derived group status, per-child refund attribution. **What shipped and why it took the shape it did:** the split runs in FINALIZE, after payment, and **adopts the paid draft order as the group's first child** rather than building N fresh orders and discarding it — that order is what the payment was taken against and what carries the unique `cart_id` replay anchor, so destroying it would orphan money and break resumption; the remaining partitions become siblings and the rows are **moved, never re-copied** (every line item, fulfillment and typed money row was costed once inside the completion lock — re-deriving would ask the pricing and tax engines a question already answered). The group takes the order's number and children suffix off it (`R1001-1`, `R1001-2`), so a customer keeps the reference they saw at checkout. `completion_result` is now `cart.order_group || cart.order` and the workflow returns whichever exists. **A parcel split between sellers divides its delivery cost** by the value each half carries (largest-remainder) — cloning the fulfillment kept the full cost on both halves and charged the customer twice, caught by a totals spec; order-level fees prorate the same way with their tax lines following. Per-seller commission needed **no commission-engine change at all**: each child publishes its own `order.placed`, which `OrderCommissionSubscriber` already answers, and the service already skips nil-seller lines so the first-party child is correctly uncommissioned. **Payments moved up to the group** (`payments.order_group_id`, `order_id` nil; `Payment#owner` extended, `exactly_one_owner` now three-way) with one `PaymentSplit` per (payment, child) prorated by child totals — so a mixed store-credit checkout never overstates gateway exposure on one seller's order. Consequences that had to ship with it: `Orders::UpdateStatuses` reads a grouped child's money from its splits rather than `order.payments` (which is empty there); capture-on-dispatch draws from the group's payments **bounded by that child's remaining share**, so the first seller to ship cannot capture the whole basket; `spree_refunds.order_id` names which child a refund puts right (`Refund#order` falls back to the payment, `Order#refunds` resolves either shape) and `PaymentSplitRefundSubscriber` recomputes only that child's `refunded_amount`; `Spree::OrderGroup` answers the payment-owner contract (`payment_total`, store credits, addresses via `Purchase::Addresses`) and counts as a purchase in `Storefront::AccessPolicy` so a guest can see what they bought. API: the Store completion response returns the group with orders nested (the customer sees **one purchase**, not three), the gateway-race retry resolves a group id, and read-only `GET /admin/order_groups` ships with `OrderGroup`/`PaymentSplit` added to the `orders`/`payments` catalog subjects.
@@ -774,7 +774,7 @@ Even before this lands, work touching adjacent areas should:
- **Order routing (`6.0-order-routing.md`)**: the per-child stock-location decision must come from the routing strategy, so a seller's items allocate from that seller's stock location. Keep `for_allocation` seller-aware-friendly (it already takes `order:`).
- **Tax provider (`6.0-tax-provider.md`)** and **Delivery rate provider (`6.0-delivery-rate-provider.md`)**: the `PayoutProvider` follows the same pluggable-strategy shape — keep the provider-registration convention consistent so all three (tax, delivery rate, payout) register and resolve the same way.
- **Admin API (`6.0-admin-api.md`)**: the `Seller` prefix is `sel_`. The "Marketplace (new in 6.0)" endpoint group there is the *operator's* API surface — keep it in sync. Seller users never call the Admin API (Decision 10).
-- **Auth + RBAC (`6.0-platform-auth.md`, `6.0-admin-rbac.md`)**: no third principal — never add a `SellerUser`/`Spree.seller_user_class`; seller staff are `Spree.admin_user_class`. Never derive back-office membership from `store_id` alone — match `RoleUser.resource_type` (`Ability#staff_roles` and `RoleGrantGuard` already do; the membership check must follow). New login surfaces get their own strategy registry and JWT audience; refresh tokens must carry the audience they were minted for. Catalog resources that sellers may hold must be marked seller-grantable at `register_resource`; `settings`/`staff`/`api_keys` never are. Seller-branch controllers scope-fetch through `current_seller` and never subclass admin controllers.
+- **Auth + RBAC (`6.0-platform-auth.md`, `6.0-admin-rbac.md`)**: no third principal — never add a `SellerUser`/`Spree.seller_user_class`; seller staff are `Spree.admin_user_class`. Never derive back-office membership from `store_id` alone — match `RoleUser.resource_type` (`Ability#staff_roles` and `RoleGrantGuard` already do; the membership check must follow). New login surfaces get their own strategy registry and JWT audience; refresh tokens must carry the audience they were minted for. Catalog resources that sellers may hold must be marked seller-grantable at `register_scope`; `settings`/`staff`/`api_keys` never are. Seller-branch controllers scope-fetch through `current_seller` and never subclass admin controllers.
- **Seller addresses (Decision 12)**: do not add a `returns_address` back, and do not give a seller a tax *rate* column — identity (`legal_name`, `registration_number`, a `TaxIdentifier`) is the seller's, the rate is `CommissionRate` + `TaxProvider`. A billing address is a `Spree::BusinessAddress` (table-sharing subclass, never STI — before proposing a `type` column again, read decisions.md 2026-08-23: `update_or_create_address` and `find_existing_address` are what decide it). Code reading a seller's returns destination goes through `Seller#returns_location`, never a stored address FK. `StockLocation` name-uniqueness and its `default` flag are per-owner, so new code must not assume one default per store.
- Do **not** revive the legacy commission model's shape (label-based rows + denormalized fee totals on the order), do **not** model commission as a polymorphic `Adjustment`, and do **not** write commission as a `Spree::Fee` (fees are buyer-facing and roll into order totals — Decision 2) — 6.0 uses the off-order `Spree::CommissionLine` ledger. Do **not** put the fund ledger in a payment-gateway namespace (the legacy gateway-namespaced-transfer mistake) nor collapse transfer and payout into one model — `Spree::SellerTransfer` (on-fulfillment) and `Spree::SellerPayout` (scheduled) are both core and provider-agnostic.
@@ -805,7 +805,7 @@ Even before this lands, work touching adjacent areas should:
- **The seller panel is its own app and its own SDK** (RESOLVED 2026-08-17). `@spree/seller-sdk` beside `@spree/sdk` and `@spree/admin-sdk`, and `packages/seller-dashboard` (shell) + `packages/seller-dashboard-starter` (host) beside their dashboard counterparts — not a mode of the admin app. The credentials differ in kind, not degree: a seller JWT only (no secret-key equivalent exists), `X-Spree-Seller-Id` rather than `X-Spree-Store-Id` (the store is derived from the seller), and a refresh cookie whose name and path are deliberately not shared. Typing those as optional-but-meaningless on one client is how a panel ends up able to call the wrong API.
**`@spree/dashboard-core` generalizes rather than forks**: it exported an `adminClient` singleton built from `createAdminClient`, so any host reusing the framework got the Admin API — the one thing Decision 10 forbids. Core now takes a registered client (`setApiClient`/`getApiClient`) that each host installs at boot; `adminClient` survives as a deprecated alias. Two further admin assumptions came out with it: the Tailwind source list hardcoded `@spree/dashboard` (so a second panel's own components were never scanned) and the store switcher built a typed `/$storeId` link that cannot compile against a router without that route. `@spree/dashboard-ui` is already headless and needed no change. One framework, two hosts — a fork would mean every registry and provider fix landing twice.
- **The storefront sees a seller's profile, never their operational state** (RESOLVED 2026-08-16, shipped). `Spree::Api::V3::SellerSerializer` carries `name`, `slug`, `about`/`about_html` and the three image URLs — and nothing else. `status` and `sellable` are excluded on purpose (a seller a shopper can reach is sellable by definition), along with settlement/tax configuration, contact and billing addresses, team size and every timestamp; a spec asserts the exact key set so nothing leaks in later. The admin serializer extends this one rather than duplicating it, per the house rule. Store endpoints are read-only `index`/`show` scoped to `sellable` — a seller onboarding, suspended or away is neither listed nor fetchable (404), since listing them would advertise products nobody can buy — and resolve by slug or prefixed id so a storefront can route `/sellers/<slug>`. Products expose `seller_id` on **both** APIs without an expand (so a storefront can group or link by seller cheaply) plus `one :seller` behind `?expand=seller`; the admin serializer additionally carries `seller_name` for its list column. `Spree::Product` gains `seller_id` and `seller` to its ransack allowlists — without them the products-table filter silently matches nothing.
-- **Seller management is staff-only, on its own catalog resource** (RESOLVED 2026-08-16, shipped). `register_resource(:sellers, …)` mints `read_sellers`/`write_sellers` with `Spree::Seller` as its subject, and is deliberately not offered to the `seller` audience — a seller administering other sellers is the one thing the seller key must never allow. `seller_profile` (the seller's own record, on the seller branch) therefore claims no subject, so the subject→resource lookup stays unambiguous.
+- **Seller management is staff-only, on its own catalog scope** (RESOLVED 2026-08-16, shipped). `register_scope(:sellers, …)` mints `read_sellers`/`write_sellers` with `Spree::Seller` as its resource, and is deliberately not offered to the `seller` audience — a seller administering other sellers is the one thing the seller key must never allow. `seller_profile` (the seller's own record, on the seller branch) therefore claims no subject, so the subject→resource lookup stays unambiguous.
- **Seller principal → `Spree::AdminUser` (`Spree.admin_user_class`), no `SellerUser` model** (RESOLVED 2026-08-15). Reuse the whole shipped auth stack and the RBAC rails (`RoleUser`/`Invitation` on `resource: seller`); membership is by resource type, never `store_id`. Isolation guaranteed at the token layer: own `seller_api` JWT audience, own `Spree.seller_authentication_strategies` + `/seller/auth/*` (so staff can be SSO-only while sellers use passwords; the seller login refuses non-members), `spree_refresh_tokens.audience`. See Decision 10 + `decisions.md` 2026-08-15.
- **Seller API → dedicated `/api/v3/seller` branch, `current_seller` scope-fetching; sellers never call the Admin API** (RESOLVED 2026-08-15). Supersedes the 2026-07-14 "seller users hit the same admin API with seller-scoped abilities" wording — permission sets with tenancy conditions no longer exist (RBAC, PR #14412), and the RBAC plan's 2026-08-08 direction already named `current_seller` endpoints. Own serializer branch off the store serializers, own OpenAPI spec, no subclassing of admin controllers. See Decision 10.
- **Store credit / gift cards split across child orders → group-level payments, prorated through `PaymentSplit` like any other payment** (RESOLVED 2026-08-15). A store-credit or gift-card payment is a `Payment` on the `OrderGroup` exactly like the gateway payment; every group payment gets one `PaymentSplit` row per child order, prorated by child totals with the same largest-remainder rule as order-level discounts. One attribution rule for every payment source, no priority ordering, no special-casing — and it composes with the resolved payment-source-agnostic transfer basis (the seller's earning never depends on how the buyer paid). Confirmed against the shipped `Carts::Complete` pipeline (payments attach before the split runs).
diff --git a/docs/plans/6.0-seller-ledger-ui.md b/docs/plans/6.0-seller-ledger-ui.md
index 7fc765543a..610a73ed73 100644
--- a/docs/plans/6.0-seller-ledger-ui.md
+++ b/docs/plans/6.0-seller-ledger-ui.md
@@ -23,11 +23,11 @@ An order placed with a single seller does not split and has no `PaymentSplit` ro
`Spree::SellerTransfer` and `Spree::SellerPayout` are subjects of the operator's `payouts` resource, which is closed to the seller audience by design (the catalog comment: a seller reads their own earnings through their own branch, scope-fetched, never through a key that could reach the whole ledger). The seller branch therefore gates its balance, transfer and payout endpoints on a new catalog resource:
```ruby
-register_resource(:seller_earnings, group: :access, subjects: -> { [:seller_earnings] },
+register_scope(:seller_earnings, group: :seller, resources: -> { [:seller_earnings] },
write: false, audiences: %i[seller])
```
-A symbol subject, exactly like `seller_profile` and for the same reason: the model classes belong to `payouts`, and claiming them twice would make `resource_for_subject` answer by registration order. Controllers declare `scoped_resource :seller_earnings` and override `authorize_resource!` to authorize the symbol (the `PoliciesController` pattern); which rows a seller may read is `current_seller` scope-fetching, never an ability rule.
+A symbol resource, exactly like `seller_profile` and for the same reason: the model classes belong to `payouts`, and claiming them twice would make `scope_for_resource` answer by registration order. Controllers declare `scoped_resource :seller_earnings` and override `authorize_resource!` to authorize the symbol (the `PoliciesController` pattern); which rows a seller may read is `current_seller` scope-fetching, never an ability rule.
Chosen over reusing `seller_profile` because a seller's owner must be able to give a packing teammate orders and fulfilments without showing them the money — settlement configuration is profile, but the ledger is the seller's books. A seller admin role is born with `grantable_keys(:seller)` at creation, so every seller created from here on holds the key; sellers are new in 6.0 and nothing older needs catching up, so there is no backfill (2026-09-09). A development database seeded before this key needs its seller role re-created or the key added by hand.
diff --git a/docs/plans/6.0-seller-order-management.md b/docs/plans/6.0-seller-order-management.md
index 37a526a3b5..eaaade40d6 100644
--- a/docs/plans/6.0-seller-order-management.md
+++ b/docs/plans/6.0-seller-order-management.md
@@ -88,7 +88,7 @@ The workflows are shared unchanged — `Spree.return_*_workflow`, `Spree.claim_*
### 6. No new permission keys
-`Spree::Return`, `Spree::Exchange` and `Spree::Claim` are already subjects of the `orders` catalog resource, and `orders` is already `audiences: %i[seller]`. So `read_orders`/`write_orders` gate all of this, and the seeded default seller role (which holds `write_orders`) needs no change. `Spree::Refund` is a subject of the separate `refunds` resource, which is **not** seller-grantable — but a seller refunds *through* `Returns::Refund` on their own return, not through the refunds endpoint, so no key changes there either. Adding `refunds` to the seller audience would open `/admin`-shaped refund creation and is explicitly not part of this.
+`Spree::Return`, `Spree::Exchange` and `Spree::Claim` are already resources of the `orders` catalog scope, and `orders` is already `audiences: %i[store seller]`. So `read_orders`/`write_orders` gate all of this, and the seeded default seller role (which holds `write_orders`) needs no change. `Spree::Refund` is a subject of the separate `refunds` resource, which is **not** seller-grantable — but a seller refunds *through* `Returns::Refund` on their own return, not through the refunds endpoint, so no key changes there either. Adding `refunds` to the seller audience would open `/admin`-shaped refund creation and is explicitly not part of this.
### 7. Seller users are already the right principal
diff --git a/docs/plans/6.0-seller-package-types.md b/docs/plans/6.0-seller-package-types.md
index 494478af2a..93865e1a5d 100644
--- a/docs/plans/6.0-seller-package-types.md
+++ b/docs/plans/6.0-seller-package-types.md
@@ -184,7 +184,7 @@ unchanged.
### Permission
```ruby
-register_resource(:package_types, group: :settings, audiences: %i[seller], subjects: -> {
+register_scope(:package_types, group: :settings, audiences: %i[store seller], resources: -> {
[Spree::PackageType]
})
```
diff --git a/docs/plans/6.0-seller-product-submission.md b/docs/plans/6.0-seller-product-submission.md
index 56bb6031ec..4fb7a7a59c 100644
--- a/docs/plans/6.0-seller-product-submission.md
+++ b/docs/plans/6.0-seller-product-submission.md
@@ -253,12 +253,12 @@ Admin branch:
### Permissions
```ruby
-register_resource(:product_types, group: :catalog, write: false,
- audiences: %i[seller],
- subjects: -> { [Spree::ProductType] })
+register_scope(:product_types, group: :catalog,
+ audiences: %i[store seller], read_only_for: %i[seller],
+ resources: -> { [Spree::ProductType] })
-register_resource(:publishing, group: :catalog,
- subjects: -> { [Spree::ProductPublication] })
+register_scope(:publishing, group: :catalog,
+ resources: -> { [Spree::ProductPublication] })
```
`Spree::ProductType` and `Spree::ProductPublication` leave the `products`
diff --git a/docs/plans/decisions.md b/docs/plans/decisions.md
index ef62cf580f..79b380607e 100644
--- a/docs/plans/decisions.md
+++ b/docs/plans/decisions.md
@@ -148,7 +148,7 @@ appearing twice in the admin;
**Suppliers and purchase orders are one new catalog resource, `:purchasing`**
(`read_purchasing` / `write_purchasing`), registered beside `:stock` in
-`PermissionConfiguration#register_default_resources`. The plan's earlier
+`PermissionConfiguration::DefaultCatalog.register`. The plan's earlier
`read_inventory` / `write_inventory` would have put "Stock" and "Inventory"
side by side on the roles screen with nothing to tell a merchant which covers
what. `Spree::StockTransferItem` joins the existing `:stock` subject list.
@@ -3937,7 +3937,7 @@ match `resource_type: 'Spree::Store'` (today it matches `store_id`, which a
vendor-resourced assignment passes — scope-exempt admin endpoints such as
`/admin/tags` and `/admin/store` would be reachable by a vendor-only user
once vendors exist); ship this ahead of the Vendor model. `Role#audience` and
-a vendor-grantable marker on `register_resource` come from the RBAC plan's
+a vendor-grantable marker on `register_scope` come from the RBAC plan's
settled direction. Never add a login surface without its own strategy
registry and JWT audience; refresh tokens carry the audience they were minted
for. Accepted trade-off: password policy and lockout stay shared between
@@ -5387,7 +5387,7 @@ books, and a seller's owner must be able to hand a packing teammate the orders
without also handing them the money. So a new read-only, seller-audience
catalog resource with a symbol subject — the ledger classes stay subjects of
the operator's `payouts` key, and claiming them twice would make
-`resource_for_subject` answer by registration order. The cost is real and was
+`scope_for_resource` answer by registration order. The cost is real and was
accepted knowingly: **a role holds the keys it was created with and is never
re-read**, so a key added to the catalog reaches new roles only. That is
harmless here because sellers are new in 6.0 and no older role exists — but a
diff --git a/docs/v5/developer/dashboard/customization/permissions.mdx b/docs/v5/developer/dashboard/customization/permissions.mdx
index fee1d3308e..dda59e0a74 100644
--- a/docs/v5/developer/dashboard/customization/permissions.mdx
+++ b/docs/v5/developer/dashboard/customization/permissions.mdx
@@ -104,7 +104,7 @@ The same `permissions` object backs the nav registry's `if` predicate, so you ca
## Custom permissions
-If your customization introduces a new model on the backend, register it as a permission catalog resource there (`Spree.permissions.register_resource` in your engine's initializer). Its keys then appear in the role editor and the API-key scope picker, and any role granted them makes `permissions.can('read', 'MyApp::Report')` resolve in the dashboard exactly like a first-party check — the abilities ship with the current-user response (`GET /api/v3/admin/me`) at sign-in, alongside `permission_keys`, the flat key list the role editor grants from.
+If your customization introduces a new model on the backend, register it as a permission catalog scope there (`Spree.permissions.register_scope` in your engine's initializer). Its keys then appear in the role editor and the API-key scope picker, and any role granted them makes `permissions.can('read', 'MyApp::Report')` resolve in the dashboard exactly like a first-party check — the abilities ship with the current-user response (`GET /api/v3/admin/me`) at sign-in, alongside `permission_keys`, the flat key list the role editor grants from.
## Reference
diff --git a/docs/v5/developer/upgrades/5.6-to-6.0.mdx b/docs/v5/developer/upgrades/5.6-to-6.0.mdx
index 4e4fb9ecaa..39b8f7a60d 100644
--- a/docs/v5/developer/upgrades/5.6-to-6.0.mdx
+++ b/docs/v5/developer/upgrades/5.6-to-6.0.mdx
@@ -614,7 +614,7 @@ Spree::Role.find_or_create_by!(name: 'support')
Storefront customers are not part of this system: the old `:default` role and `DefaultCustomer` set are gone, customers never resolve roles, and the Store API no longer consults CanCanCan at all — customer authorization is ownership-scoped queries plus `Spree::Storefront::AccessPolicy` (swappable via `Spree::Dependencies.storefront_access_policy_class`). If an extension added storefront `can` rules, move them into an access-policy subclass or a checkout workflow `validate` hook. Extensions register their resources into the catalog once, which makes them grantable to roles **and** mintable as API-key scopes:
```ruby
-Spree.permissions.register_resource(:reviews, group: :catalog, subjects: -> { [SpreeReviews::Review] })
+Spree.permissions.register_scope(:reviews, group: :catalog, resources: -> { [SpreeReviews::Review] })
```
Two enforcement changes on the Admin API:
diff --git a/packages/dashboard/e2e/roles.spec.ts b/packages/dashboard/e2e/roles.spec.ts
index 014a1e2d32..76828ae4c9 100644
--- a/packages/dashboard/e2e/roles.spec.ts
+++ b/packages/dashboard/e2e/roles.spec.ts
@@ -85,6 +85,37 @@ test.describe('roles', () => {
})
})
+ // The row opens the editor on click, so the overflow trigger has to swallow
+ // its own click — otherwise reaching for what is hidden opens the sheet
+ // instead. The tooltip's own appearance is left to the design system; what
+ // matters here is that asking for it is not a click on the row.
+ test('the overflow count does not open the editor', async ({ page }) => {
+ const creds = await login(page)
+ await gotoRoles(page, creds.store_id)
+
+ const name = `e2e-overflow-${Date.now()}`
+ await page.getByRole('button', { name: /add role/i }).click()
+ await sheet(page)
+ .getByRole('button', { name: /^order manager$/i })
+ .click()
+ await page.locator('#role-name').fill(name)
+ await sheet(page)
+ .getByRole('button', { name: /^save$/i })
+ .click()
+ await expect(sheet(page)).toHaveCount(0, { timeout: 15_000 })
+
+ // Order manager grants more than the row previews, so the count shows.
+ const row = page.getByRole('row').filter({ hasText: new RegExp(name, 'i') })
+ const more = row.getByRole('button', { name: /\+\d+ more/i })
+ await expect(more).toBeVisible()
+
+ await more.click()
+ await expect(sheet(page)).toHaveCount(0)
+
+ // Still on the list, with the row intact.
+ await expect(more).toBeVisible()
+ })
+
test('the admin role opens read-only', async ({ page }) => {
const creds = await login(page)
await gotoRoles(page, creds.store_id)
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index bc7b5410d0..e8f820e327 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -4113,10 +4113,11 @@
"analytics": "التحليلات",
"catalog": "الكتالوج",
"customers": "العملاء",
+ "loyalty": "الولاء",
"marketing": "التسويق",
"orders": "الطلبات",
- "settings": "الإعدادات",
- "loyalty": "الولاء"
+ "sellers": "البائعون",
+ "settings": "الإعدادات"
},
"labels": {
"read": "عرض {{resource}}",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index 869d296d60..b32215f200 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -4088,10 +4088,11 @@
"analytics": "Analysen",
"catalog": "Katalog",
"customers": "Kunden",
+ "loyalty": "Treue",
"marketing": "Marketing",
"orders": "Bestellungen",
- "settings": "Einstellungen",
- "loyalty": "Treue"
+ "sellers": "Verkäufer",
+ "settings": "Einstellungen"
},
"labels": {
"read": "{{resource}} ansehen",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index 5c6dd34e25..34d355b5eb 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -4088,10 +4088,11 @@
"analytics": "Analytics",
"catalog": "Catalog",
"customers": "Customers",
+ "loyalty": "Loyalty",
"marketing": "Marketing",
"orders": "Orders",
- "settings": "Settings",
- "loyalty": "Loyalty"
+ "sellers": "Sellers",
+ "settings": "Settings"
},
"labels": {
"read": "View {{resource}}",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index abea386e7b..42eeb49ab6 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -4088,10 +4088,11 @@
"analytics": "Analyses",
"catalog": "Catalogue",
"customers": "Clients",
+ "loyalty": "Fidélité",
"marketing": "Marketing",
"orders": "Commandes",
- "settings": "Paramètres",
- "loyalty": "Fidélité"
+ "sellers": "Vendeurs",
+ "settings": "Paramètres"
},
"labels": {
"read": "Voir {{resource}}",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index d10c798930..7e86ad0869 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -4140,10 +4140,11 @@
"analytics": "Analityka",
"catalog": "Katalog",
"customers": "Klienci",
+ "loyalty": "Lojalność",
"marketing": "Marketing",
"orders": "Zamówienia",
- "settings": "Ustawienia",
- "loyalty": "Lojalność"
+ "sellers": "Sprzedawcy",
+ "settings": "Ustawienia"
},
"labels": {
"read": "Podgląd: {{resource}}",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index 0c3a456673..212e52ce4a 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -4078,10 +4078,11 @@
"analytics": "分析",
"catalog": "商品目录",
"customers": "客户",
+ "loyalty": "会员权益",
"marketing": "营销",
"orders": "订单",
- "settings": "设置",
- "loyalty": "会员权益"
+ "sellers": "卖家",
+ "settings": "设置"
},
"labels": {
"read": "查看{{resource}}",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles.tsx
index 5975f23e29..94897d724b 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/roles.tsx
@@ -18,6 +18,9 @@ import {
TableHead,
TableHeader,
TableRow,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
toastManager,
useConfirm,
} from '@spree/dashboard-ui'
@@ -237,14 +240,36 @@ function PermissionSummary({ role }: { role: Role }) {
return (
<div className="flex flex-wrap items-center gap-1">
{preview.map((key) => (
- <Badge key={key} variant="secondary">
+ <Badge key={key} variant="outline">
{permissionKeyLabel(t, catalog?.data, key)}
</Badge>
))}
{overflow > 0 && (
- <span className="text-xs text-muted-foreground">
- {t('admin.roles.badges.more', { count: overflow })}
- </span>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ {/* Focusable and named: the rest of the list opens on focus as
+ well as hover, so it is not pointer-only. The row itself opens
+ the editor on click, so reading what is hidden must not count
+ as clicking the row — by pointer or by keyboard. */}
+ <button
+ type="button"
+ onClick={(event) => event.stopPropagation()}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter' || event.key === ' ') event.stopPropagation()
+ }}
+ className="cursor-help rounded-sm text-xs text-muted-foreground focus-visible:outline-2 focus-visible:outline-ring focus-visible:outline-offset-2"
+ >
+ {t('admin.roles.badges.more', { count: overflow })}
+ </button>
+ </TooltipTrigger>
+ <TooltipContent className="max-w-xs">
+ <ul>
+ {role.permissions.slice(PERMISSION_PREVIEW_COUNT).map((key) => (
+ <li key={key}>{permissionKeyLabel(t, catalog?.data, key)}</li>
+ ))}
+ </ul>
+ </TooltipContent>
+ </Tooltip>
)}
</div>
)
diff --git a/spree/api/app/controllers/spree/api/v3/admin/permissions_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/permissions_controller.rb
index f16dcb0ec3..817648f42c 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/permissions_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/permissions_controller.rb
@@ -6,6 +6,11 @@ module Spree
# editor and the API-key scope picker render. It is vocabulary, not
# data, so any authenticated admin credential may read it (same class
# of exemption as `/tags`).
+ #
+ # Staff keys only. Both surfaces this feeds build something owned by
+ # the store — a store role, a secret key — and a key another audience
+ # holds (a seller's own profile or books) would render as an option
+ # that fails validation the moment it is picked.
class PermissionsController < Admin::BaseController
skip_scope_check!
diff --git a/spree/api/app/serializers/spree/api/v3/admin/permission_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/permission_serializer.rb
index 0e6586f24e..fa02e112e1 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/permission_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/permission_serializer.rb
@@ -15,22 +15,22 @@ module Spree
attributes :key
- attribute(:resource) { |entry| entry.resource.name.to_s }
+ attribute(:resource) { |entry| entry.scope.name.to_s }
attribute(:kind) { |entry| entry.kind.to_s }
- attribute(:group) { |entry| entry.resource.group.to_s }
+ attribute(:group) { |entry| entry.scope.group.to_s }
attribute(:group_label) do |entry|
- Spree.t("permissions_catalog.groups.#{entry.resource.group}",
- default: entry.resource.group.to_s.humanize)
+ Spree.t("permissions_catalog.groups.#{entry.scope.group}",
+ default: entry.scope.group.to_s.humanize)
end
attribute(:label) do |entry|
- Spree.t("permissions_catalog.resources.#{entry.resource.name}.label",
- default: entry.resource.name.to_s.humanize)
+ Spree.t("permissions_catalog.resources.#{entry.scope.name}.label",
+ default: entry.scope.name.to_s.humanize)
end
attribute(:description) do |entry|
- Spree.t("permissions_catalog.resources.#{entry.resource.name}.description", default: '')
+ Spree.t("permissions_catalog.resources.#{entry.scope.name}.description", default: '')
end
end
end
diff --git a/spree/api/app/serializers/spree/api/v3/admin/role_serializer.rb b/spree/api/app/serializers/spree/api/v3/admin/role_serializer.rb
index 38dff7069b..d8301238e3 100644
--- a/spree/api/app/serializers/spree/api/v3/admin/role_serializer.rb
+++ b/spree/api/app/serializers/spree/api/v3/admin/role_serializer.rb
@@ -14,8 +14,11 @@ module Spree
attributes :name, :description, created_at: :iso8601, updated_at: :iso8601
+ # The admin role ignores its stored list and grants everything — so
+ # it reports every key its own audience may hold, which is what the
+ # role grid renders and what a duplicate of it copies.
attribute(:permissions) do |role|
- role.name == Spree::Role::ADMIN_ROLE ? Spree.permissions.catalog_keys : role.permissions
+ role.name == Spree::Role::ADMIN_ROLE ? Spree.permissions.grantable_keys(role.audience) : role.permissions
end
attribute(:mutable, &:mutable?)
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/admin_users_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/admin_users_controller_spec.rb
index 394c6712ee..263dee0d5a 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/admin_users_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/admin_users_controller_spec.rb
@@ -100,7 +100,7 @@ RSpec.describe Spree::Api::V3::Admin::AdminUsersController, type: :controller do
end
it 'forbids assigning a role whose permissions exceed its own' do
- owner_role = create(:role, name: 'owner', permissions: Spree.permissions.catalog_keys)
+ owner_role = create(:role, name: 'owner', permissions: Spree.permissions.grantable_keys(:store))
patch :update, params: { id: target.prefixed_id, role_ids: [owner_role.prefixed_id] }, as: :json
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/invitations_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/invitations_controller_spec.rb
index 8a723414ed..3257ae515e 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/invitations_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/invitations_controller_spec.rb
@@ -54,7 +54,7 @@ RSpec.describe Spree::Api::V3::Admin::InvitationsController, type: :controller d
end
it 'forbids inviting into a role whose permissions exceed its own' do
- owner_role = create(:role, name: 'owner', permissions: Spree.permissions.catalog_keys)
+ owner_role = create(:role, name: 'owner', permissions: Spree.permissions.grantable_keys(:store))
expect {
post :create, params: { email: '[email protected]', role_id: owner_role.prefixed_id }, as: :json
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/me_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/me_controller_spec.rb
index 572ea9584b..093011ca7a 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/me_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/me_controller_spec.rb
@@ -68,7 +68,7 @@ RSpec.describe Spree::Api::V3::Admin::MeController, type: :controller do
it 'returns the full catalog as permission_keys for admin users' do
subject
- expect(json_response['permission_keys']).to eq(Spree.permissions.catalog_keys)
+ expect(json_response['permission_keys']).to eq(Spree.permissions.grantable_keys(:store))
end
context 'as a staffer with a limited role' do
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/permissions_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/permissions_controller_spec.rb
index dc63dd3bf5..4cc9a361be 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/permissions_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/permissions_controller_spec.rb
@@ -13,7 +13,18 @@ RSpec.describe Spree::Api::V3::Admin::PermissionsController, type: :controller d
expect(response).to have_http_status(:ok)
keys = json_response['data'].map { |entry| entry['key'] }
- expect(keys).to eq(Spree.permissions.catalog_keys)
+ expect(keys).to eq(Spree.permissions.grantable_keys(:store))
+ end
+
+ # Both surfaces this feeds build something the store owns — a store role,
+ # a secret key — and neither can hold another audience's keys, so offering
+ # them would only produce a role that refuses to save.
+ it 'omits the keys only another audience may hold' do
+ get :index, as: :json
+
+ keys = json_response['data'].map { |entry| entry['key'] }
+ expect(keys).not_to include('read_seller_profile', 'write_seller_profile', 'read_seller_earnings')
+ expect(keys).to include('read_sellers', 'read_payouts', 'read_commissions')
end
it 'describes each entry with resource, kind, group and labels' do
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/roles_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/roles_controller_spec.rb
index d4204f6208..5ea9f93e89 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/roles_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/roles_controller_spec.rb
@@ -41,7 +41,7 @@ RSpec.describe Spree::Api::V3::Admin::RolesController, type: :controller do
admin = json_response['data'].find { |r| r['name'] == 'admin' }
expect(admin['mutable']).to be false
- expect(admin['permissions']).to eq(Spree.permissions.catalog_keys)
+ expect(admin['permissions']).to eq(Spree.permissions.grantable_keys(:store))
end
end
@@ -89,8 +89,8 @@ RSpec.describe Spree::Api::V3::Admin::RolesController, type: :controller do
# A role owned by another resource (a marketplace seller) confers nothing
# in the store admin, so it must not widen what the caller may grant.
it 'ignores keys the caller holds only on a non-store resource' do
- Spree.permissions.register_resource(
- :products, group: :catalog, audiences: %i[dummy_model], subjects: -> { [Spree::Product] }
+ Spree.permissions.register_scope(
+ :products, group: :catalog, audiences: %i[dummy_model], resources: -> { [Spree::Product] }
)
create(:role_user, user: staffer,
role: create(:role, name: 'seller_catalog', permissions: %w[write_products],
diff --git a/spree/core/app/models/spree/ability.rb b/spree/core/app/models/spree/ability.rb
index b9f79d6f3c..6b633cadc0 100644
--- a/spree/core/app/models/spree/ability.rb
+++ b/spree/core/app/models/spree/ability.rb
@@ -102,14 +102,15 @@ module Spree
# catalog that changes after the role was saved would leave stale keys
# behind — the write-time check is a UX affordance, this is the boundary.
#
+ # The bound applies to staff too: the catalog holds resources only another
+ # audience can use, and a store role carrying one would otherwise be
+ # granted it here.
+ #
# @param roles [Array<Spree::Role>]
# @return [Array<String>]
def grantable_keys_for(roles)
roles.flat_map do |role|
- keys = Spree.permissions.expand_keys(role.permissions)
- next keys if role.staff?
-
- keys & Spree.permissions.grantable_keys(role.audience)
+ Spree.permissions.expand_keys(role.permissions) & Spree.permissions.grantable_keys(role.audience)
end.uniq
end
@@ -158,7 +159,10 @@ module Spree
# ability rules — see the Axis A/B split in docs/plans/decisions.md.
def activate_full_access
can :manage, :all
- @permission_keys = Spree.permissions.catalog_keys
+ # Everything a store's back office may hold — not the whole catalog,
+ # which also carries the keys that only mean something on another
+ # audience's panel.
+ @permission_keys = Spree.permissions.grantable_keys(Spree::PermissionConfiguration::STAFF_AUDIENCE)
end
# Reference data every staff member can read regardless of keys — address
diff --git a/spree/core/app/models/spree/api_key.rb b/spree/core/app/models/spree/api_key.rb
index e19eedc17d..c154bc5c3d 100644
--- a/spree/core/app/models/spree/api_key.rb
+++ b/spree/core/app/models/spree/api_key.rb
@@ -11,14 +11,19 @@ module Spree
# Convenience aliases expanded at check time (never stored expanded).
ALIAS_SCOPES = %w[read_all write_all].freeze
- # Admin API authorization scopes — the permission catalog keys plus the
- # aliases. Derived from the catalog so an extension registering a resource
- # (`Spree.permissions.register_resource`) makes its keys mintable on secret
+ # Admin API authorization scopes — the permission catalog keys a store's
+ # own back office may hold, plus the aliases. Derived from the catalog so
+ # an extension registering a resource
+ # (`Spree.permissions.register_scope`) makes its keys mintable on secret
# keys with no further wiring. See docs/plans/6.0-admin-rbac.md.
#
+ # Staff-grantable only: a secret key is issued against a store, so keys
+ # that exist for another audience (a seller's own profile or books) are
+ # not mintable on one.
+ #
# @return [Array<String>]
def self.known_scopes
- Spree.permissions.catalog_keys + ALIAS_SCOPES
+ Spree.permissions.grantable_keys(Spree::PermissionConfiguration::STAFF_AUDIENCE) + ALIAS_SCOPES
end
# Scopes are stored in a JSON column (jsonb on PostgreSQL, json elsewhere).
diff --git a/spree/core/app/models/spree/role.rb b/spree/core/app/models/spree/role.rb
index d50ac82f0d..04f7685597 100644
--- a/spree/core/app/models/spree/role.rb
+++ b/spree/core/app/models/spree/role.rb
@@ -153,11 +153,12 @@ module Spree
errors.add(:permissions, :role_permissions_unknown, message: Spree.t(:role_permissions_unknown, keys: unknown.join(', '))) if unknown.any?
end
- # A role outside the store's back office is bounded by the catalog: only
- # resources registered as grantable to its kind may appear on it, so
- # settings/staff/api_keys can never reach a seller, even from a seed.
+ # Every role is bounded by the catalog: only resources registered as
+ # grantable to its kind may appear on it, so settings/staff/api_keys can
+ # never reach a seller, and a seller's own keys can never reach a store
+ # role — even from a seed.
def permissions_must_be_grantable_for_resource
- return if staff? || resource_type.blank?
+ return if resource_type.blank?
ungrantable = permissions - Spree.permissions.grantable_keys(audience)
return if ungrantable.none?
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index e6a2a45149..3ce52023df 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -1453,6 +1453,8 @@ en:
loyalty: Loyalty
marketing: Marketing
orders: Orders
+ seller: Seller
+ sellers: Sellers
settings: Settings
kinds:
read: View
diff --git a/spree/core/lib/spree/core.rb b/spree/core/lib/spree/core.rb
index 24ddaa5484..8dc0cf58a4 100644
--- a/spree/core/lib/spree/core.rb
+++ b/spree/core/lib/spree/core.rb
@@ -780,8 +780,8 @@ module Spree
# secret API key scopes. Roles themselves are data (Spree::Role#permissions);
# code only registers the vocabulary.
#
- # @example Registering a resource from an extension
- # Spree.permissions.register_resource(:reviews, group: :catalog, subjects: -> {
+ # @example Registering a scope from an extension
+ # Spree.permissions.register_scope(:reviews, group: :catalog, resources: -> {
# [SpreeReviews::Review]
# })
#
diff --git a/spree/core/lib/spree/core/permission_configuration.rb b/spree/core/lib/spree/core/permission_configuration.rb
index 1fe1a73702..d825659b09 100644
--- a/spree/core/lib/spree/core/permission_configuration.rb
+++ b/spree/core/lib/spree/core/permission_configuration.rb
@@ -2,16 +2,21 @@
# and secret API keys (see docs/plans/6.0-admin-rbac.md).
#
# Code defines the vocabulary, data defines the roles: core and extensions
-# register *resources* here, and each registration yields the grantable
-# `read_<resource>` / `write_<resource>` keys. Roles store keys on their row
+# register *scopes* here, and each registration yields the grantable
+# `read_<scope>` / `write_<scope>` keys. Roles store keys on their row
# (`Spree::Role#permissions`); API keys store them as scopes
# (`Spree::ApiKey#scopes`). There is no code-managed role concept.
#
-# @example Registering a resource from an extension
-# Spree.permissions.register_resource(:reviews, group: :catalog, subjects: -> {
+# @example Registering a scope from an extension
+# Spree.permissions.register_scope(:reviews, group: :catalog, resources: -> {
# [SpreeReviews::Review]
# })
#
+
+require 'spree/core/permissions/scope'
+require 'spree/core/permissions/entry'
+require 'spree/core/permissions/default_catalog'
+
module Spree
class PermissionConfiguration
# Raised when a 5.x initializer still calls the removed permission-set API.
@@ -20,188 +25,112 @@ module Spree
READ_PREFIX = 'read_'.freeze
WRITE_PREFIX = 'write_'.freeze
- # A role's audience is its owning resource, lowercased — a role on a
+ # A role's audience is its owning record, lowercased — a role on a
# `Spree::Store` is `:store`, one on a `Spree::Seller` is `:seller` (see
# `Spree::Role#audience`).
#
- # The store's own back office is the baseline: every resource is grantable
- # there, so registrations name only the *additional* audiences they open up.
+ # The store's own back office is an audience like any other — the one a
+ # registration means when it names none.
STAFF_AUDIENCE = :store
- # A registered catalog resource. Yields one or two grantable keys and maps
- # them to the CanCanCan subjects they cover.
- class Resource
- attr_reader :name, :group
-
- # @param name [Symbol] resource identifier (`:orders`)
- # @param group [Symbol] UI grouping for the permission pickers
- # @param subjects [Proc, Array] CanCanCan subjects covered by this
- # resource; pass a lambda so model classes resolve lazily
- # @param write [Boolean] whether a `write_<name>` key exists
- # @param audiences [Array<Symbol>] the non-staff audiences whose roles may
- # hold this resource's keys
- def initialize(name:, group:, subjects:, write: true, audiences: [], read_only_for: [])
- @name = name.to_sym
- @group = group.to_sym
- @subjects = subjects
- @write = write
- @audiences = (Array(audiences).map(&:to_sym) | [STAFF_AUDIENCE]).freeze
- @read_only_for = Array(read_only_for).map(&:to_sym).freeze
- end
-
- # @return [Boolean]
- def write?
- @write
- end
-
- # @return [Array<Symbol>] every audience this resource is grantable to,
- # staff included
- def audiences
- @audiences
- end
-
- # @param audience [Symbol, String, nil]
- # @return [Boolean]
- def grantable_to?(audience)
- return false if audience.blank?
-
- @audiences.include?(audience.to_s.to_sym)
- end
-
- # @return [Array<Class, Symbol>]
- def subjects
- Array(@subjects.respond_to?(:call) ? @subjects.call : @subjects)
- end
-
- # @return [String]
- def read_key
- "#{READ_PREFIX}#{name}"
- end
-
- # @return [String, nil]
- def write_key
- "#{WRITE_PREFIX}#{name}" if write?
- end
-
- # @return [Array<String>] the grantable keys, read first
- def keys
- [read_key, write_key].compact
- end
-
- # The keys one audience may hold. A resource the operator writes can
- # still be read-only for somebody else — product types are the case:
- # staff define them, a seller only picks from them.
- #
- # @param audience [Symbol, String, nil]
- # @return [Array<String>]
- def keys_for(audience)
- return [read_key] if @read_only_for.include?(audience.to_s.to_sym)
-
- keys
- end
- end
-
def initialize
- @resources = {}
- register_default_resources
+ @scopes = {}
+ DefaultCatalog.register(self)
end
- # Registers a catalog resource, yielding its `read_<name>` (and, unless
+ # Registers a catalog scope, yielding its `read_<name>` (and, unless
# `write: false`, `write_<name>`) keys. Re-registering a name replaces it.
#
# @param name [Symbol, String]
# @param group [Symbol] UI group (`:orders`, `:catalog`, `:marketing`, `:loyalty`,
# `:customers`, `:settings`, `:access`, `:analytics` — or your own)
- # @param subjects [Proc, Array] CanCanCan subjects the keys grant
+ # @param resources [Proc, Array] CanCanCan resources the keys grant
# @param write [Boolean]
- # @param audiences [Array<Symbol>] the audiences beyond staff whose roles
- # may hold these keys (`%i[seller]`). Empty by default — opening a
- # resource to another audience exposes it to a principal outside the
- # store's own staff, so it is a deliberate act. Never open `settings`,
- # `staff` or `api_keys`.
- # @return [Resource]
- def register_resource(name, group:, subjects:, write: true, audiences: [], read_only_for: [])
- # `read_all` / `write_all` are the API-key wildcard aliases — a resource
+ # @param audiences [Array<Symbol>] every audience whose roles may hold
+ # these keys — the whole list, with the store's own back office as
+ # `:store`. Just the store by default. Naming another audience exposes
+ # the scope to a principal outside the store's own staff, so it is a
+ # deliberate act; a list without `:store` keeps it off the staff picker
+ # and off secret keys entirely. Never open `settings`, `staff` or
+ # `api_keys`.
+ # @return [Scope]
+ def register_scope(name, group:, resources:, write: true, audiences: [STAFF_AUDIENCE], read_only_for: [])
+ # `read_all` / `write_all` are the API-key wildcard aliases — a scope
# named `all` would silently mint keys that grant the whole catalog.
- raise ArgumentError, "the permission resource name 'all' is reserved" if name.to_s == 'all'
+ raise ArgumentError, "the permission scope name 'all' is reserved" if name.to_s == 'all'
- resource = Resource.new(
- name: name, group: group, subjects: subjects, write: write,
+ scope = Scope.new(
+ name: name, group: group, resources: resources, write: write,
audiences: audiences, read_only_for: read_only_for
)
- @resources[resource.name] = resource
+ @scopes[scope.name] = scope
end
# @param name [Symbol, String]
- # @return [Resource, nil]
- def unregister_resource(name)
- @resources.delete(name.to_sym)
+ # @return [Scope, nil]
+ def unregister_scope(name)
+ @scopes.delete(name.to_sym)
end
- # @return [Array<Resource>] in registration order (drives UI ordering)
- def resources
- @resources.values
+ # @return [Array<Scope>] in registration order (drives UI ordering)
+ def scopes
+ @scopes.values
end
# @param name [Symbol, String]
- # @return [Resource, nil]
- def resource(name)
- @resources[name.to_s.to_sym]
+ # @return [Scope, nil]
+ def scope(name)
+ @scopes[name.to_s.to_sym]
end
- # The catalog resource whose subjects cover the given model class —
+ # The catalog scope whose resources cover the given model class —
# matching by ancestry so subclasses (e.g. a Gateway under PaymentMethod)
- # resolve to their base subject's resource. Used to derive the required
+ # resolve to their base resource's scope. Used to derive the required
# permission for polymorphic endpoints (translations, custom fields).
#
# @param klass [Class]
- # @return [Resource, nil]
- def resource_for_subject(klass)
+ # @return [Scope, nil]
+ def scope_for_resource(klass)
return nil unless klass.is_a?(Class)
- resources.find do |candidate|
- candidate.subjects.any? { |subject| subject.is_a?(Class) && klass <= subject }
- end
- end
-
- # One grantable key with its kind and owning resource — the unit the
- # `/admin/permissions` discovery endpoint serializes.
- class Entry
- attr_reader :key, :kind, :resource
-
- def initialize(key:, kind:, resource:)
- @key = key
- @kind = kind
- @resource = resource
+ scopes.find do |candidate|
+ candidate.resources.any? { |resource| resource.is_a?(Class) && klass <= resource }
end
end
# @return [Array<String>] every grantable key, in registration order
def catalog_keys
- resources.flat_map(&:keys)
+ scopes.flat_map(&:keys)
end
- # Resources grantable to one audience. An unknown audience simply matches
+ # Scopes grantable to one audience. An unknown audience simply matches
# nothing, so a panel that does not exist yet reads as granting nothing
# rather than raising.
#
# @param audience [Symbol, String] `:store`, `:seller`, …
- # @return [Array<Resource>] in registration order
- def grantable_resources(audience)
- resources.select { |resource| resource.grantable_to?(audience) }
+ # @return [Array<Scope>] in registration order
+ def grantable_scopes(audience)
+ scopes.select { |scope| scope.grantable_to?(audience) }
end
# @param audience [Symbol, String]
# @return [Array<String>] every key that audience may hold, in catalog order
def grantable_keys(audience)
- grantable_resources(audience).flat_map { |resource| resource.keys_for(audience) }
+ grantable_scopes(audience).flat_map { |scope| scope.keys_for(audience) }
end
- # @return [Array<Entry>] every grantable key with metadata, in catalog order
- def entries
- resources.flat_map do |resource|
- resource.keys.map do |key|
- Entry.new(key: key, kind: key.start_with?(WRITE_PREFIX) ? :write : :read, resource: resource)
+ # The grantable keys one audience may hold, with the metadata a permission
+ # picker renders. Defaults to staff, which is what the Admin API's
+ # discovery endpoint serves: a store role can never usefully hold a
+ # seller's own keys, so offering them there is only a way to build a role
+ # that refuses to save.
+ #
+ # @param audience [Symbol, String]
+ # @return [Array<Entry>] in catalog order
+ def entries(audience: STAFF_AUDIENCE)
+ grantable_scopes(audience).flat_map do |scope|
+ scope.keys_for(audience).map do |key|
+ Entry.new(key: key, kind: key.start_with?(WRITE_PREFIX) ? :write : :read, scope: scope)
end
end
end
@@ -212,17 +141,17 @@ module Spree
!resolve_key(key).nil?
end
- # Resolves a key into its kind and resource.
+ # Resolves a key into its kind and scope.
#
# @param key [String, Symbol]
- # @return [Array(Symbol, Resource), nil] `[:read | :write, resource]`
+ # @return [Array(Symbol, Scope), nil] `[:read | :write, scope]`
def resolve_key(key)
key = key.to_s
if key.start_with?(WRITE_PREFIX)
- found = resource(key.delete_prefix(WRITE_PREFIX))
+ found = scope(key.delete_prefix(WRITE_PREFIX))
[:write, found] if found&.write?
elsif key.start_with?(READ_PREFIX)
- found = resource(key.delete_prefix(READ_PREFIX))
+ found = scope(key.delete_prefix(READ_PREFIX))
[:read, found] if found
end
end
@@ -237,11 +166,11 @@ module Spree
kind, found = resolve_key(key)
return false unless found
- found.subjects.each do |subject|
+ found.resources.each do |resource|
if kind == :write
- ability.can(:manage, subject)
+ ability.can(:manage, resource)
else
- ability.can(%i[read admin], subject)
+ ability.can(%i[read admin], resource)
end
end
true
@@ -256,9 +185,13 @@ module Spree
# @return [Array<String>]
def expand_keys(keys)
keys = Array(keys).map(&:to_s)
- return catalog_keys if keys.include?('write_all')
+ # The aliases belong to secret API keys, which are a store's own
+ # credential — so they expand over what staff may hold, never over
+ # another audience's keys.
+ staff_resources = grantable_scopes(STAFF_AUDIENCE)
+ return staff_resources.flat_map(&:keys) if keys.include?('write_all')
- effective = keys.include?('read_all') ? resources.map(&:read_key) : []
+ effective = keys.include?('read_all') ? staff_resources.map(&:read_key) : []
effective |= keys.flat_map do |key|
kind, found = resolve_key(key)
next [] unless found
@@ -269,10 +202,10 @@ module Spree
end
# Restores the catalog to core defaults. Useful for tests that register
- # extra resources.
+ # extra scopes.
def reset!
- @resources = {}
- register_default_resources
+ @scopes = {}
+ DefaultCatalog.register(self)
end
# Removed in 6.0 — roles are data now (see docs/plans/6.0-admin-rbac.md).
@@ -284,217 +217,5 @@ module Spree
'managed in the dashboard (Settings → Roles), via the Admin API, or in seeds. ' \
"Upgrade guide: https://spreecommerce.org/docs/developer/upgrades/5.6-to-6.0"
end
-
- private
-
- # The core vocabulary — one entry per Admin API scope resource. Subjects
- # are lambdas so model classes resolve at activation, not load, time.
- # rubocop:disable Metrics/MethodLength
- def register_default_resources
- register_resource(:orders, group: :orders, audiences: %i[seller], subjects: -> {
- [Spree::Order, Spree::OrderGroup, Spree::LineItem, Spree::TaxLine, Spree::Discount, Spree::Fee,
- Spree::Return, Spree::Exchange, Spree::Claim, Spree::TaxIdentifier,
- Spree::CustomField, Spree::DigitalLink]
- })
- register_resource(:payments, group: :orders, subjects: -> { [Spree::Payment, Spree::PaymentSplit] })
- register_resource(:fulfillments, group: :orders, audiences: %i[seller], subjects: -> {
- [Spree::Fulfillment, Spree::ShippingLabel, Spree::Delivery]
- })
- register_resource(:refunds, group: :orders, subjects: -> { [Spree::Refund] })
- # Stored value is not a promotion and not an order: a gift card or a
- # store credit is prepaid money the store owes. Its own group, mirroring
- # the dashboard's Loyalty nav. The KEY names are unchanged, so roles
- # created before the move keep working.
- register_resource(:gift_cards, group: :loyalty, subjects: -> {
- [Spree::GiftCard, Spree::GiftCardBatch]
- })
- register_resource(:store_credits, group: :loyalty, subjects: -> {
- [Spree::StoreCredit, Spree::StoreCreditEvent]
- })
-
- # `Spree::Import` and its rows are subjects here because a CSV import is
- # a bulk product write and nothing else — which is the same reasoning
- # that makes `write_<resource>` the key gating every import endpoint
- # (see Spree::Import.required_scope). Without them CanCanCan denies a
- # principal whose capability comes from catalog keys alone, which is
- # every seller: the key gate would pass on `write_products` and the
- # `authorize!` immediately behind it would refuse.
- #
- # An operator is unaffected either way — the `admin` role grants
- # `can :manage, :all` and never consults this list.
- register_resource(:products, group: :catalog, audiences: %i[seller], subjects: -> {
- [Spree::Product, Spree::Variant, Spree::OptionType,
- Spree::OptionValue, Spree::Price, Spree::PriceList, Spree::PriceRule,
- Spree::Catalog, Spree::CatalogProduct,
- Spree::CatalogAssignment, Spree::CustomField, Spree::DigitalAsset,
- Spree::Import, Spree::ImportRow]
- })
- # Its own resource so a seller can be granted the read without the
- # write, but the write key has to exist: the operator's endpoint serves
- # create/update/destroy, and a resource declared `write: false` has no
- # `write_product_types` for that gate to accept — every scoped key and
- # every non-admin staff role would 403
- # (docs/plans/6.0-seller-product-submission.md). Sellers hold the read
- # alone; `grantable_keys` is what bounds them, not the catalog.
- register_resource(:product_types, group: :catalog,
- audiences: %i[seller], read_only_for: %i[seller],
- subjects: -> { [Spree::ProductType] })
- # Which channels carry a product is marketplace merchandising, so this
- # is closed to the seller audience entirely — a seller lists, the
- # marketplace distributes, and the seller branch serializes no
- # publication at all.
- #
- # Publishing is written through the products endpoint rather than one of
- # its own, so `write_publishing` gates nothing today; what this
- # registration does is take `ProductPublication` out of the `products`
- # subject list, which is what a seller's role would otherwise reach. A
- # staff role that manages publications needs this key alongside
- # `write_products`.
- register_resource(:publishing, group: :catalog, subjects: -> {
- [Spree::ProductPublication]
- })
- # Media is its own resource because a file is no longer a product's
- # alone: one row can be placed on a category or collection, and the
- # library lists, traces and deletes across all of them. Reaching a file
- # *through* a product still needs only `products` — the nested gallery
- # endpoints are that product's own media — but enumerating the library,
- # asking where a file is used, or deleting one everywhere is this key.
- register_resource(:media, group: :catalog, audiences: %i[seller], subjects: -> {
- [Spree::Media]
- })
- register_resource(:categories, group: :catalog, subjects: -> {
- [Spree::Category, Spree::ProductCategory]
- })
- register_resource(:collections, group: :catalog, subjects: -> {
- [Spree::Collection, Spree::ProductCollection, Spree::CollectionRule]
- })
- register_resource(:stock, group: :catalog, audiences: %i[seller], subjects: -> {
- [Spree::StockLevel, Spree::StockLocation, Spree::StockMovement,
- Spree::StockTransfer, Spree::StockTransferItem, Spree::StockReservation,
- Spree::StockReceipt, Spree::StockReceiptItem]
- })
- # Buying goods in, which is a different job from moving the goods you
- # already have: `write_stock` must not also mean "may place orders with
- # suppliers" (docs/plans/6.0-inventory-operations.md). Closed to the
- # seller audience — a marketplace seller does not purchase on the
- # operator's account.
- register_resource(:purchasing, group: :catalog, subjects: -> {
- [Spree::Supplier, Spree::PurchaseOrder, Spree::PurchaseOrderItem,
- Spree::StockReceipt, Spree::StockReceiptItem]
- })
-
- register_resource(:promotions, group: :marketing, subjects: -> {
- [Spree::Promotion, Spree::PromotionRule, Spree::PromotionAction,
- Spree::PromotionCategory, Spree::CouponCode, Spree::CustomField]
- })
-
- register_resource(:customers, group: :customers, subjects: -> {
- [Spree.customer_class, Spree::Address, Spree::CreditCard, Spree::CustomerGroup,
- Spree::Company, Spree::CompanyMembership,
- Spree::CompanyInvitation,
- Spree::TaxIdentifier, Spree::TaxExemptionCertificate,
- # GDPR records are about a customer and read alongside one, so they
- # ride the same key rather than becoming a resource of their own.
- Spree::DataRequest, Spree::ConsentRecord,
- Spree::CustomField]
- })
-
- register_resource(:settings, group: :settings, subjects: -> {
- [Spree::Store, Spree::PaymentMethod, Spree::Gateway,
- Spree::DeliveryZone, Spree::DeliveryZoneMember,
- Spree::StockLocation, Spree::DeliveryProfile,
- Spree::Market, Spree::TaxCategory, Spree::TaxRate, Spree::AllowedOrigin,
- Spree::RefundReason, Spree::ReturnReason, Spree::ClaimReason,
- Spree::OrderCancellationReason, Spree::Channel,
- Spree::OrderRoutingRule, Spree::CustomFieldDefinition, Spree::Policy]
- })
- # How goods actually get shipped and what that costs. Its own resource
- # rather than part of `settings` because on a marketplace a seller owns
- # their own methods, and `settings` is never seller-grantable — the rest
- # of what it covers is store-wide administration
- # (docs/plans/6.0-multi-vendor-marketplace.md, Decision 13).
- #
- # The profiles and zones these methods hang off stay in `settings`: the
- # marketplace defines that vocabulary and a seller only reads it.
- register_resource(:delivery_methods, group: :settings, audiences: %i[seller], subjects: -> {
- [Spree::DeliveryMethod, Spree::DeliveryMethodRule, Spree::DeliveryMethodService]
- })
- # What goods are packed into: the marketplace's boxes and cartons, and
- # each seller's own. Its own resource rather than part of `settings` for
- # the same reason `delivery_methods` is — a seller owns their packaging
- # and `settings` is never seller-grantable
- # (docs/plans/6.0-seller-package-types.md).
- register_resource(:package_types, group: :settings, audiences: %i[seller], subjects: -> {
- [Spree::PackageType]
- })
- register_resource(:webhooks, group: :settings, subjects: -> {
- [Spree::WebhookEndpoint, Spree::WebhookDelivery]
- })
- register_resource(:integrations, group: :settings, subjects: -> { [Spree::Integration] })
-
- register_resource(:api_keys, group: :access, subjects: -> { [Spree::ApiKey] })
- register_resource(:staff, group: :access, subjects: -> {
- [Spree.admin_user_class, Spree::Invitation, Spree::Role, Spree::RoleUser]
- })
-
- # Running the marketplace: admitting sellers, approving them, suspending
- # them. Deliberately not opened to the seller audience — a seller
- # administering other sellers is the one thing this key must not allow.
- # The seller records themselves, plus what the marketplace asks of them
- # before admitting them: who decides admission is who admits, so the
- # checklist rides the same key rather than becoming a settings matter.
- register_resource(:sellers, group: :access, subjects: -> {
- [Spree::Seller, Spree::SellerRequirement, Spree::SellerRequirementSubmission]
- })
-
- # What the marketplace charges its sellers. Its own resource rather than
- # part of `settings`, and closed to the seller audience for the same
- # reason `sellers` is: a seller must never be able to read, let alone
- # set, what anyone is charged.
- register_resource(:commissions, group: :access, subjects: -> {
- [Spree::CommissionRate, Spree::CommissionRule, Spree::CommissionLine]
- })
-
- # What the marketplace owes its sellers, and what it has sent them.
- # Separate from `commissions` because they are opposite directions of the
- # same relationship, and a finance operator often needs one without the
- # other. Closed to the seller audience: a seller reads their own earnings
- # through their own branch, scope-fetched, never through a key that could
- # reach the whole ledger.
- register_resource(:payouts, group: :access, subjects: -> {
- [Spree::SellerTransfer, Spree::SellerPayout]
- })
-
- # A seller editing their own record: profile, branding, addresses,
- # onboarding.
- #
- # A symbol subject, not `Spree::Seller`: that class belongs to `sellers`
- # above — the operator's key — and claiming it twice would make
- # `resource_for_subject` answer by registration order, besides letting a
- # seller's key manage seller records generally. A symbol grants a real
- # `can` rule (so `authorize!` on the seller branch resolves) while
- # staying invisible to `resource_for_subject`, which matches Classes
- # only. Which seller they may touch is still `current_seller`
- # scope-fetching, never an ability rule.
- register_resource(:seller_profile, group: :access, subjects: -> { [:seller_profile] },
- audiences: %i[seller])
-
- # A seller reading their own books: balance, earnings, settlements.
- #
- # Its own key rather than part of `seller_profile`, so an owner can hand
- # a packing teammate the orders without the money. Read-only, and a
- # symbol for the reason `seller_profile` is one: the ledger classes
- # belong to `payouts`, the operator's key. Which rows a seller reads is
- # `current_seller` scope-fetching on their own branch.
- register_resource(:seller_earnings, group: :access, subjects: -> { [:seller_earnings] },
- write: false, audiences: %i[seller])
-
- register_resource(:dashboard, group: :analytics, subjects: -> { [:dashboard] },
- write: false, audiences: %i[seller])
- # Semantic reporting (docs/plans/6.0-analytics-semantic-layer.md). Staff
- # only until seller queries get a compiler-forced seller scope.
- register_resource(:reports, group: :analytics, subjects: -> { [:reports, Spree::SavedReport, Spree::Exports::Report] })
- end
- # rubocop:enable Metrics/MethodLength
end
end
diff --git a/spree/core/lib/spree/core/permissions/default_catalog.rb b/spree/core/lib/spree/core/permissions/default_catalog.rb
new file mode 100644
index 0000000000..bb93260ab0
--- /dev/null
+++ b/spree/core/lib/spree/core/permissions/default_catalog.rb
@@ -0,0 +1,236 @@
+# What a store's back office is made of, in the order the permission pickers
+# show it. Registration order IS picker order. The seller panel's own
+# scopes come last, listed for the seller audience alone — staff never
+# see them.
+#
+# Only the vocabulary lives here. How keys resolve, activate and expand is
+# Spree::PermissionConfiguration; what a role actually holds is data.
+module Spree
+ class PermissionConfiguration
+ module DefaultCatalog
+ # The core vocabulary — one entry per Admin API scope scope. Resources
+ # are lambdas so model classes resolve at activation, not load, time.
+ # rubocop:disable Metrics/MethodLength
+ def self.register(catalog)
+ catalog.register_scope(:dashboard, group: :analytics, resources: -> { [:dashboard] },
+ write: false, audiences: %i[store seller])
+
+ # Semantic reporting (docs/plans/6.0-analytics-semantic-layer.md). Staff
+ # only until seller queries get a compiler-forced seller scope.
+ catalog.register_scope(:reports, group: :analytics,
+ resources: -> { [:reports, Spree::SavedReport, Spree::Exports::Report] })
+
+ catalog.register_scope(:orders, group: :orders, audiences: %i[store seller], resources: -> {
+ [Spree::Order, Spree::OrderGroup, Spree::LineItem, Spree::TaxLine, Spree::Discount, Spree::Fee,
+ Spree::Return, Spree::Exchange, Spree::Claim, Spree::TaxIdentifier,
+ Spree::CustomField, Spree::DigitalLink]
+ })
+ catalog.register_scope(:payments, group: :orders, resources: -> { [Spree::Payment, Spree::PaymentSplit] })
+ catalog.register_scope(:fulfillments, group: :orders, audiences: %i[store seller], resources: -> {
+ [Spree::Fulfillment, Spree::ShippingLabel, Spree::Delivery]
+ })
+ catalog.register_scope(:refunds, group: :orders, resources: -> { [Spree::Refund] })
+
+ # `Spree::Import` and its rows are resources here because a CSV import is
+ # a bulk product write and nothing else — which is the same reasoning
+ # that makes `write_<scope>` the key gating every import endpoint
+ # (see Spree::Import.required_scope). Without them CanCanCan denies a
+ # principal whose capability comes from catalog keys alone, which is
+ # every seller: the key gate would pass on `write_products` and the
+ # `authorize!` immediately behind it would refuse.
+ #
+ # An operator is unaffected either way — the `admin` role grants
+ # `can :manage, :all` and never consults this list.
+ catalog.register_scope(:products, group: :catalog, audiences: %i[store seller], resources: -> {
+ [Spree::Product, Spree::Variant, Spree::OptionType,
+ Spree::OptionValue, Spree::Price, Spree::PriceList, Spree::PriceRule,
+ Spree::Catalog, Spree::CatalogProduct,
+ Spree::CatalogAssignment, Spree::CustomField, Spree::DigitalAsset,
+ Spree::Import, Spree::ImportRow]
+ })
+
+ # Its own scope so a seller can be granted the read without the
+ # write, but the write key has to exist: the operator's endpoint serves
+ # create/update/destroy, and a scope declared `write: false` has no
+ # `write_product_types` for that gate to accept — every scoped key and
+ # every non-admin staff role would 403
+ # (docs/plans/6.0-seller-product-submission.md). Sellers hold the read
+ # alone; `grantable_keys` is what bounds them, not the catalog.
+ catalog.register_scope(:product_types, group: :catalog,
+ audiences: %i[store seller], read_only_for: %i[seller],
+ resources: -> { [Spree::ProductType] })
+
+ # Which channels carry a product is marketplace merchandising, so this
+ # is closed to the seller audience entirely — a seller lists, the
+ # marketplace distributes, and the seller branch serializes no
+ # publication at all.
+ #
+ # Publishing is written through the products endpoint rather than one of
+ # its own, so `write_publishing` gates nothing today; what this
+ # registration does is take `ProductPublication` out of the `products`
+ # resource list, which is what a seller's role would otherwise reach. A
+ # staff role that manages publications needs this key alongside
+ # `write_products`.
+ catalog.register_scope(:publishing, group: :catalog, resources: -> {
+ [Spree::ProductPublication]
+ })
+
+ # Media is its own scope because a file is no longer a product's
+ # alone: one row can be placed on a category or collection, and the
+ # library lists, traces and deletes across all of them. Reaching a file
+ # *through* a product still needs only `products` — the nested gallery
+ # endpoints are that product's own media — but enumerating the library,
+ # asking where a file is used, or deleting one everywhere is this key.
+ catalog.register_scope(:media, group: :catalog, audiences: %i[store seller], resources: -> {
+ [Spree::Media]
+ })
+ catalog.register_scope(:categories, group: :catalog, resources: -> {
+ [Spree::Category, Spree::ProductCategory]
+ })
+ catalog.register_scope(:collections, group: :catalog, resources: -> {
+ [Spree::Collection, Spree::ProductCollection, Spree::CollectionRule]
+ })
+ catalog.register_scope(:stock, group: :catalog, audiences: %i[store seller], resources: -> {
+ [Spree::StockLevel, Spree::StockLocation, Spree::StockMovement,
+ Spree::StockTransfer, Spree::StockTransferItem, Spree::StockReservation,
+ Spree::StockReceipt, Spree::StockReceiptItem]
+ })
+
+ # Buying goods in, which is a different job from moving the goods you
+ # already have: `write_stock` must not also mean "may place orders with
+ # suppliers" (docs/plans/6.0-inventory-operations.md). Closed to the
+ # seller audience — a marketplace seller does not purchase on the
+ # operator's account.
+ catalog.register_scope(:purchasing, group: :catalog, resources: -> {
+ [Spree::Supplier, Spree::PurchaseOrder, Spree::PurchaseOrderItem,
+ Spree::StockReceipt, Spree::StockReceiptItem]
+ })
+
+ catalog.register_scope(:customers, group: :customers, resources: -> {
+ [Spree.customer_class, Spree::Address, Spree::CreditCard, Spree::CustomerGroup,
+ Spree::Company, Spree::CompanyMembership,
+ Spree::CompanyInvitation,
+ Spree::TaxIdentifier, Spree::TaxExemptionCertificate,
+ # GDPR records are about a customer and read alongside one, so they
+ # ride the same key rather than becoming a scope of their own.
+ Spree::DataRequest, Spree::ConsentRecord,
+ Spree::CustomField]
+ })
+
+ # Running the marketplace: admitting sellers, approving them, suspending
+ # them. Deliberately not opened to the seller audience — a seller
+ # administering other sellers is the one thing this key must not allow.
+ # The seller records themselves, plus what the marketplace asks of them
+ # before admitting them: who decides admission is who admits, so the
+ # checklist rides the same key rather than becoming a settings matter.
+ catalog.register_scope(:sellers, group: :sellers, resources: -> {
+ [Spree::Seller, Spree::SellerRequirement, Spree::SellerRequirementSubmission]
+ })
+
+ # What the marketplace charges its sellers. Its own scope rather than
+ # part of `settings`, and closed to the seller audience for the same
+ # reason `sellers` is: a seller must never be able to read, let alone
+ # set, what anyone is charged.
+ catalog.register_scope(:commissions, group: :sellers, resources: -> {
+ [Spree::CommissionRate, Spree::CommissionRule, Spree::CommissionLine]
+ })
+
+ # What the marketplace owes its sellers, and what it has sent them.
+ # Separate from `commissions` because they are opposite directions of the
+ # same relationship, and a finance operator often needs one without the
+ # other. Closed to the seller audience: a seller reads their own earnings
+ # through their own branch, scope-fetched, never through a key that could
+ # reach the whole ledger.
+ catalog.register_scope(:payouts, group: :sellers, resources: -> {
+ [Spree::SellerTransfer, Spree::SellerPayout]
+ })
+
+ # Stored value is not a promotion and not an order: a gift card or a
+ # store credit is prepaid money the store owes. Its own group, mirroring
+ # the dashboard's Loyalty nav. The KEY names are unchanged, so roles
+ # created before the move keep working.
+ catalog.register_scope(:gift_cards, group: :loyalty, resources: -> {
+ [Spree::GiftCard, Spree::GiftCardBatch]
+ })
+ catalog.register_scope(:store_credits, group: :loyalty, resources: -> {
+ [Spree::StoreCredit, Spree::StoreCreditEvent]
+ })
+
+ catalog.register_scope(:promotions, group: :marketing, resources: -> {
+ [Spree::Promotion, Spree::PromotionRule, Spree::PromotionAction,
+ Spree::PromotionCategory, Spree::CouponCode, Spree::CustomField]
+ })
+
+ catalog.register_scope(:settings, group: :settings, resources: -> {
+ [Spree::Store, Spree::PaymentMethod, Spree::Gateway,
+ Spree::DeliveryZone, Spree::DeliveryZoneMember,
+ Spree::StockLocation, Spree::DeliveryProfile,
+ Spree::Market, Spree::TaxCategory, Spree::TaxRate, Spree::AllowedOrigin,
+ Spree::RefundReason, Spree::ReturnReason, Spree::ClaimReason,
+ Spree::OrderCancellationReason, Spree::Channel,
+ Spree::OrderRoutingRule, Spree::CustomFieldDefinition, Spree::Policy]
+ })
+
+ # How goods actually get shipped and what that costs. Its own scope
+ # rather than part of `settings` because on a marketplace a seller owns
+ # their own methods, and `settings` is never seller-grantable — the rest
+ # of what it covers is store-wide administration
+ # (docs/plans/6.0-multi-vendor-marketplace.md, Decision 13).
+ #
+ # The profiles and zones these methods hang off stay in `settings`: the
+ # marketplace defines that vocabulary and a seller only reads it.
+ catalog.register_scope(:delivery_methods, group: :settings, audiences: %i[store seller], resources: -> {
+ [Spree::DeliveryMethod, Spree::DeliveryMethodRule, Spree::DeliveryMethodService]
+ })
+
+ # What goods are packed into: the marketplace's boxes and cartons, and
+ # each seller's own. Its own scope rather than part of `settings` for
+ # the same reason `delivery_methods` is — a seller owns their packaging
+ # and `settings` is never seller-grantable
+ # (docs/plans/6.0-seller-package-types.md).
+ catalog.register_scope(:package_types, group: :settings, audiences: %i[store seller], resources: -> {
+ [Spree::PackageType]
+ })
+ catalog.register_scope(:webhooks, group: :settings, resources: -> {
+ [Spree::WebhookEndpoint, Spree::WebhookDelivery]
+ })
+ catalog.register_scope(:integrations, group: :settings, resources: -> { [Spree::Integration] })
+
+ catalog.register_scope(:api_keys, group: :access, resources: -> { [Spree::ApiKey] })
+ catalog.register_scope(:staff, group: :access, resources: -> {
+ [Spree.admin_user_class, Spree::Invitation, Spree::Role, Spree::RoleUser]
+ })
+
+ # The seller panel's own scopes. Their audience is the seller alone,
+ # so they grant a seller's role what it needs while staying out of the
+ # staff permission picker, where a store role could never usefully
+ # hold them.
+
+ # A seller editing their own record: profile, branding, addresses,
+ # onboarding.
+ #
+ # A symbol resource, not `Spree::Seller`: that class belongs to `sellers`
+ # above — the operator's key — and claiming it twice would make
+ # `scope_for_resource` answer by registration order, besides letting a
+ # seller's key manage seller records generally. A symbol grants a real
+ # `can` rule (so `authorize!` on the seller branch resolves) while
+ # staying invisible to `scope_for_resource`, which matches Classes
+ # only. Which seller they may touch is still `current_seller`
+ # scope-fetching, never an ability rule.
+ catalog.register_scope(:seller_profile, group: :seller, resources: -> { [:seller_profile] },
+ audiences: %i[seller])
+
+ # A seller reading their own books: balance, earnings, settlements.
+ #
+ # Its own key rather than part of `seller_profile`, so an owner can hand
+ # a packing teammate the orders without the money. Read-only, and a
+ # symbol for the reason `seller_profile` is one: the ledger classes
+ # belong to `payouts`, the operator's key. Which rows a seller reads is
+ # `current_seller` scope-fetching on their own branch.
+ catalog.register_scope(:seller_earnings, group: :seller, resources: -> { [:seller_earnings] },
+ write: false, audiences: %i[seller])
+ end
+ # rubocop:enable Metrics/MethodLength
+ end
+ end
+end
diff --git a/spree/core/lib/spree/core/permissions/entry.rb b/spree/core/lib/spree/core/permissions/entry.rb
new file mode 100644
index 0000000000..f267c90f9c
--- /dev/null
+++ b/spree/core/lib/spree/core/permissions/entry.rb
@@ -0,0 +1,15 @@
+module Spree
+ class PermissionConfiguration
+ # One grantable key with its kind and owning scope — the unit the
+ # `/admin/permissions` discovery endpoint serializes.
+ class Entry
+ attr_reader :key, :kind, :scope
+
+ def initialize(key:, kind:, scope:)
+ @key = key
+ @kind = kind
+ @scope = scope
+ end
+ end
+ end
+end
diff --git a/spree/core/lib/spree/core/permissions/scope.rb b/spree/core/lib/spree/core/permissions/scope.rb
new file mode 100644
index 0000000000..946fa49b57
--- /dev/null
+++ b/spree/core/lib/spree/core/permissions/scope.rb
@@ -0,0 +1,76 @@
+module Spree
+ class PermissionConfiguration
+ # A registered catalog scope. Yields one or two grantable keys and maps
+ # them to the CanCanCan resources they cover.
+ class Scope
+ attr_reader :name, :group
+
+ # @param name [Symbol] scope identifier (`:orders`)
+ # @param group [Symbol] UI grouping for the permission pickers
+ # @param resources [Proc, Array] CanCanCan resources covered by this
+ # scope; pass a lambda so model classes resolve lazily
+ # @param write [Boolean] whether a `write_<name>` key exists
+ # @param audiences [Array<Symbol>] every audience whose roles may hold
+ # this scope's keys — the store's own back office is `:store`, and
+ # is the whole list unless the registration says otherwise
+ def initialize(name:, group:, resources:, write: true, audiences: [STAFF_AUDIENCE], read_only_for: [])
+ @name = name.to_sym
+ @group = group.to_sym
+ @resources = resources
+ @write = write
+ @audiences = Array(audiences).map(&:to_sym).freeze
+ @read_only_for = Array(read_only_for).map(&:to_sym).freeze
+ end
+
+ # @return [Boolean]
+ def write?
+ @write
+ end
+
+ # @return [Array<Symbol>] every audience this scope is grantable to
+ def audiences
+ @audiences
+ end
+
+ # @param audience [Symbol, String, nil]
+ # @return [Boolean]
+ def grantable_to?(audience)
+ return false if audience.blank?
+
+ @audiences.include?(audience.to_s.to_sym)
+ end
+
+ # @return [Array<Class, Symbol>]
+ def resources
+ Array(@resources.respond_to?(:call) ? @resources.call : @resources)
+ end
+
+ # @return [String]
+ def read_key
+ "#{READ_PREFIX}#{name}"
+ end
+
+ # @return [String, nil]
+ def write_key
+ "#{WRITE_PREFIX}#{name}" if write?
+ end
+
+ # @return [Array<String>] the grantable keys, read first
+ def keys
+ [read_key, write_key].compact
+ end
+
+ # The keys one audience may hold. A scope the operator writes can
+ # still be read-only for somebody else — product types are the case:
+ # staff define them, a seller only picks from them.
+ #
+ # @param audience [Symbol, String, nil]
+ # @return [Array<String>]
+ def keys_for(audience)
+ return [read_key] if @read_only_for.include?(audience.to_s.to_sym)
+
+ keys
+ end
+ end
+ end
+end
diff --git a/spree/core/lib/spree/translations.rb b/spree/core/lib/spree/translations.rb
index fb7e67b9c5..e738def37f 100644
--- a/spree/core/lib/spree/translations.rb
+++ b/spree/core/lib/spree/translations.rb
@@ -132,7 +132,7 @@ module Spree
# @param klass [Class]
# @return [Symbol]
def permission_resource_name(klass)
- Spree.permissions.resource_for_subject(klass)&.name ||
+ Spree.permissions.scope_for_resource(klass)&.name ||
public_resource_type(klass).pluralize.to_sym
end
diff --git a/spree/core/spec/lib/spree/core/permission_configuration_spec.rb b/spree/core/spec/lib/spree/core/permission_configuration_spec.rb
index 0b3af58427..99576c0fd4 100644
--- a/spree/core/spec/lib/spree/core/permission_configuration_spec.rb
+++ b/spree/core/spec/lib/spree/core/permission_configuration_spec.rb
@@ -6,10 +6,10 @@ RSpec.describe Spree::PermissionConfiguration do
describe 'default catalog' do
it 'registers the core resources' do
- expect(configuration.resource(:orders)).to be_present
- expect(configuration.resource(:products)).to be_present
- expect(configuration.resource(:staff)).to be_present
- expect(configuration.resource(:dashboard)).to be_present
+ expect(configuration.scope(:orders)).to be_present
+ expect(configuration.scope(:products)).to be_present
+ expect(configuration.scope(:staff)).to be_present
+ expect(configuration.scope(:dashboard)).to be_present
end
it 'yields read and write keys per resource' do
@@ -22,47 +22,79 @@ RSpec.describe Spree::PermissionConfiguration do
end
end
- describe '#register_resource' do
+ # The pickers render groups in first-appearance order, so the order these
+ # are registered in IS the order a merchant reads them in. Pinned here
+ # because nothing else would notice a registration moving.
+ describe 'group order' do
+ it 'runs from what a merchant looks at most to what they set up once' do
+ groups = configuration.grantable_scopes(:store).map(&:group).uniq
+
+ expect(groups).to eq(%i[analytics orders catalog customers sellers loyalty marketing settings access])
+ end
+
+ it 'keeps running the marketplace together, apart from access' do
+ expect(%i[sellers commissions payouts].map { |name| configuration.scope(name).group }).to all(eq(:sellers))
+ end
+ end
+
+ describe '#register_scope' do
it 'registers a resource with lazy subjects and yields its keys' do
- configuration.register_resource(:reviews, group: :catalog, subjects: -> { [Spree::Product] })
+ configuration.register_scope(:reviews, group: :catalog, resources: -> { [Spree::Product] })
expect(configuration.catalog_keys).to include('read_reviews', 'write_reviews')
- expect(configuration.resource(:reviews).subjects).to eq([Spree::Product])
- expect(configuration.resource(:reviews).group).to eq(:catalog)
+ expect(configuration.scope(:reviews).resources).to eq([Spree::Product])
+ expect(configuration.scope(:reviews).group).to eq(:catalog)
end
it 'replaces an existing registration with the same name' do
- configuration.register_resource(:reviews, group: :catalog, subjects: [Spree::Product])
- configuration.register_resource(:reviews, group: :marketing, subjects: [Spree::Order])
+ configuration.register_scope(:reviews, group: :catalog, resources: [Spree::Product])
+ configuration.register_scope(:reviews, group: :marketing, resources: [Spree::Order])
- expect(configuration.resource(:reviews).group).to eq(:marketing)
+ expect(configuration.scope(:reviews).group).to eq(:marketing)
end
it 'reserves all — its keys would collide with the wildcard aliases' do
expect {
- configuration.register_resource(:all, group: :catalog, subjects: [Spree::Product])
+ configuration.register_scope(:all, group: :catalog, resources: [Spree::Product])
}.to raise_error(ArgumentError, /reserved/)
end
end
describe 'audiences' do
- it 'grants every resource to the store back office without naming it' do
- configuration.register_resource(:reviews, group: :catalog, subjects: [Spree::Product])
+ it 'grants a resource to the store back office by default' do
+ configuration.register_scope(:reviews, group: :catalog, resources: [Spree::Product])
+
+ expect(configuration.scope(:reviews)).to be_grantable_to(:store)
+ expect(configuration.grantable_keys(:store)).to include('read_reviews', 'write_reviews')
+ end
- expect(configuration.resource(:reviews)).to be_grantable_to(:store)
- expect(configuration.grantable_keys(:store)).to eq(configuration.catalog_keys)
+ # A key that only means something on the seller's own panel: granting it
+ # to a store role would build a role the seller branch never consults.
+ # The audience list is the whole list, so leaving the store out is how a
+ # resource stays off the staff picker.
+ it 'withholds a resource whose audiences leave the store out' do
+ configuration.register_scope(:reviews, group: :catalog, audiences: %i[seller], resources: [Spree::Product])
+
+ expect(configuration.scope(:reviews)).not_to be_grantable_to(:store)
+ expect(configuration.scope(:seller_profile)).not_to be_grantable_to(:store)
+ expect(configuration.grantable_keys(:store)).not_to include(
+ 'read_seller_profile', 'write_seller_profile', 'read_seller_earnings'
+ )
+ expect(configuration.entries.map(&:key)).not_to include('read_seller_profile')
end
- it 'grants a resource to the audiences it names, store included' do
- configuration.register_resource(:reviews, group: :catalog, audiences: %i[seller], subjects: [Spree::Product])
+ it 'grants a resource to exactly the audiences it names' do
+ configuration.register_scope(:reviews, group: :catalog, audiences: %i[store seller], resources: [Spree::Product])
+ expect(configuration.scope(:reviews).audiences).to contain_exactly(:store, :seller)
- expect(configuration.resource(:reviews).audiences).to contain_exactly(:store, :seller)
+ configuration.register_scope(:reviews, group: :catalog, audiences: %i[seller], resources: [Spree::Product])
+ expect(configuration.scope(:reviews).audiences).to contain_exactly(:seller)
end
it 'withholds unnamed audiences' do
- configuration.register_resource(:reviews, group: :catalog, subjects: [Spree::Product])
+ configuration.register_scope(:reviews, group: :catalog, resources: [Spree::Product])
- expect(configuration.resource(:reviews)).not_to be_grantable_to(:seller)
+ expect(configuration.scope(:reviews)).not_to be_grantable_to(:seller)
expect(configuration.grantable_keys(:seller)).not_to include('read_reviews')
end
@@ -78,8 +110,8 @@ RSpec.describe Spree::PermissionConfiguration do
# owns their own boxes, and `settings` is never seller-grantable
# (docs/plans/6.0-seller-package-types.md).
it 'keeps package types out of the settings resource' do
- expect(configuration.resource(:settings).subjects).not_to include(Spree::PackageType)
- expect(configuration.resource(:package_types).subjects).to include(Spree::PackageType)
+ expect(configuration.scope(:settings).resources).not_to include(Spree::PackageType)
+ expect(configuration.scope(:package_types).resources).to include(Spree::PackageType)
end
it 'never opens the operator-only resources to sellers' do
@@ -94,25 +126,25 @@ RSpec.describe Spree::PermissionConfiguration do
end
end
- describe '#unregister_resource' do
+ describe '#unregister_scope' do
it 'removes the resource and its keys' do
- configuration.register_resource(:reviews, group: :catalog, subjects: [Spree::Product])
- configuration.unregister_resource(:reviews)
+ configuration.register_scope(:reviews, group: :catalog, resources: [Spree::Product])
+ configuration.unregister_scope(:reviews)
- expect(configuration.resource(:reviews)).to be_nil
+ expect(configuration.scope(:reviews)).to be_nil
expect(configuration.catalog_keys).not_to include('read_reviews')
end
end
describe '#resolve_key' do
it 'resolves read and write keys' do
- kind, resource = configuration.resolve_key('write_orders')
+ kind, scope = configuration.resolve_key('write_orders')
expect(kind).to eq(:write)
- expect(resource.name).to eq(:orders)
+ expect(scope.name).to eq(:orders)
- kind, resource = configuration.resolve_key('read_gift_cards')
+ kind, scope = configuration.resolve_key('read_gift_cards')
expect(kind).to eq(:read)
- expect(resource.name).to eq(:gift_cards)
+ expect(scope.name).to eq(:gift_cards)
end
it 'returns nil for unknown keys' do
@@ -168,14 +200,18 @@ RSpec.describe Spree::PermissionConfiguration do
expect(configuration.expand_keys(%w[read_orders bogus write_nothing])).to eq(%w[read_orders])
end
- it 'expands write_all to the whole catalog' do
- expect(configuration.expand_keys(%w[write_all])).to eq(configuration.catalog_keys)
+ # The aliases belong to secret API keys, which a store issues — so they
+ # expand over what staff may hold, never over another audience's keys.
+ it 'expands write_all to everything staff may hold' do
+ expect(configuration.expand_keys(%w[write_all])).to eq(configuration.grantable_keys(:store))
+ expect(configuration.expand_keys(%w[write_all])).not_to include('read_seller_profile')
end
it 'expands read_all to every read key' do
expanded = configuration.expand_keys(%w[read_all])
expect(expanded).to include('read_orders', 'read_products', 'read_dashboard')
+ expect(expanded).not_to include('read_seller_earnings')
expect(expanded.grep(/\Awrite_/)).to be_empty
end
@@ -186,29 +222,29 @@ RSpec.describe Spree::PermissionConfiguration do
end
end
- describe '#resource_for_subject' do
+ describe '#scope_for_resource' do
it 'resolves a model class to its owning resource' do
- expect(configuration.resource_for_subject(Spree::Order).name).to eq(:orders)
- expect(configuration.resource_for_subject(Spree::OptionType).name).to eq(:products)
+ expect(configuration.scope_for_resource(Spree::Order).name).to eq(:orders)
+ expect(configuration.scope_for_resource(Spree::OptionType).name).to eq(:products)
end
it 'matches by ancestry so subclasses resolve to the base subject' do
- expect(configuration.resource_for_subject(Spree::Gateway).name).to eq(:settings)
+ expect(configuration.scope_for_resource(Spree::Gateway).name).to eq(:settings)
end
it 'returns nil for classes no resource covers' do
- expect(configuration.resource_for_subject(Spree::Country)).to be_nil
- expect(configuration.resource_for_subject('not a class')).to be_nil
+ expect(configuration.scope_for_resource(Spree::Country)).to be_nil
+ expect(configuration.scope_for_resource('not a class')).to be_nil
end
end
describe '#reset!' do
it 'restores the default catalog' do
- configuration.register_resource(:reviews, group: :catalog, subjects: [Spree::Product])
+ configuration.register_scope(:reviews, group: :catalog, resources: [Spree::Product])
configuration.reset!
- expect(configuration.resource(:reviews)).to be_nil
- expect(configuration.resource(:orders)).to be_present
+ expect(configuration.scope(:reviews)).to be_nil
+ expect(configuration.scope(:orders)).to be_present
end
end
@@ -277,7 +313,7 @@ RSpec.describe Spree::PermissionConfiguration do
end
it 'leaves Spree::Seller mapped to the operator resource' do
- expect(Spree.permissions.resource_for_subject(Spree::Seller).name).to eq(:sellers)
+ expect(Spree.permissions.scope_for_resource(Spree::Seller).name).to eq(:sellers)
end
end
diff --git a/spree/core/spec/models/spree/ability_spec.rb b/spree/core/spec/models/spree/ability_spec.rb
index af4ccf0273..f4f0f63acb 100644
--- a/spree/core/spec/models/spree/ability_spec.rb
+++ b/spree/core/spec/models/spree/ability_spec.rb
@@ -150,9 +150,16 @@ describe Spree::Ability, type: :model do
admin.role_users.create!(role: Spree::Role.default_admin_role(store))
end
- it 'grants everything and reports the full catalog' do
+ it 'grants everything and reports every key staff may hold' do
expect(staff_ability).to be_able_to :manage, :all
- expect(staff_ability.permission_keys).to eq(Spree.permissions.catalog_keys)
+ expect(staff_ability.permission_keys).to eq(Spree.permissions.grantable_keys(:store))
+ end
+
+ # `can :manage, :all` really does cover everything, but the reported
+ # keys drive the dashboard's pickers — and offering a key only another
+ # audience may hold builds a role that refuses to save.
+ it 'leaves out the keys only another audience may hold' do
+ expect(staff_ability.permission_keys).not_to include('read_seller_profile', 'read_seller_earnings')
end
end
@@ -200,8 +207,8 @@ describe Spree::Ability, type: :model do
before do
# Open orders to the stand-in's audience, as the catalog opens it to
# marketplace sellers.
- Spree.permissions.register_resource(
- :orders, group: :orders, audiences: %i[customer_group], subjects: -> { [Spree::Order] }
+ Spree.permissions.register_scope(
+ :orders, group: :orders, audiences: %i[customer_group], resources: -> { [Spree::Order] }
)
admin.role_users.create!(
role: create(:role, name: 'panel_orders', permissions: %w[write_orders], resource: panel)
@@ -294,8 +301,8 @@ describe Spree::Ability, type: :model do
let(:seller_like) { Spree::DummyModel.create!(name: 'Seller A') }
before do
- Spree.permissions.register_resource(
- :products, group: :catalog, audiences: %i[dummy_model], subjects: -> { [Spree::Product] }
+ Spree.permissions.register_scope(
+ :products, group: :catalog, audiences: %i[dummy_model], resources: -> { [Spree::Product] }
)
end
diff --git a/spree/core/spec/models/spree/role_spec.rb b/spree/core/spec/models/spree/role_spec.rb
index 55a967d805..56ccb7af43 100644
--- a/spree/core/spec/models/spree/role_spec.rb
+++ b/spree/core/spec/models/spree/role_spec.rb
@@ -121,8 +121,8 @@ describe Spree::Role do
describe 'resource-bounded permissions' do
before do
- Spree.permissions.register_resource(
- :products, group: :catalog, audiences: %i[customer_group], subjects: -> { [Spree::Product] }
+ Spree.permissions.register_scope(
+ :products, group: :catalog, audiences: %i[customer_group], resources: -> { [Spree::Product] }
)
end
@@ -140,9 +140,23 @@ describe Spree::Role do
expect(role.errors[:permissions].join).not_to include('write_products')
end
- it 'leaves store roles unbounded' do
+ it 'allows a store role every key its own audience is granted' do
expect(build(:role, permissions: %w[write_settings write_staff])).to be_valid
end
+
+ # The catalog carries resources only another audience can use. A store
+ # role holding one would be granted its subjects at activation without
+ # ever holding the staff key that covers them.
+ it 'refuses a store role the keys only another audience may hold' do
+ Spree.permissions.register_scope(
+ :their_own_thing, group: :seller, audiences: %i[customer_group], resources: -> { [Spree::Product] }
+ )
+
+ role = build(:role, permissions: %w[write_settings write_their_own_thing])
+
+ expect(role).not_to be_valid
+ expect(role.errors[:permissions].join).to include('write_their_own_thing')
+ end
end
describe 'admin role protection' do
diff --git a/spree/lib/generators/spree/install/templates/config/initializers/spree.rb b/spree/lib/generators/spree/install/templates/config/initializers/spree.rb
index cbe087dd30..3afbbee41c 100644
--- a/spree/lib/generators/spree/install/templates/config/initializers/spree.rb
+++ b/spree/lib/generators/spree/install/templates/config/initializers/spree.rb
@@ -88,7 +88,7 @@ Rails.application.config.after_initialize do
# .update!(permissions: %w[read_orders read_customers])
#
# Extensions can register additional permission resources:
- # Spree.permissions.register_resource(:reviews, group: :catalog, subjects: -> { [MyApp::Review] })
+ # Spree.permissions.register_scope(:reviews, group: :catalog, resources: -> { [MyApp::Review] })
#
# To customize authorization beyond the catalog, replace the ability class:
# Spree::Dependencies.ability_class = 'MyApp::Ability'