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-4.3.1 lib/effective_logging/active_storage_logger.rb
effective_logging-4.3.0 lib/effective_logging/active_storage_logger.rb
effective_logging-4.2.0 lib/effective_logging/active_storage_logger.rb
effective_logging-4.1.3 lib/effective_logging/active_storage_logger.rb
effective_logging-4.1.2 lib/effective_logging/active_storage_logger.rb
effective_logging-4.1.1 lib/effective_logging/active_storage_logger.rb
effective_logging-4.1.0 lib/effective_logging/active_storage_logger.rb
effective_logging-4.0.0 lib/effective_logging/active_storage_logger.rb
effective_logging-3.5.4 lib/effective_logging/active_storage_logger.rb
effective_logging-3.5.3 lib/effective_logging/active_storage_logger.rb
effective_logging-3.5.2 lib/effective_logging/active_storage_logger.rb
effective_logging-3.5.1 lib/effective_logging/active_storage_logger.rb
effective_logging-3.5.0 lib/effective_logging/active_storage_logger.rb
effective_logging-3.4.1 lib/effective_logging/active_storage_logger.rb
effective_logging-3.4.0 lib/effective_logging/active_storage_logger.rb
effective_logging-3.3.0 lib/effective_logging/active_storage_logger.rb
effective_logging-3.2.3 lib/effective_logging/active_storage_logger.rb
effective_logging-3.2.2 lib/effective_logging/active_storage_logger.rb
effective_logging-3.2.1 lib/effective_logging/active_storage_logger.rb
effective_logging-3.2.0 lib/effective_logging/active_storage_logger.rb