Rename variant 'owner' to 'hub'

As discussed by team, and using same nomenclature as VariantOverride.
This commit is contained in:
David Cook
2026-03-11 10:44:15 +11:00
parent e9ce2df5a9
commit 18fb1cfa74
9 changed files with 21 additions and 21 deletions

View File

@@ -40,7 +40,7 @@ module Spree
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', optional: false
belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true, optional: false
belongs_to :supplier, class_name: 'Enterprise', optional: false, touch: true
belongs_to :owner, class_name: 'Enterprise', optional: true
belongs_to :hub, class_name: 'Enterprise', optional: true
delegate :name, :name=, :description, :description=, :meta_keywords, to: :product
@@ -275,8 +275,8 @@ module Spree
# Clone this variant, retaining a 'source' link to it
def create_linked_variant(user)
# Owner is my enterprise which has permission to create variants sourced from that supplier
owner_id = EnterpriseRelationship.permitted_by(supplier).permitting(user.enterprises)
# Hub owner is my enterprise which has permission to create variant sourced from that supplier
hub_id = EnterpriseRelationship.permitted_by(supplier).permitting(user.enterprises)
.with_permission(:create_linked_variants)
.pick(:child_id)
@@ -284,7 +284,7 @@ module Spree
variant.price = price
variant.source_variants = [self]
variant.stock_items << Spree::StockItem.new(variant:)
variant.owner_id = owner_id
variant.hub_id = hub_id
variant.on_demand = on_demand
variant.on_hand = on_hand
variant.save!

View File

@@ -4,7 +4,7 @@
%td.col-image
-# empty
- variant.source_variants.each do |source_variant|
= content_tag(:span, "🔗", title: t('admin.products_page.variant_row.sourced_from', source_name: source_variant.name, source_id: source_variant.id, owner_name: variant.owner&.name))
= content_tag(:span, "🔗", title: t('admin.products_page.variant_row.sourced_from', source_name: source_variant.name, source_id: source_variant.id, hub_name: variant.hub&.name))
%td.col-name.field.naked_inputs
= f.hidden_field :id
= f.text_field :display_name, 'aria-label': t('admin.products_page.columns.name'), placeholder: variant.product.name

View File

@@ -721,7 +721,7 @@ en:
image:
edit: Edit
variant_row:
sourced_from: "Sourced from: %{source_name} (%{source_id}); Owned by: %{owner_name}"
sourced_from: "Sourced from: %{source_name} (%{source_id}); Hub: %{hub_name}"
product_preview:
product_preview: Product preview
shop_tab: Shop

View File

@@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddHubToSpreeVariants < ActiveRecord::Migration[7.1]
def change
add_reference :spree_variants, :hub, foreign_key: { to_table: :enterprises }
end
end

View File

@@ -1,7 +0,0 @@
# frozen_string_literal: true
class AddOwnerToSpreeVariants < ActiveRecord::Migration[7.1]
def change
add_reference :spree_variants, :owner, foreign_key: { to_table: :enterprises }
end
end

View File

@@ -1009,8 +1009,8 @@ ActiveRecord::Schema[7.1].define(version: 2026_03_06_015040) do
t.bigint "supplier_id"
t.float "variant_unit_scale"
t.string "variant_unit_name", limit: 255
t.bigint "owner_id"
t.index ["owner_id"], name: "index_spree_variants_on_owner_id"
t.bigint "hub_id"
t.index ["hub_id"], name: "index_spree_variants_on_hub_id"
t.index ["primary_taxon_id"], name: "index_spree_variants_on_primary_taxon_id"
t.index ["product_id"], name: "index_variants_on_product_id"
t.index ["shipping_category_id"], name: "index_spree_variants_on_shipping_category_id"
@@ -1271,7 +1271,7 @@ ActiveRecord::Schema[7.1].define(version: 2026_03_06_015040) do
add_foreign_key "spree_tax_rates", "spree_zones", column: "zone_id", name: "spree_tax_rates_zone_id_fk"
add_foreign_key "spree_users", "spree_addresses", column: "bill_address_id", name: "spree_users_bill_address_id_fk"
add_foreign_key "spree_users", "spree_addresses", column: "ship_address_id", name: "spree_users_ship_address_id_fk"
add_foreign_key "spree_variants", "enterprises", column: "owner_id"
add_foreign_key "spree_variants", "enterprises", column: "hub_id"
add_foreign_key "spree_variants", "enterprises", column: "supplier_id"
add_foreign_key "spree_variants", "spree_products", column: "product_id", name: "spree_variants_product_id_fk"
add_foreign_key "spree_variants", "spree_shipping_categories", column: "shipping_category_id"

View File

@@ -8,7 +8,7 @@ RSpec.describe Spree::Variant do
it { is_expected.to have_many :semantic_links }
it { is_expected.to belong_to(:product).required }
it { is_expected.to belong_to(:supplier).required }
it { is_expected.to belong_to(:owner).optional }
it { is_expected.to belong_to(:hub).optional }
it { is_expected.to have_many(:inventory_units) }
it { is_expected.to have_many(:line_items) }
it { is_expected.to have_many(:stock_items) }
@@ -1024,7 +1024,7 @@ RSpec.describe Spree::Variant do
linked_variant = variant.create_linked_variant(user)
expect(linked_variant.source_variants).to eq [variant]
expect(linked_variant.owner).to eq enterprise
expect(linked_variant.hub).to eq enterprise
expect(linked_variant.price).to eq 10.95
expect(linked_variant.on_demand).to eq false
expect(linked_variant.on_hand).to eq 5

View File

@@ -121,7 +121,7 @@ RSpec.describe "Admin::ProductsV3" do
# The new variant is owned by my enterprise that has permission, not the other one
new_variant = variant.product.variants.order(:id).last
expect(new_variant.owner).to eq enterprise
expect(new_variant.hub).to eq enterprise
end
end
end

View File

@@ -147,7 +147,7 @@ RSpec.describe 'As an enterprise user, I can browse my products' do
let!(:v3_source) { p3.variants.first }
let!(:v3_sourced) {
create(:variant, display_name: "Variant3-sourced", product: p3, supplier: source_producer,
owner: producer)
hub: producer)
}
let!(:enterprise_relationship) {
# Other producer grants me access to manage their variant
@@ -163,7 +163,7 @@ RSpec.describe 'As an enterprise user, I can browse my products' do
it "shows sourced variant with indicator" do
within row_containing_name("Variant3-sourced") do
expect(page).to have_selector 'span[title*="Sourced from: "]'
expect(page).to have_selector 'span[title*="Owned by: My Enterprise"]'
expect(page).to have_selector 'span[title*="Hub: My Enterprise"]'
end
end
end