Class: Effective::LogsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/effective/logs_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

This is a post from our Javascript



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/effective/logs_controller.rb', line 12

def create
  EffectiveLogging.authorized?(self, :create, Effective::Log.new())

  @log = Effective::Log.new().tap do |log|
    log.message = log_params[:message]
    log.status = (EffectiveLogging.statuses.include?(log_params[:status]) ? log_params[:status] : 'info')
    log.user = (current_user rescue nil)

    count = -1
    Array((JSON.parse(log_params[:details]) rescue [])).flatten(1).each do |obj|
      if obj.kind_of?(Hash)
        obj.each { |k, v| log.details[k] = v if v.present? }
      else
        log.details["param_#{(count += 1)}"] = obj if obj.present?
      end
    end

    # Match the referrer
    log.details[:ip] ||= request.ip
    log.details[:referrer] ||= request.referrer
    log.details[:user_agent] ||= request.user_agent

    log.save
  end

  render text: 'ok', status: :ok, json: {}
end

#html_partObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/effective/logs_controller.rb', line 70

def html_part
  @log = Effective::Log.find(params[:id])

  EffectiveLogging.authorized?(self, :show, @log)

  value = @log.details[(params[:key] || '').to_sym].to_s

  open = value.index('<!DOCTYPE html') || value.index('<html')
  close = value.rindex('</html>') if open.present?

  if open.present? && close.present?
    render inline: value[open...(close+7)].html_safe
  else
    render inline: value.html_safe
  end
end

#indexObject

This is the User index event



41
42
43
44
45
46
47
48
49
# File 'app/controllers/effective/logs_controller.rb', line 41

def index
  if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
    @datatable = Effective::Datatables::Logs.new(user_id: current_user.id)
  else
    @datatable = EffectiveLogsDatatable.new(self, user_id: current_user.id)
  end

  EffectiveLogging.authorized?(self, :index, Effective::Log.new(user_id: current_user.id))
end

#showObject

This is the User show event



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/effective/logs_controller.rb', line 52

def show
  @log = Effective::Log.includes(:logs).find(params[:id])
  @log.next_log = Effective::Log.unscoped.order(:id).where(parent_id: @log.parent_id).where('id > ?', @log.id).first
  @log.prev_log = Effective::Log.unscoped.order(:id).where(parent_id: @log.parent_id).where('id < ?', @log.id).last

  @page_title = "Log ##{@log.to_param}"

  if @log.logs.present?
    if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
      @log.datatable = Effective::Datatables::Logs.new(log_id: @log.id)
    else
      @log.datatable = EffectiveLogsDatatable.new(self, log_id: @log.id)
    end
  end

  EffectiveLogging.authorized?(self, :show, @log)
end