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.

Code review issues fixed.

Matthew Kennedya10baf86ada8
diff --git a/core/app/models/spree/digital.rb b/core/app/models/spree/digital.rb
index d906406391..9fc4a59b5c 100644
--- a/core/app/models/spree/digital.rb
+++ b/core/app/models/spree/digital.rb
@@ -4,6 +4,7 @@ module Spree
has_many :digital_links, dependent: :destroy
has_one_attached :attachment
+
validates :attachment, attached: true
end
end
diff --git a/core/app/models/spree/digital_link.rb b/core/app/models/spree/digital_link.rb
index 5723fa71aa..3056d83197 100644
--- a/core/app/models/spree/digital_link.rb
+++ b/core/app/models/spree/digital_link.rb
@@ -1,15 +1,16 @@
module Spree
class DigitalLink < Spree::Base
+ has_secure_token :secret
+
belongs_to :digital
validates :digital, presence: true
belongs_to :line_item
- validates_length_of :secret, is: 30
-
before_validation :set_defaults, on: :create
- # Can this link stil be used? It is valid if it's less than 24 hours old and was not accessed more than 3 times
+ # Can this link stil be used? It is valid if it's less than 24 hours
+ # old and was not accessed more than 3 times
def authorizable?
!(expired? || access_limit_exceeded?)
end
@@ -30,14 +31,14 @@ module Spree
def reset!
update_column :access_counter, 0
- update_column :created_at, Time.now
+ update_column :created_at, Time.current
end
private
- # Populating the secret automatically and zero'ing the access_counter (otherwise it might turn out to be NULL)
+ # Populating the secret automatically and zero'ing the access_counter
+ # (otherwise it might turn out to be NULL)
def set_defaults
- self.secret = SecureRandom.hex(15)
self.access_counter ||= 0
end
end
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb
index e063eadc9b..04a655849d 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -129,8 +129,8 @@ module Spree
# include master variant digitals
master = variant.product.master
- create_digital_links_for_variant(master) if master.digital?
+ create_digital_links_for_variant(master) if master.digital?
create_digital_links_for_variant(variant) unless variant.is_master?
end
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 5c1069e9b9..5d7ce03b99 100644
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -55,7 +55,6 @@ module Spree
has_many :possible_promotions, -> { advertised.active }, through: :promotion_rules,
class_name: 'Spree::Promotion',
source: :promotion
- has_many :digitals, through: :variants_including_master
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :products
@@ -88,6 +87,7 @@ module Spree
has_many :store_products, class_name: 'Spree::StoreProduct'
has_many :stores, through: :store_products, class_name: 'Spree::Store'
+ has_many :digitals, through: :variants_including_master
after_create :add_associations_from_prototype
after_create :build_variants_from_option_values_hash, if: :option_values_hash
diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb
index 4b6920a0bc..dd97b9de70 100644
--- a/core/app/models/spree/variant.rb
+++ b/core/app/models/spree/variant.rb
@@ -43,6 +43,7 @@ module Spree
inverse_of: :variant
has_many :wished_items, dependent: :destroy
+
has_many :digitals
before_validation :set_cost_currency