Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard audit improvements #2982

Merged
merged 3 commits into from
Feb 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rails_admin/config/actions/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ class Dashboard < RailsAdmin::Config::Actions::Base
nil
end

register_instance_option :auditing_versions_limit do
50
end

register_instance_option :controller do
proc do
@history = @auditing_adapter && @auditing_adapter.latest || []
@history = @auditing_adapter && @auditing_adapter.latest(@action.auditing_versions_limit) || []
if @action.statistics?
@abstract_models = RailsAdmin::Config.visible_models(controller: self).collect(&:abstract_model)

Expand Down
4 changes: 2 additions & 2 deletions lib/rails_admin/extensions/history/auditing_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def initialize(controller, user_class = User)
require 'rails_admin/extensions/history/history'
end

def latest
::RailsAdmin::History.latest
def latest(count = 100)
::RailsAdmin::History.latest(count)
end

def delete_object(object, model, user)
Expand Down
4 changes: 2 additions & 2 deletions lib/rails_admin/extensions/history/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class History < ActiveRecord::Base
default_scope { order('id DESC') }

class << self
def latest
limit(100)
def latest(count = 100)
limit(count)
end

def create_history_item(message, object, abstract_model, user)
Expand Down
6 changes: 4 additions & 2 deletions lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ def initialize(controller, user_class = 'User', version_class = '::Version')
end
end

def latest
@version_class.order('id DESC').limit(100).collect { |version| VersionProxy.new(version, @user_class) }
def latest(count = 100)
@version_class.
order(id: :desc).includes(:item).limit(count).
collect { |version| VersionProxy.new(version, @user_class) }
end

def delete_object(_object, _model, _user)
Expand Down