Sha256: d1218ef9e99b8f5ea1c74275cfa36b94b6d1f868386f4250f9efd75f9c4146a9

Contents?: true

Size: 751 Bytes

Versions: 2

Compression:

Stored size: 751 Bytes

Contents

module EffectiveLogging
  module ActiveStorageLogger

    def track_downloads
      user = current_user if respond_to?(:current_user)

      key = decode_verified_key()
      return unless key.present?

      blob = ActiveStorage::Blob.where(key: key[:key]).first
      return unless blob.present?

      blob.attachments.each do |attachment|
        next if attachment.name == 'embeds'
        next if attachment.record_type == 'ActionText::RichText'

        associated = attachment.record
        filename = blob.filename.to_s
        message = [associated.to_s, filename.to_s].uniq.join(' ')

        EffectiveLogger.download(message, associated: associated, associated_to_s: filename, filename: filename, user: user)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
effective_logging-3.1.3 lib/effective_logging/active_storage_logger.rb
effective_logging-3.1.2 lib/effective_logging/active_storage_logger.rb