From 079d4e0bf500615d0eca293f6433c77a77c018ed Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Wed, 31 Oct 2018 11:23:29 +0000 Subject: [PATCH] Fix variant_overrides permissions for overrides that belong to the supplier herself --- ...5158_allow_all_suppliers_own_variant_overrides.rb | 12 ++++++++++++ db/schema.rb | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20181031105158_allow_all_suppliers_own_variant_overrides.rb diff --git a/db/migrate/20181031105158_allow_all_suppliers_own_variant_overrides.rb b/db/migrate/20181031105158_allow_all_suppliers_own_variant_overrides.rb new file mode 100644 index 0000000000..a04bd5dfff --- /dev/null +++ b/db/migrate/20181031105158_allow_all_suppliers_own_variant_overrides.rb @@ -0,0 +1,12 @@ +class AllowAllSuppliersOwnVariantOverrides < ActiveRecord::Migration + def up + # This migration is fixing a detail of previous migration RevokeVariantOverrideswithoutPermissions + # Here we allow all variant_overrides where hub_id is the products supplier_id + # This is needed when the supplier herself uses the inventory to manage stock and not the catalog + owned_variant_overrides = VariantOverride.unscoped + .joins(variant: :product).where("spree_products.supplier_id = variant_overrides.hub_id") + + owned_variant_overrides.update_all(permission_revoked_at: nil) + end +end + diff --git a/db/schema.rb b/db/schema.rb index 3e60568a4a..18f7177b86 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20181020103501) do +ActiveRecord::Schema.define(:version => 20181031105158) do create_table "account_invoices", :force => true do |t| t.integer "user_id", :null => false