Sha256: b3681690b4a3b0d2534b35918520f7636288a170a22b88a07cdeea03055d0190

Contents?: true

Size: 892 Bytes

Versions: 28

Compression:

Stored size: 892 Bytes

Contents

# frozen_string_literal: true

module EffectiveLogging
  module ActiveStorageLogger

    def track_downloads
      return if EffectiveLogging.supressed?

      user = current_user if respond_to?(:current_user)

      key = decode_verified_key()
      return unless key.present?
      return if (key[:content_type] || '').starts_with?('image')

      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

28 entries across 28 versions & 1 rubygems

Version Path
effective_logging-3.1.15 lib/effective_logging/active_storage_logger.rb
effective_logging-3.1.14 lib/effective_logging/active_storage_logger.rb
effective_logging-3.1.13 lib/effective_logging/active_storage_logger.rb
effective_logging-3.1.12 lib/effective_logging/active_storage_logger.rb
effective_logging-3.1.11 lib/effective_logging/active_storage_logger.rb
effective_logging-3.1.10 lib/effective_logging/active_storage_logger.rb
effective_logging-3.1.9 lib/effective_logging/active_storage_logger.rb
effective_logging-3.1.8 lib/effective_logging/active_storage_logger.rb