diff --git a/app/models/concerns/blob_virus_scanner.rb b/app/models/concerns/blob_virus_scanner.rb index 4cd5f8476..c6b0966c9 100644 --- a/app/models/concerns/blob_virus_scanner.rb +++ b/app/models/concerns/blob_virus_scanner.rb @@ -1,3 +1,7 @@ +# TODO: once we're using Rails 6, use the hooks on attachments creation +# (rather than on blob creation). +# This will help to avoid cloberring metadata accidentally (as metadata +# are more stable on attachment creation than on blob creation). module BlobVirusScanner extend ActiveSupport::Concern diff --git a/config/initializers/active_storage.rb b/config/initializers/active_storage.rb index e9fb875dd..7357c9267 100644 --- a/config/initializers/active_storage.rb +++ b/config/initializers/active_storage.rb @@ -1,3 +1,9 @@ ActiveStorage::Service.url_expires_in = 1.hour +# In Rails 5.2, we have to hook at `on_load` on the blob themeselves, which is +# not ideal. +# +# Rails 6 adds support for `.on_load(:active_storage_attachment)`, which is +# cleaner (as it allows to enqueue the virus scan on attachment creation, rather +# than on blob creation). ActiveSupport.on_load(:active_storage_blob) { include BlobVirusScanner }