mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-20 04:59:16 +00:00
Merge branch 'master' into 2-0-stable-nov-8th
This commit is contained in:
@@ -1,4 +1,37 @@
|
||||
require 'spree/core/preference_rescue'
|
||||
# Spree 1.3.6.beta preference rescue implementation, required for the new
|
||||
# preferences migration, which is broken since commit ab707cf due to the
|
||||
# absence of this file.
|
||||
#
|
||||
# Migration: db/migrate/20120327000645_new_preferences.rb
|
||||
# Source: https://raw.githubusercontent.com/spree/spree/1-3-stable/core/lib/spree/core/preference_rescue.rb
|
||||
#
|
||||
# rubocop:disable all
|
||||
module Spree
|
||||
class OldPrefs < ActiveRecord::Base
|
||||
self.table_name = "spree_preferences"
|
||||
belongs_to :owner, :polymorphic => true
|
||||
attr_accessor :owner_klass
|
||||
end
|
||||
|
||||
class PreferenceRescue
|
||||
def self.try
|
||||
OldPrefs.where(:key => nil).each do |old_pref|
|
||||
next unless owner = (old_pref.owner rescue nil)
|
||||
unless old_pref.owner_type == "Spree::Activator" || old_pref.owner_type == "Spree::Configuration"
|
||||
begin
|
||||
old_pref.key = [owner.class.name, old_pref.name, owner.id].join('::').underscore
|
||||
old_pref.value_type = owner.preference_type(old_pref.name)
|
||||
puts "Migrating Preference: #{old_pref.key}"
|
||||
old_pref.save
|
||||
rescue NoMethodError => ex
|
||||
puts ex.message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop:enable all
|
||||
|
||||
class NewPreferences < ActiveRecord::Migration
|
||||
|
||||
@@ -45,4 +78,4 @@ class NewPreferences < ActiveRecord::Migration
|
||||
add_column :spree_preferences, :group_id, :integer
|
||||
add_column :spree_preferences, :group_type, :string
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
class RevokeVariantOverrideswithoutPermissions < ActiveRecord::Migration
|
||||
def up
|
||||
# This process was executed when the permission_revoked_at colum was created (see AddPermissionRevokedAtToVariantOverrides)
|
||||
# It needs to be repeated due to #2739
|
||||
variant_override_hubs = Enterprise.where(id: VariantOverride.select(:hub_id).uniq)
|
||||
|
||||
variant_override_hubs.find_each do |hub|
|
||||
permitting_producer_ids = hub.relationships_as_child
|
||||
.with_permission(:create_variant_overrides).pluck(:parent_id)
|
||||
|
||||
variant_overrides_with_revoked_permissions = VariantOverride.for_hubs(hub)
|
||||
.joins(variant: :product).where("spree_products.supplier_id NOT IN (?)", permitting_producer_ids)
|
||||
|
||||
variant_overrides_with_revoked_permissions.update_all(permission_revoked_at: Time.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class UpdateWeightCalculatorTypeClassName < ActiveRecord::Migration
|
||||
def up
|
||||
Spree::Calculator.connection.execute("UPDATE spree_calculators SET type = 'Calculator::Weight' WHERE type = 'OpenFoodNetwork::Calculator::Weight'")
|
||||
end
|
||||
|
||||
def down
|
||||
Spree::Calculator.connection.execute("UPDATE spree_calculators SET type = 'OpenFoodNetwork::Calculator::Weight' WHERE type = 'Calculator::Weight'")
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20181010093850) do
|
||||
ActiveRecord::Schema.define(:version => 20181106162211) do
|
||||
|
||||
create_table "account_invoices", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
|
||||
Reference in New Issue
Block a user