<commit_before>if defined?(EffectiveDatatables)
  module Effective
    module Datatables
      class Logs < Effective::Datatable
        include EffectiveLoggingHelper

        datatable do
          default_order :created_at, :desc

          table_column :created_at
          table_column :id, visible: false

          unless attributes[:user_id] || attributes[:user] || (attributes[:user] == false)
            table_column :user
          end

          unless attributes[:status] == false
            table_column :status, filter: { type: :select, values: EffectiveLogging.statuses }
          end

          table_column :associated_type, visible: false
          table_column :associated_id, visible: false, label: 'Associated Id'
          table_column :associated_to_s, label: 'Associated'

          table_column :message do |log|
            log.message.starts_with?("\t") ? log.message.gsub("\t", "&nbsp;&nbsp;") : log.message
          end

          table_column :logs_count, visible: false

          table_column :details, visible: false, sortable: false do |log|
            tableize_hash(log.details.except(:email), th: true, sub_th: false, width: '100%')
          end

          table_column :updated_at, visible: false

          unless attributes[:actions] == false
            actions_column partial: 'admin/logs/actions', partial_local: :log
          end
        end

        # A nil attributes[:log_id] means give me all the top level log entries
        # If we set a log_id then it's for sub logs
        def collection
          collection = Effective::Log.unscoped.where(parent_id: attributes[:log_id]).includes(:user, :associated)

          if attributes[:log_changes]
            collection = collection.where(status: EffectiveLogging.log_changes_status)
          end

          if (attributes[:user] || attributes[:user_id]).present?
            user_id = attributes[:user_id] || (attributes[:user].kind_of?(User) ? attributes[:user].id : attributes[:user].to_i)
            collection = collection.where('user_id = ? OR (associated_id = ? AND associated_type = ?)', user_id, user_id, 'User')
          end

          if attributes[:associated_id] && attributes[:associated_type]
            collection = collection.where(associated_id: attributes[:associated_id], associated_type: attributes[:associated_type])
          end

          if attributes[:associated]
            collection = collection.where(associated: attributes[:associated])
          end

          collection
        end

      end
    end
  end
end
<commit_msg>Include user table_column in user specific logs<commit_after>if defined?(EffectiveDatatables)
  module Effective
    module Datatables
      class Logs < Effective::Datatable
        include EffectiveLoggingHelper

        datatable do
          default_order :created_at, :desc

          table_column :created_at
          table_column :id, visible: false

          if attributes[:user] == false
            # Do not include
          elsif attributes[:user_id].present?
            table_column :user, filter: { collection: User.where(id: Array(attributes[:user_id])) }
          elsif attributes[:user].present?
            table_column :user, filter: { collection: User.where(id: Array(attributes[:user]).map { |user| user.to_param }) }
          else
            table_column :user
          end

          unless attributes[:status] == false
            table_column :status, filter: { type: :select, values: EffectiveLogging.statuses }
          end

          table_column :associated_type, visible: false
          table_column :associated_id, visible: false, label: 'Associated Id'
          table_column :associated_to_s, label: 'Associated'

          table_column :message do |log|
            log.message.starts_with?("\t") ? log.message.gsub("\t", "&nbsp;&nbsp;") : log.message
          end

          table_column :logs_count, visible: false

          table_column :details, visible: false, sortable: false do |log|
            tableize_hash(log.details.except(:email), th: true, sub_th: false, width: '100%')
          end

          table_column :updated_at, visible: false

          unless attributes[:actions] == false
            actions_column partial: 'admin/logs/actions', partial_local: :log
          end
        end

        # A nil attributes[:log_id] means give me all the top level log entries
        # If we set a log_id then it's for sub logs
        def collection
          collection = Effective::Log.unscoped.where(parent_id: attributes[:log_id]).includes(:user, :associated)

          if attributes[:log_changes]
            collection = collection.where(status: EffectiveLogging.log_changes_status)
          end

          if (attributes[:user] || attributes[:user_id]).present?
            user_ids = Array(attributes[:user].presence || attributes[:user_id]).map { |user| user.kind_of?(User) ? user.id : user.to_i }
            collection = collection.where('user_id IN (?) OR (associated_id IN (?) AND associated_type = ?)', user_ids, user_ids, 'User')
          end

          if attributes[:associated_id] && attributes[:associated_type]
            collection = collection.where(associated_id: attributes[:associated_id], associated_type: attributes[:associated_type])
          end

          if attributes[:associated]
            collection = collection.where(associated: attributes[:associated])
          end

          collection
        end

      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09914498817536838, 'fraction_numerical': 0.0010915044569765327, 'mean_word_length': 2.537966537966538, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7645299', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1414, 'n_words': 374}