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.

Add deprecation warnings to legacy functionality (Spree 5.5) (#13599)

Damian Legawiec180736c2063c
diff --git a/backend/engines/core/app/models/spree/ability.rb b/backend/engines/core/app/models/spree/ability.rb
index 2934bd8ff4..d9d52970f0 100644
--- a/backend/engines/core/app/models/spree/ability.rb
+++ b/backend/engines/core/app/models/spree/ability.rb
@@ -30,11 +30,21 @@ module Spree
# modify the default +Ability+ of an application. The +ability+ argument must be a class that includes
# the +CanCan::Ability+ module. The registered ability should behave properly as a stand-alone class
# and therefore should be easy to test in isolation.
+ # @deprecated Use Spree::PermissionSets instead. Will be removed in Spree 5.5.
def self.register_ability(ability)
+ Spree::Deprecation.warn(
+ 'Spree::Ability.register_ability is deprecated and will be removed in Spree 5.5. ' \
+ 'Please use Spree::PermissionSets instead. See Spree::PermissionSets::Base for details.'
+ )
abilities.add(ability)
end
+ # @deprecated Use Spree::PermissionSets instead. Will be removed in Spree 5.5.
def self.remove_ability(ability)
+ Spree::Deprecation.warn(
+ 'Spree::Ability.remove_ability is deprecated and will be removed in Spree 5.5. ' \
+ 'Please use Spree::PermissionSets instead. See Spree::PermissionSets::Base for details.'
+ )
abilities.delete(ability)
end
diff --git a/backend/engines/core/app/models/spree/store.rb b/backend/engines/core/app/models/spree/store.rb
index 1860a25aa0..4503627c65 100644
--- a/backend/engines/core/app/models/spree/store.rb
+++ b/backend/engines/core/app/models/spree/store.rb
@@ -204,14 +204,17 @@ module Spree
end
end
- # FIXME: we need to drop `or_initialize` in v5
- # this behaviour is very buggy and unpredictable
+ # @deprecated The or_initialize behavior will be removed in Spree 5.5.
def self.default
Rails.cache.fetch('default_store') do
# workaround for Mobility bug with first_or_initialize
if where(default: true).any?
where(default: true).first
else
+ Spree::Deprecation.warn(
+ 'Spree::Store.default returning a new unpersisted store when no default store exists is deprecated ' \
+ 'and will be removed in Spree 5.5. Please ensure a default store is created before calling Store.default.'
+ )
new(default: true)
end
end
diff --git a/backend/engines/core/app/models/spree/taxon.rb b/backend/engines/core/app/models/spree/taxon.rb
index f8862f4d28..11869fbce5 100644
--- a/backend/engines/core/app/models/spree/taxon.rb
+++ b/backend/engines/core/app/models/spree/taxon.rb
@@ -38,7 +38,8 @@ module Spree
has_one :store, through: :taxonomy
has_many :classifications, -> { order(:position) }, dependent: :destroy_async, inverse_of: :taxon
has_many :products, through: :classifications
- has_one :icon, as: :viewable, dependent: :destroy, class_name: 'Spree::TaxonImage' # TODO: remove this as this is deprecated
+ # @deprecated Use Spree::Taxon#image (Active Storage) instead. Will be removed in Spree 5.5.
+ has_one :icon, as: :viewable, dependent: :destroy, class_name: 'Spree::TaxonImage'
has_many :prototype_taxons, class_name: 'Spree::PrototypeTaxon', dependent: :destroy
has_many :prototypes, through: :prototype_taxons, class_name: 'Spree::Prototype'
diff --git a/backend/engines/core/app/models/spree/taxon_image.rb b/backend/engines/core/app/models/spree/taxon_image.rb
index 95e04c2ff3..1153ec7f23 100644
--- a/backend/engines/core/app/models/spree/taxon_image.rb
+++ b/backend/engines/core/app/models/spree/taxon_image.rb
@@ -1,9 +1,17 @@
module Spree
+ # @deprecated Use Spree::Taxon#image (Active Storage) instead. Will be removed in Spree 5.5.
class TaxonImage < Asset
include Spree::TaxonImage::Configuration::ActiveStorage
include Rails.application.routes.url_helpers
include Spree::ImageMethods
+ after_initialize do
+ Spree::Deprecation.warn(
+ 'Spree::TaxonImage is deprecated and will be removed in Spree 5.5. ' \
+ 'Please use Spree::Taxon#image (Active Storage) instead.'
+ )
+ end
+
def styles
self.class.styles.map do |_, size|
width, height = size[/(\d+)x(\d+)/].split('x').map(&:to_i)
diff --git a/backend/engines/core/lib/spree/webhooks.rb b/backend/engines/core/lib/spree/webhooks.rb
index 639219cfbc..21f163c9c5 100644
--- a/backend/engines/core/lib/spree/webhooks.rb
+++ b/backend/engines/core/lib/spree/webhooks.rb
@@ -1,7 +1,7 @@
module Spree
module Webhooks
def self.disable_webhooks
- Spree::Deprecation.warn('Spree::Webhooks.disable_webhooks is deprecated. Use Spree::LegacyWebhooks.disable_webhooks instead.')
+ Spree::Deprecation.warn('Spree::Webhooks.disable_webhooks is deprecated and will be removed in Spree 5.5. Use Spree::LegacyWebhooks.disable_webhooks instead.')
prev_value = disabled?
RequestStore.store[:disable_spree_legacy_webhooks] = true
yield
@@ -10,12 +10,12 @@ module Spree
end
def self.disabled?
- Spree::Deprecation.warn('Spree::Webhooks.disabled? is deprecated. Use Spree::LegacyWebhooks.disabled? instead.')
+ Spree::Deprecation.warn('Spree::Webhooks.disabled? is deprecated and will be removed in Spree 5.5. Use Spree::LegacyWebhooks.disabled? instead.')
RequestStore.fetch(:disable_spree_legacy_webhooks) { false }
end
def self.disabled=(value)
- Spree::Deprecation.warn('Spree::Webhooks.disabled= is deprecated. Use Spree::LegacyWebhooks.disabled= instead.')
+ Spree::Deprecation.warn('Spree::Webhooks.disabled= is deprecated and will be removed in Spree 5.5. Use Spree::LegacyWebhooks.disabled= instead.')
RequestStore.store[:disable_spree_legacy_webhooks] = value
end
end