activeadmin-audit 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2eea25e963a62183de6ecfa5dbbb1ccdf1fe5fd2
4
- data.tar.gz: 26600c5639afb004e950447a9104c9a8600ae083
3
+ metadata.gz: 0e531041f918eba6555a4d60a8be881de0f5e21d
4
+ data.tar.gz: 47a35a6077e02a7cad49cccfd72ec7f2ced715c1
5
5
  SHA512:
6
- metadata.gz: 50af6f9fb5257b18c7845fd982aea7a3a618f7b5e0648799f538edb7f4afbf7b213efef0f5f15ed9aff11d141ddeeb5b46f8eb103072a4d5956097e0de4bbe5d
7
- data.tar.gz: b63c0beff362edc36238acb03e9b3a48a812982969bfd24605b3e65597ded857f2db5da579ef4247a3bedb24d07ba733d0fc0118439172973b24f404a4532bde
6
+ metadata.gz: 197e0bc999224d9017ccbef3e1e953ebd64068cdac8e0c0bafd104ecd72e7f80bf3a132bf8887d4b1db1f5d96287adf374b6ed5e72f90e3093b5297a303685e1
7
+ data.tar.gz: 6c22f3a836fa938c58d9ada37e00d1f8563c3d708a8e67bbdcf145ee96a31e31ddaeabed9d08f4c912861dd46bcab7fdb95c11daa7da4a28fe76884ab00c7fcc
data/README.md CHANGED
@@ -23,6 +23,26 @@ Or install it yourself as:
23
23
 
24
24
  $ gem install activeadmin-audit
25
25
 
26
+ ## Setting up Active Admin Audit (for Rails)
27
+
28
+ After installing the gem, you need to run the generator. Here are your options:
29
+
30
+ - If you want to use an existing user class, provide it as an argument:
31
+ ```sh
32
+ rails g active_admin_audit:install User
33
+ ```
34
+
35
+ - Otherwise, with no arguments we will create an `AdminUser` class to use with Devise:
36
+ ```sh
37
+ rails g active_admin_audit:install
38
+ ```
39
+
40
+ The generator adds these core files, among others:
41
+
42
+ ```
43
+ config/initializers/active_admin_audit.rb
44
+ ```
45
+
26
46
  ## Usage
27
47
 
28
48
  Copy and apply migrations
@@ -46,7 +66,7 @@ class ApplicationController < ActionController::Base
46
66
  end
47
67
  ```
48
68
 
49
- From model that you want to auditing call `has_versions` method
69
+ From model that you want to auditing call `has_versions` method
50
70
 
51
71
  ```ruby
52
72
  class Movie < ActiveRecord::Base
@@ -58,7 +78,7 @@ class Movie < ActiveRecord::Base
58
78
  images: [:url, :width, :height, :kind],
59
79
  }
60
80
  ```
61
-
81
+
62
82
  By default `has_versions` take care about all record attributes including belongs_to references. If you don't want to include some attribute you can pass it name to `skip` options. If you want to include has_many relation pass it's name with attributes to `also_include` option.
63
83
 
64
84
  To display table with latest changes on the ActiveAdmin resource page use helper `latest_versions`:
@@ -88,4 +108,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
88
108
  ## License
89
109
 
90
110
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
91
-
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ['lib']
21
21
 
22
22
  spec.add_dependency 'activeadmin', '>= 1.0.0.pre1'
23
- spec.add_dependency 'paper_trail', '~> 4.0.0'
23
+ spec.add_dependency 'paper_trail', '~> 5.0'
24
24
  spec.add_dependency 'rails', '>= 4.0.0'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.12'
@@ -5,7 +5,12 @@ ActiveAdmin.register ActiveAdmin::Audit::ContentVersion, as: 'ContentVersion' do
5
5
 
6
6
  filter :item_type, input_html: { class: 'chosen' }, as: :select
7
7
  filter :event, input_html: { class: 'chosen' }, as: :select
8
- filter :whodunnit, input_html: { class: 'chosen' }, as: :select, collection: -> { AdminUser.all.map { |u| [u.email, u.id] } }
8
+ filter :whodunnit, input_html: { class: 'chosen' }, as: :select,
9
+ collection: lambda {
10
+ ActiveAdmin::Audit.configuration.user_class_name.to_s.classify.constantize.all.map do |user|
11
+ [user.email, user.id]
12
+ end
13
+ }
9
14
  filter :created_at
10
15
 
11
16
  index do
@@ -53,4 +58,4 @@ ActiveAdmin.register ActiveAdmin::Audit::ContentVersion, as: 'ContentVersion' do
53
58
  additional_objects_snapshot: version.additional_objects_snapshot,
54
59
  }
55
60
  end
56
- end
61
+ end
@@ -29,7 +29,7 @@ module ActiveAdmin
29
29
  end
30
30
 
31
31
  def who
32
- AdminUser.find_by(id: whodunnit)
32
+ Audit.configuration.user_class_name.to_s.classify.constantize.find_by(id: whodunnit)
33
33
  end
34
34
 
35
35
  def item_class
@@ -45,4 +45,4 @@ module ActiveAdmin
45
45
  end
46
46
  end
47
47
  end
48
- end
48
+ end
@@ -1,4 +1,5 @@
1
1
  require 'active_admin'
2
+ require 'active_admin/audit/configuration'
2
3
  require 'active_admin/audit/version'
3
4
  require 'active_admin/audit/engine'
4
5
  require 'active_admin/audit/controller_helper'
@@ -9,5 +10,17 @@ require 'active_admin/versions_helper'
9
10
 
10
11
  module ActiveAdmin
11
12
  module Audit
13
+ class << self
14
+ attr_accessor :configuration
15
+
16
+ def configuration
17
+ @configuration ||= ::ActiveAdmin::Audit::Configuration.new
18
+ end
19
+
20
+ # Gets called within the initializer
21
+ def setup
22
+ yield(configuration)
23
+ end
24
+ end
12
25
  end
13
26
  end
@@ -0,0 +1,14 @@
1
+ module ActiveAdmin
2
+ module Audit
3
+ class Configuration
4
+ include ActiveAdmin::Settings
5
+
6
+ # == User class name
7
+ #
8
+ # Set the name of the class that is used as the AdminUser.
9
+ # Defaults to AdminUser
10
+ #
11
+ setting :user_class_name, :admin_user
12
+ end
13
+ end
14
+ end
@@ -2,7 +2,7 @@ module ActiveAdmin
2
2
  module Audit
3
3
  module ControllerHelper
4
4
  def user_for_paper_trail
5
- current_admin_user
5
+ send(ActiveAdmin.application.current_user_method)
6
6
  end
7
7
 
8
8
  def paper_trail_enabled_for_controller
@@ -10,4 +10,4 @@ module ActiveAdmin
10
10
  end
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -14,6 +14,10 @@ module ActiveAdmin
14
14
  module ActiveAdmin::ViewHelpers
15
15
  include ActiveAdmin::VersionsHelper
16
16
  end
17
+
18
+ ActiveAdmin.setup do |config|
19
+ config.before_filter :set_paper_trail_whodunnit
20
+ end
17
21
  end
18
22
 
19
23
  initializer 'active_record.set_configs' do
@@ -14,7 +14,7 @@ module ActiveAdmin
14
14
  options[:skip] += translated_attrs.map { |attr| "#{attr}_translations" }
15
15
  end
16
16
 
17
- has_paper_trail options.merge(on: [:nothing], class_name: 'ActiveAdmin::Audit::ContentVersion', meta: {
17
+ has_paper_trail options.merge(on: [], class_name: 'ActiveAdmin::Audit::ContentVersion', meta: {
18
18
  additional_objects: ->(record) { record.additional_objects_snapshot.to_json },
19
19
  additional_objects_changes: ->(record) { record.additional_objects_snapshot_changes.to_json },
20
20
  })
@@ -39,7 +39,7 @@ module ActiveAdmin
39
39
 
40
40
  # Will save new version of the object
41
41
  after_commit do
42
- if paper_trail_switched_on?
42
+ if paper_trail.enabled?
43
43
  if @event_for_paper_trail
44
44
  generate_version!
45
45
  end
@@ -50,7 +50,7 @@ module ActiveAdmin
50
50
 
51
51
  if options_on.include?(:create)
52
52
  after_create do
53
- if paper_trail_switched_on?
53
+ if paper_trail.enabled?
54
54
  @event_for_paper_trail = 'create'
55
55
  end
56
56
  end
@@ -59,7 +59,7 @@ module ActiveAdmin
59
59
  if options_on.include?(:update)
60
60
  # Cache object changes to access it from after_commit
61
61
  after_update do
62
- if paper_trail_switched_on?
62
+ if paper_trail.enabled?
63
63
  @event_for_paper_trail = 'update'
64
64
  cache_version_object_changes
65
65
  end
@@ -69,7 +69,7 @@ module ActiveAdmin
69
69
  if options_on.include?(:destroy)
70
70
  # Cache all details to access it from after_commit
71
71
  before_destroy do
72
- if paper_trail_switched_on?
72
+ if paper_trail.enabled?
73
73
  @event_for_paper_trail = 'destroy'
74
74
  cache_version_object
75
75
  cache_version_object_changes
@@ -97,15 +97,15 @@ module ActiveAdmin
97
97
  private
98
98
 
99
99
  def cache_version_object
100
- @version_object_cache ||= object_attrs_for_paper_trail(self.attributes)
100
+ @version_object_cache ||= paper_trail.object_attrs_for_paper_trail
101
101
  end
102
102
 
103
103
  def cache_version_object_changes
104
- @version_object_changes_cache ||= changes_for_paper_trail
104
+ @version_object_changes_cache ||= paper_trail.changes
105
105
  end
106
106
 
107
107
  def cache_version_additional_objects_and_changes
108
- @version_additional_objects_and_changes_cache ||= merge_metadata({})
108
+ @version_additional_objects_and_changes_cache ||= paper_trail.merge_metadata({})
109
109
  end
110
110
 
111
111
  def clear_version_cache
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module Audit
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
@@ -0,0 +1,17 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module ActiveAdminAudit
4
+ module Generators
5
+ class InstallGenerator < ActiveRecord::Generators::Base
6
+ desc "Installs Active Admin Audit and generates the necessary configurations"
7
+ argument :name, type: :string, default: "AdminUser"
8
+
9
+ source_root File.expand_path("../templates", __FILE__)
10
+
11
+ def copy_initializer
12
+ @underscored_user_name = name.underscore.gsub('/', '_')
13
+ template 'active_admin.audit.rb.erb', 'config/initializers/active_admin_audit.rb'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ ActiveAdmin::Audit.setup do |config|
2
+ # == User class name
3
+ #
4
+ # Set the name of the class that is used as the AdminUser.
5
+ # Defaults to AdminUser
6
+ #
7
+ config.user_class_name = :<%= @underscored_user_name %>
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-audit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Emelyanov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-08 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 4.0.0
33
+ version: '5.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 4.0.0
40
+ version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -218,6 +218,7 @@ files:
218
218
  - bin/setup
219
219
  - db/migrate/20141219113159_create_versions.rb
220
220
  - lib/active_admin/audit.rb
221
+ - lib/active_admin/audit/configuration.rb
221
222
  - lib/active_admin/audit/controller_helper.rb
222
223
  - lib/active_admin/audit/engine.rb
223
224
  - lib/active_admin/audit/has_versions.rb
@@ -226,6 +227,8 @@ files:
226
227
  - lib/active_admin/versions_helper.rb
227
228
  - lib/active_admin/views/latest_versions.rb
228
229
  - lib/activeadmin/audit.rb
230
+ - lib/generators/active_admin_audit/install_generator.rb
231
+ - lib/generators/active_admin_audit/templates/active_admin.audit.rb.erb
229
232
  homepage: https://github.com/holyketzer/activeadmin-audit
230
233
  licenses:
231
234
  - MIT
@@ -246,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
249
  version: '0'
247
250
  requirements: []
248
251
  rubyforge_project:
249
- rubygems_version: 2.5.1
252
+ rubygems_version: 2.6.8
250
253
  signing_key:
251
254
  specification_version: 4
252
255
  summary: PaperTrail based audit for ActiveAdmin