mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-25 01:23:23 +00:00
Active Storage always touches associated records when attachments are changed. But for the Terms of Service it's important to keep the updated_at date because that's how we find out how new it is and if a customer accepted those terms already. And while we migrate files, the content of the files will stay the same and we don't want customers to be asked to accept the same terms again.
30 lines
738 B
Ruby
30 lines
738 B
Ruby
# frozen_string_literal: true
|
|
|
|
class TermsOfServiceFile < ApplicationRecord
|
|
include HasMigratingFile
|
|
|
|
has_one_migrating :attachment
|
|
|
|
validates :attachment, presence: true
|
|
|
|
# The most recently uploaded file is the current one.
|
|
def self.current
|
|
order(:id).last
|
|
end
|
|
|
|
def self.current_url
|
|
current&.attachment&.url || Spree::Config.footer_tos_url
|
|
end
|
|
|
|
# If no file has been uploaded, we don't know when the old terms have
|
|
# been updated last. So we return the most recent possible update time.
|
|
def self.updated_at
|
|
current&.updated_at || Time.zone.now
|
|
end
|
|
|
|
def touch(_)
|
|
# Ignore Active Storage changing the timestamp during migrations.
|
|
# This can be removed once we got rid of Paperclip.
|
|
end
|
|
end
|