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

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(controller, user_class = User) ⇒ AuditingAdapter

Returns a new instance of AuditingAdapter.



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

#create_object(message, object, abstract_model, user) ⇒ Object



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

#delete_object(message, object, model, user) ⇒ Object



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

#latestObject



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

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



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.page(page.presence || "1").per(per_page)
  versions.map{|version| VersionProxy.new(version, @user_class)}
end

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



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.page(page.presence || "1").per(per_page)
  versions.map{|version| VersionProxy.new(version, @user_class)}
end

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



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