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.

Simplify the generation of a secret key by depending on Rails' has_secure_token

Stefan Vermaas8e31721f01f6
diff --git a/api/app/models/spree/webhooks/subscriber.rb b/api/app/models/spree/webhooks/subscriber.rb
index 0e443270cc..7b681e1353 100644
--- a/api/app/models/spree/webhooks/subscriber.rb
+++ b/api/app/models/spree/webhooks/subscriber.rb
@@ -5,11 +5,11 @@ module Spree
include Spree::VendorConcern
end
+ has_secure_token :secret_key
+
has_many :events, inverse_of: :subscriber
validates :url, 'spree/url': true, presence: true
- validates :secret_key, presence: true
-
validate :check_uri_path
self.whitelisted_ransackable_attributes = %w[active subscriptions url]
@@ -18,7 +18,6 @@ module Spree
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
- before_validation :generate_secret_key, unless: :secret_key?
before_save :parse_subscriptions
def self.with_urls_for(event)
@@ -53,10 +52,6 @@ module Spree
errors.add(:url, 'the URL must have a path') if uri.blank? || uri.path.blank?
end
- def generate_secret_key
- self.secret_key = SecureRandom.urlsafe_base64(32)
- end
-
def parse_subscriptions
return if subscriptions.blank? || subscriptions.is_a?(Array)