Class: RailsAdmin::Extensions::PaperTrail::AuditingAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_admin/extensions/paper_trail/auditing_adapter.rb

Constant Summary

COLUMN_MAPPING =
{
  :table => :item_type,
  :username => :whodunnit,
  :item => :item_id,
  :created_at => :created_at,
  :message => :event
}

Instance Method Summary (collapse)

Constructor Details

- (AuditingAdapter) initialize(controller, user_class = User)



40
41
42
43
44
# File 'lib/rails_admin/extensions/paper_trail/auditing_adapter.rb', line 40

def initialize(controller, user_class = User)
  raise "PaperTrail not found" unless defined?(PaperTrail)
  @controller = controller
  @user_class = user_class
end

Instance Method Details

- (Object) create_object(message, object, abstract_model, user)



58
59
60
# File 'lib/rails_admin/extensions/paper_trail/auditing_adapter.rb', line 58

def create_object(message, object, abstract_model, user)
  # do nothing
end

- (Object) delete_object(message, object, model, user)



50
51
52
# File 'lib/rails_admin/extensions/paper_trail/auditing_adapter.rb', line 50

def delete_object(message, object, model, user)
  # do nothing
end

- (Object) latest



46
47
48
# File 'lib/rails_admin/extensions/paper_trail/auditing_adapter.rb', line 46

def latest
  ::Version.limit(100).map{|version| VersionProxy.new(version, @user_class)}
end

- (Object) listing_for_model(model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rails_admin/extensions/paper_trail/auditing_adapter.rb', line 62

def listing_for_model(model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
  if sort.present?
    sort = COLUMN_MAPPING[sort.to_sym]
  else
    sort = :created_at
    sort_reverse = "true"
  end
  versions = ::Version.where :item_type => model.model.name
  versions = versions.where("event LIKE ?", "%#{query}%") if query.present?
  versions = versions.order(sort_reverse == "true" ? "#{sort} DESC" : sort)
  versions = all ? versions : versions.send(Kaminari.config.page_method_name, page.presence || "1").per(per_page)
  versions.map{|version| VersionProxy.new(version, @user_class)}
end

- (Object) listing_for_object(model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rails_admin/extensions/paper_trail/auditing_adapter.rb', line 76

def listing_for_object(model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
  if sort.present?
    sort = COLUMN_MAPPING[sort.to_sym]
  else
    sort = :created_at
    sort_reverse = "true"
  end
  versions = ::Version.where :item_type => model.model.name, :item_id => object.id
  versions = versions.where("event LIKE ?", "%#{query}%") if query.present?
  versions = versions.order(sort_reverse == "true" ? "#{sort} DESC" : sort)
  versions = all ? versions : versions.send(Kaminari.config.page_method_name, page.presence || "1").per(per_page)
  versions.map{|version| VersionProxy.new(version, @user_class)}
end

- (Object) update_object(model, object, associations_before, associations_after, modified_associations, old_object, user)



54
55
56
# File 'lib/rails_admin/extensions/paper_trail/auditing_adapter.rb', line 54

def update_object(model, object, associations_before, associations_after, modified_associations, old_object, user)
  # do nothing
end