audited 4.7.1 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of audited might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.standard.yml +5 -0
- data/.travis.yml +35 -26
- data/Appraisals +27 -18
- data/CHANGELOG.md +97 -4
- data/Gemfile +1 -1
- data/README.md +88 -19
- data/Rakefile +6 -6
- data/gemfiles/rails50.gemfile +3 -0
- data/gemfiles/rails51.gemfile +3 -0
- data/gemfiles/rails52.gemfile +3 -1
- data/gemfiles/rails60.gemfile +10 -0
- data/gemfiles/rails61.gemfile +10 -0
- data/lib/audited-rspec.rb +3 -1
- data/lib/audited.rb +26 -8
- data/lib/audited/audit.rb +48 -43
- data/lib/audited/auditor.rb +137 -57
- data/lib/audited/railtie.rb +16 -0
- data/lib/audited/rspec_matchers.rb +5 -3
- data/lib/audited/sweeper.rb +3 -10
- data/lib/audited/version.rb +3 -1
- data/lib/generators/audited/install_generator.rb +9 -7
- data/lib/generators/audited/migration.rb +2 -0
- data/lib/generators/audited/migration_helper.rb +3 -1
- data/lib/generators/audited/templates/add_association_to_audits.rb +2 -0
- data/lib/generators/audited/templates/add_comment_to_audits.rb +2 -0
- data/lib/generators/audited/templates/add_remote_address_to_audits.rb +2 -0
- data/lib/generators/audited/templates/add_request_uuid_to_audits.rb +2 -0
- data/lib/generators/audited/templates/add_version_to_auditable_index.rb +23 -0
- data/lib/generators/audited/templates/install.rb +3 -1
- data/lib/generators/audited/templates/rename_association_to_associated.rb +2 -0
- data/lib/generators/audited/templates/rename_changes_to_audited_changes.rb +2 -0
- data/lib/generators/audited/templates/rename_parent_to_association.rb +2 -0
- data/lib/generators/audited/templates/revert_polymorphic_indexes_order.rb +2 -0
- data/lib/generators/audited/upgrade_generator.rb +20 -14
- data/spec/audited/audit_spec.rb +151 -62
- data/spec/audited/auditor_spec.rb +456 -239
- data/spec/audited/sweeper_spec.rb +29 -20
- data/spec/audited_spec.rb +18 -0
- data/spec/audited_spec_helpers.rb +7 -7
- data/spec/rails_app/app/assets/config/manifest.js +2 -0
- data/spec/rails_app/config/application.rb +7 -2
- data/spec/rails_app/config/database.yml +1 -0
- data/spec/rails_app/config/environment.rb +1 -1
- data/spec/rails_app/config/environments/test.rb +5 -5
- data/spec/rails_app/config/initializers/secret_token.rb +2 -2
- data/spec/spec_helper.rb +15 -13
- data/spec/support/active_record/models.rb +37 -11
- data/spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb +1 -2
- data/spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb +1 -2
- data/spec/support/active_record/schema.rb +28 -20
- data/test/db/version_1.rb +2 -2
- data/test/db/version_2.rb +2 -2
- data/test/db/version_3.rb +2 -3
- data/test/db/version_4.rb +2 -3
- data/test/db/version_5.rb +0 -1
- data/test/db/version_6.rb +2 -0
- data/test/install_generator_test.rb +18 -19
- data/test/test_helper.rb +6 -7
- data/test/upgrade_generator_test.rb +22 -17
- metadata +64 -29
- data/gemfiles/rails40.gemfile +0 -9
- data/gemfiles/rails41.gemfile +0 -8
- data/gemfiles/rails42.gemfile +0 -8
- data/spec/rails_app/config/environments/development.rb +0 -21
- data/spec/rails_app/config/environments/production.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f924caa522dc6d65c88066c2d28416dfcef844efa85bdef056da226db12a8984
|
4
|
+
data.tar.gz: 63bdef3cd4aefea080eb36e6b7c394f5d97b465e3376027a68e3c28f1b278d5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acbc5581e27594c84ad817ac7e2f90e02d34786106689a943177552890205d4acfaa5a7ac5489b1a0fbdbc5196028d462e4540d5253ee78b2612bc8f03abfcad
|
7
|
+
data.tar.gz: 532724043c0c57659a3c3f3d0eaf21c832a6c3863a8607bb802d882bf13b4579e8b051265e6c4082a51bdbc2291f7466508e03c7cb67df90bda6b8c234a6d7a4
|
data/.gitignore
CHANGED
data/.standard.yml
ADDED
data/.travis.yml
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.
|
4
|
+
- 2.3.8
|
5
|
+
- 2.4.10
|
6
|
+
- 2.5.9
|
7
|
+
- 2.6.7
|
8
|
+
- 2.7.3
|
9
|
+
- 3.0.1
|
9
10
|
- ruby-head
|
10
11
|
env:
|
11
12
|
- DB=SQLITE
|
@@ -13,46 +14,54 @@ env:
|
|
13
14
|
- DB=MYSQL
|
14
15
|
addons:
|
15
16
|
postgresql: "9.4"
|
17
|
+
services:
|
18
|
+
- mysql
|
16
19
|
before_install:
|
17
20
|
# https://github.com/travis-ci/travis-ci/issues/8978
|
18
21
|
- "travis_retry gem update --system"
|
19
|
-
- "travis_retry gem install bundler"
|
20
22
|
gemfile:
|
21
|
-
- gemfiles/rails40.gemfile
|
22
|
-
- gemfiles/rails41.gemfile
|
23
|
-
- gemfiles/rails42.gemfile
|
24
23
|
- gemfiles/rails50.gemfile
|
25
24
|
- gemfiles/rails51.gemfile
|
26
25
|
- gemfiles/rails52.gemfile
|
26
|
+
- gemfiles/rails60.gemfile
|
27
|
+
- gemfiles/rails61.gemfile
|
27
28
|
matrix:
|
28
|
-
|
29
|
-
- rvm:
|
29
|
+
include:
|
30
|
+
- rvm: 2.6.7
|
31
|
+
script: bundle exec standardrb
|
32
|
+
env: DB=standard # make travis build display nicer
|
30
33
|
exclude:
|
31
|
-
- rvm: 2.
|
34
|
+
- rvm: 2.3.8
|
35
|
+
gemfile: gemfiles/rails61.gemfile
|
36
|
+
- rvm: 2.4.10
|
37
|
+
gemfile: gemfiles/rails61.gemfile
|
38
|
+
- rvm: 2.3.8
|
39
|
+
gemfile: gemfiles/rails60.gemfile
|
40
|
+
- rvm: 2.4.10
|
41
|
+
gemfile: gemfiles/rails60.gemfile
|
42
|
+
- rvm: 2.6.7
|
43
|
+
gemfile: gemfiles/rails42.gemfile
|
44
|
+
- rvm: 2.7.3
|
45
|
+
gemfile: gemfiles/rails42.gemfile
|
46
|
+
- rvm: 3.0.1
|
47
|
+
gemfile: gemfiles/rails42.gemfile
|
48
|
+
- rvm: 3.0.1
|
32
49
|
gemfile: gemfiles/rails50.gemfile
|
33
|
-
- rvm:
|
50
|
+
- rvm: 3.0.1
|
34
51
|
gemfile: gemfiles/rails51.gemfile
|
35
|
-
- rvm:
|
52
|
+
- rvm: 3.0.1
|
36
53
|
gemfile: gemfiles/rails52.gemfile
|
37
|
-
- rvm: 2.4.3
|
38
|
-
gemfile: gemfiles/rails40.gemfile
|
39
|
-
- rvm: 2.4.3
|
40
|
-
gemfile: gemfiles/rails41.gemfile
|
41
|
-
- rvm: 2.5.0
|
42
|
-
gemfile: gemfiles/rails40.gemfile
|
43
|
-
- rvm: 2.5.0
|
44
|
-
gemfile: gemfiles/rails41.gemfile
|
45
54
|
- rvm: ruby-head
|
46
|
-
gemfile: gemfiles/
|
55
|
+
gemfile: gemfiles/rails42.gemfile
|
56
|
+
allow_failures:
|
47
57
|
- rvm: ruby-head
|
48
|
-
gemfile: gemfiles/rails41.gemfile
|
49
58
|
fast_finish: true
|
50
59
|
branches:
|
51
60
|
only:
|
52
61
|
- master
|
53
|
-
|
62
|
+
- /.*-stable$/
|
54
63
|
notifications:
|
55
64
|
webhooks:
|
56
65
|
urls:
|
57
|
-
-
|
66
|
+
- https://buildlight.collectiveidea.com/
|
58
67
|
on_start: always
|
data/Appraisals
CHANGED
@@ -1,28 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
gem 'protected_attributes'
|
4
|
-
gem 'test-unit'
|
5
|
-
end
|
1
|
+
# Include DB adapters matching the version requirements in
|
2
|
+
# rails/activerecord/lib/active_record/connection_adapters/*adapter.rb
|
6
3
|
|
7
|
-
appraise
|
8
|
-
gem
|
9
|
-
gem
|
4
|
+
appraise "rails50" do
|
5
|
+
gem "rails", "~> 5.0.0"
|
6
|
+
gem "mysql2", ">= 0.3.18", "< 0.6.0"
|
7
|
+
gem "pg", ">= 0.18", "< 2.0"
|
8
|
+
gem "sqlite3", "~> 1.3.6"
|
10
9
|
end
|
11
10
|
|
12
|
-
appraise
|
13
|
-
gem
|
14
|
-
gem
|
11
|
+
appraise "rails51" do
|
12
|
+
gem "rails", "~> 5.1.4"
|
13
|
+
gem "mysql2", ">= 0.3.18", "< 0.6.0"
|
14
|
+
gem "pg", ">= 0.18", "< 2.0"
|
15
|
+
gem "sqlite3", "~> 1.3.6"
|
15
16
|
end
|
16
17
|
|
17
|
-
appraise
|
18
|
-
gem
|
18
|
+
appraise "rails52" do
|
19
|
+
gem "rails", ">= 5.2.0", "< 5.3"
|
20
|
+
gem "mysql2", ">= 0.4.4", "< 0.6.0"
|
21
|
+
gem "pg", ">= 0.18", "< 2.0"
|
22
|
+
gem "sqlite3", "~> 1.3.6"
|
19
23
|
end
|
20
24
|
|
21
|
-
appraise
|
22
|
-
gem
|
25
|
+
appraise "rails60" do
|
26
|
+
gem "rails", ">= 6.0.0", "< 6.1"
|
27
|
+
gem "mysql2", ">= 0.4.4"
|
28
|
+
gem "pg", ">= 0.18", "< 2.0"
|
29
|
+
gem "sqlite3", "~> 1.4"
|
23
30
|
end
|
24
31
|
|
25
|
-
appraise
|
26
|
-
gem
|
27
|
-
gem
|
32
|
+
appraise "rails61" do
|
33
|
+
gem "rails", ">= 6.1.0", "< 6.2"
|
34
|
+
gem "mysql2", ">= 0.4.4"
|
35
|
+
gem "pg", ">= 1.1", "< 2.0"
|
36
|
+
gem "sqlite3", "~> 1.4"
|
28
37
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,78 @@
|
|
1
1
|
# Audited ChangeLog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 5.0.1 (2021-06-11)
|
4
|
+
|
5
|
+
Improved
|
6
|
+
|
7
|
+
- Don't load associated model when auditing is disabled - @nut4k1
|
8
|
+
[#584](https://github.com/collectiveidea/audited/pull/584)
|
9
|
+
|
10
|
+
## 5.0.0 (2021-06-10)
|
11
|
+
|
12
|
+
Improved
|
13
|
+
|
14
|
+
- Fixes an issue where array attributes were not deserialized properly - @cfeckardt, @yuki24
|
15
|
+
[#448](https://github.com/collectiveidea/audited/pull/448)
|
16
|
+
[#576](https://github.com/collectiveidea/audited/pull/576)
|
17
|
+
- Improve error message on audit_comment and allow for i18n override - @james
|
18
|
+
[#523](https://github.com/collectiveidea/audited/pull/523/)
|
19
|
+
- Don't require a comment if only non-audited fields are changed - @james
|
20
|
+
[#522](https://github.com/collectiveidea/audited/pull/522/)
|
21
|
+
- Readme updates - @gourshete
|
22
|
+
[#525](https://github.com/collectiveidea/audited/pull/525)
|
23
|
+
- Allow restoring previous enum behavior with flag - @travisofthenorth
|
24
|
+
[#526](https://github.com/collectiveidea/audited/pull/526)
|
25
|
+
- Follow Rails Autoloading conventions - @duncanjbrown
|
26
|
+
[#532](https://github.com/collectiveidea/audited/pull/532)
|
27
|
+
- Fix own_and_associated_audits for STI Models - @eric-hemasystems
|
28
|
+
[#533](https://github.com/collectiveidea/audited/pull/533)
|
29
|
+
- Rails 6.1 Improvements - @okuramasafumi, @marcrohloff
|
30
|
+
[#563](https://github.com/collectiveidea/audited/pull/563)
|
31
|
+
[#544](https://github.com/collectiveidea/audited/pull/544)
|
32
|
+
- Use Thread local variables instead of Fibers - @arathunku
|
33
|
+
[#568](https://github.com/collectiveidea/audited/pull/568)
|
34
|
+
|
35
|
+
Changed
|
36
|
+
|
37
|
+
- Drop support for Rails 4 - @travisofthenorth
|
38
|
+
[#527](https://github.com/collectiveidea/audited/pull/527)
|
39
|
+
|
40
|
+
## 4.10.0 (2021-01-07)
|
41
|
+
|
42
|
+
Added
|
43
|
+
|
44
|
+
- Add redacted option
|
45
|
+
[#485](https://github.com/collectiveidea/audited/pull/485)
|
46
|
+
- Rails 6.1. support
|
47
|
+
[#554](https://github.com/collectiveidea/audited/pull/554)
|
48
|
+
[#559](https://github.com/collectiveidea/audited/pull/559)
|
49
|
+
|
50
|
+
Improved
|
51
|
+
|
52
|
+
- Avoid extra query on first audit version
|
53
|
+
[#513](https://github.com/collectiveidea/audited/pull/513)
|
54
|
+
|
55
|
+
|
56
|
+
## 4.9.0 (2019-07-17)
|
4
57
|
|
5
58
|
Breaking changes
|
6
59
|
|
7
|
-
-
|
60
|
+
- removed block support for `Audit.reconstruct_attributes`
|
61
|
+
[#437](https://github.com/collectiveidea/audited/pull/437)
|
62
|
+
- removed `audited_columns`, `non_audited_columns`, `auditing_enabled=` instance methods,
|
63
|
+
use class methods instead
|
64
|
+
[#424](https://github.com/collectiveidea/audited/pull/424)
|
65
|
+
- removed rails 4.1 and 4.0 support
|
66
|
+
[#431](https://github.com/collectiveidea/audited/pull/431)
|
8
67
|
|
9
68
|
Added
|
10
69
|
|
11
|
-
-
|
70
|
+
- Add `with_auditing` methods to enable temporarily
|
71
|
+
[#502](https://github.com/collectiveidea/audited/pull/502)
|
72
|
+
- Add `update_with_comment_only` option to control audit creation with only comments
|
73
|
+
[#327](https://github.com/collectiveidea/audited/pull/327)
|
74
|
+
- Support for Rails 6.0 and Ruby 2.6
|
75
|
+
[#494](https://github.com/collectiveidea/audited/pull/494)
|
12
76
|
|
13
77
|
Changed
|
14
78
|
|
@@ -16,7 +80,36 @@ Changed
|
|
16
80
|
|
17
81
|
Fixed
|
18
82
|
|
19
|
-
-
|
83
|
+
- Ensure enum changes are stored consistently
|
84
|
+
[#429](https://github.com/collectiveidea/audited/pull/429)
|
85
|
+
|
86
|
+
## 4.8.0 (2018-08-19)
|
87
|
+
|
88
|
+
Breaking changes
|
89
|
+
|
90
|
+
- None
|
91
|
+
|
92
|
+
Added
|
93
|
+
|
94
|
+
- Add ability to globally disable auditing
|
95
|
+
[#426](https://github.com/collectiveidea/audited/pull/426)
|
96
|
+
- Add `own_and_associated_audits` method to auditable models
|
97
|
+
[#428](https://github.com/collectiveidea/audited/pull/428)
|
98
|
+
- Ability to nest `as_user` within itself
|
99
|
+
[#450](https://github.com/collectiveidea/audited/pull/450)
|
100
|
+
- Private methods can now be used for conditional auditing
|
101
|
+
[#454](https://github.com/collectiveidea/audited/pull/454)
|
102
|
+
|
103
|
+
Changed
|
104
|
+
|
105
|
+
- Add version to `auditable_index`
|
106
|
+
[#427](https://github.com/collectiveidea/audited/pull/427)
|
107
|
+
- Rename audited resource revision `version` attribute to `audit_version` and deprecate `version` attribute
|
108
|
+
[#443](https://github.com/collectiveidea/audited/pull/443)
|
109
|
+
|
110
|
+
Fixed
|
111
|
+
|
112
|
+
- None
|
20
113
|
|
21
114
|
## 4.7.1 (2018-04-10)
|
22
115
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
-
Audited [![Build Status](https://secure.travis-ci.org/collectiveidea/audited.svg)](http://travis-ci.org/collectiveidea/audited) [![
|
1
|
+
Audited [![Build Status](https://secure.travis-ci.org/collectiveidea/audited.svg)](http://travis-ci.org/collectiveidea/audited) [![Code Climate](https://codeclimate.com/github/collectiveidea/audited.svg)](https://codeclimate.com/github/collectiveidea/audited) [![Security](https://hakiri.io/github/collectiveidea/audited/master.svg)](https://hakiri.io/github/collectiveidea/audited/master)
|
2
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
|
2
3
|
=======
|
3
4
|
|
4
5
|
**Audited** (previously acts_as_audited) is an ORM extension that logs all changes to your models. Audited can also record who made those changes, save comments and associate models related to the changes.
|
5
6
|
|
6
|
-
Audited currently (4.x) works with Rails 5.2, 5.1, 5.0 and 4.2. It may work with 4.1 and 4.0, but this is not guaranteed.
|
7
7
|
|
8
|
+
Audited currently (5.x) works with Rails 6.1, 6.0, 5.2, 5.1, and 5.0.
|
9
|
+
|
10
|
+
For Rails 4, use gem version 4.x
|
8
11
|
For Rails 3, use gem version 3.0 or see the [3.0-stable branch](https://github.com/collectiveidea/audited/tree/3.0-stable).
|
9
12
|
|
10
13
|
## Supported Rubies
|
11
14
|
|
12
15
|
Audited supports and is [tested against](http://travis-ci.org/collectiveidea/audited) the following Ruby versions:
|
13
16
|
|
14
|
-
* 2.
|
15
|
-
* 2.
|
16
|
-
* 2.
|
17
|
-
* 2.
|
18
|
-
* 2.5.0
|
17
|
+
* 2.3.7
|
18
|
+
* 2.4.4
|
19
|
+
* 2.5.1
|
20
|
+
* 2.6.3
|
19
21
|
|
20
22
|
Audited may work just fine with a Ruby version not listed above, but we can't guarantee that it will. If you'd like to maintain a Ruby that isn't listed, please let us know with a [pull request](https://github.com/collectiveidea/audited/pulls).
|
21
23
|
|
@@ -28,7 +30,7 @@ Audited is currently ActiveRecord-only. In a previous life, Audited worked with
|
|
28
30
|
Add the gem to your Gemfile:
|
29
31
|
|
30
32
|
```ruby
|
31
|
-
gem "audited", "~> 4.
|
33
|
+
gem "audited", "~> 4.9"
|
32
34
|
```
|
33
35
|
|
34
36
|
Then, from your Rails app directory, create the `audits` table:
|
@@ -38,7 +40,9 @@ $ rails generate audited:install
|
|
38
40
|
$ rake db:migrate
|
39
41
|
```
|
40
42
|
|
41
|
-
If you're using PostgreSQL, then you can use `rails generate audited:install --audited-changes-column-type jsonb` (or `json`) to store audit changes natively with
|
43
|
+
By default changes are stored in YAML format. If you're using PostgreSQL, then you can use `rails generate audited:install --audited-changes-column-type jsonb` (or `json` for MySQL 5.7+ and Rails 5+) to store audit changes natively with database JSON column types.
|
44
|
+
|
45
|
+
If you're using something other than integer primary keys (e.g. UUID) for your User model, then you can use `rails generate audited:install --audited-user-id-column-type uuid` to customize the `audits` table `user_id` column type.
|
42
46
|
|
43
47
|
#### Upgrading
|
44
48
|
|
@@ -67,7 +71,7 @@ By default, whenever a user is created, updated or destroyed, a new audit is cre
|
|
67
71
|
```ruby
|
68
72
|
user = User.create!(name: "Steve")
|
69
73
|
user.audits.count # => 1
|
70
|
-
user.
|
74
|
+
user.update!(name: "Ryan")
|
71
75
|
user.audits.count # => 2
|
72
76
|
user.destroy
|
73
77
|
user.audits.count # => 3
|
@@ -76,7 +80,7 @@ user.audits.count # => 3
|
|
76
80
|
Audits contain information regarding what action was taken on the model and what changes were made.
|
77
81
|
|
78
82
|
```ruby
|
79
|
-
user.
|
83
|
+
user.update!(name: "Ryan")
|
80
84
|
audit = user.audits.last
|
81
85
|
audit.action # => "update"
|
82
86
|
audit.audited_changes # => {"name"=>["Steve", "Ryan"]}
|
@@ -130,7 +134,7 @@ end
|
|
130
134
|
You can attach comments to each audit using an `audit_comment` attribute on your model.
|
131
135
|
|
132
136
|
```ruby
|
133
|
-
user.
|
137
|
+
user.update!(name: "Ryan", audit_comment: "Changing name, just because")
|
134
138
|
user.audits.last.comment # => "Changing name, just because"
|
135
139
|
```
|
136
140
|
|
@@ -142,9 +146,17 @@ class User < ActiveRecord::Base
|
|
142
146
|
end
|
143
147
|
```
|
144
148
|
|
149
|
+
You can update an audit only if audit_comment is present. You can optionally add the `:update_with_comment_only` option set to `false` to your `audited` call to turn this behavior off for all audits.
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
class User < ActiveRecord::Base
|
153
|
+
audited :update_with_comment_only => false
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
145
157
|
### Limiting stored audits
|
146
158
|
|
147
|
-
You can limit the number of audits stored for your model. To configure limiting for all audited models, put the following in an initializer:
|
159
|
+
You can limit the number of audits stored for your model. To configure limiting for all audited models, put the following in an initializer file (`config/initializers/audited.rb`):
|
148
160
|
|
149
161
|
```ruby
|
150
162
|
Audited.max_audits = 10 # keep only 10 latest audits
|
@@ -163,7 +175,7 @@ Whenever an object is updated or destroyed, extra audits are combined with newer
|
|
163
175
|
```ruby
|
164
176
|
user = User.create!(name: "Steve")
|
165
177
|
user.audits.count # => 1
|
166
|
-
user.
|
178
|
+
user.update!(name: "Ryan")
|
167
179
|
user.audits.count # => 2
|
168
180
|
user.destroy
|
169
181
|
user.audits.count # => 2
|
@@ -183,7 +195,7 @@ class PostsController < ApplicationController
|
|
183
195
|
end
|
184
196
|
```
|
185
197
|
|
186
|
-
To use a method other than `current_user`, put the following in an initializer:
|
198
|
+
To use a method other than `current_user`, put the following in an initializer file (`config/initializers/audited.rb`):
|
187
199
|
|
188
200
|
```ruby
|
189
201
|
Audited.current_user_method = :authenticated_user
|
@@ -193,16 +205,16 @@ Outside of a request, Audited can still record the user with the `as_user` metho
|
|
193
205
|
|
194
206
|
```ruby
|
195
207
|
Audited.audit_class.as_user(User.find(1)) do
|
196
|
-
post.
|
208
|
+
post.update!(title: "Hello, world!")
|
197
209
|
end
|
198
210
|
post.audits.last.user # => #<User id: 1>
|
199
211
|
```
|
200
212
|
|
201
213
|
The standard Audited install assumes your User model has an integer primary key type. If this isn't true (e.g. you're using UUID primary keys), you'll need to create a migration to update the `audits` table `user_id` column type. (See Installation above for generator flags if you'd like to regenerate the install migration.)
|
202
214
|
|
203
|
-
#### Custom
|
215
|
+
#### Custom Audit User
|
204
216
|
|
205
|
-
You might need to use a custom auditor from time to time.
|
217
|
+
You might need to use a custom auditor from time to time. This can be done by simply passing in a string:
|
206
218
|
|
207
219
|
```ruby
|
208
220
|
class ApplicationController < ActionController::Base
|
@@ -216,6 +228,25 @@ class ApplicationController < ActionController::Base
|
|
216
228
|
end
|
217
229
|
```
|
218
230
|
|
231
|
+
`as_user` also accepts a string, which can be useful for auditing updates made in a CLI environment:
|
232
|
+
|
233
|
+
```rb
|
234
|
+
Audited.audit_class.as_user("console-user-#{ENV['SSH_USER']}") do
|
235
|
+
post.update_attributes!(title: "Hello, world!")
|
236
|
+
end
|
237
|
+
post.audits.last.user # => 'console-user-username'
|
238
|
+
```
|
239
|
+
|
240
|
+
If you want to set a specific user as the auditor of the commands in a CLI environment, whether that is a string or an ActiveRecord object, you can use the following command:
|
241
|
+
|
242
|
+
```rb
|
243
|
+
Audited.store[:audited_user] = "username"
|
244
|
+
|
245
|
+
# or
|
246
|
+
|
247
|
+
Audited.store[:audited_user] = User.find(1)
|
248
|
+
```
|
249
|
+
|
219
250
|
### Associated Audits
|
220
251
|
|
221
252
|
Sometimes it's useful to associate an audit with a model other than the one being changed. For instance, given the following models:
|
@@ -250,11 +281,16 @@ Now, when an audit is created for a user, that user's company is also saved alon
|
|
250
281
|
```ruby
|
251
282
|
company = Company.create!(name: "Collective Idea")
|
252
283
|
user = company.users.create!(name: "Steve")
|
253
|
-
user.
|
284
|
+
user.update!(name: "Steve Richert")
|
254
285
|
user.audits.last.associated # => #<Company name: "Collective Idea">
|
255
286
|
company.associated_audits.last.auditable # => #<User name: "Steve Richert">
|
256
287
|
```
|
257
288
|
|
289
|
+
You can access records' own audits and associated audits in one go:
|
290
|
+
```ruby
|
291
|
+
company.own_and_associated_audits
|
292
|
+
```
|
293
|
+
|
258
294
|
### Conditional auditing
|
259
295
|
|
260
296
|
If you want to audit only under specific conditions, you can provide conditional options (similar to ActiveModel callbacks) that will ensure your model is only audited for these conditions.
|
@@ -312,6 +348,29 @@ To disable auditing on an entire model:
|
|
312
348
|
User.auditing_enabled = false
|
313
349
|
```
|
314
350
|
|
351
|
+
To disable auditing on all models:
|
352
|
+
|
353
|
+
```ruby
|
354
|
+
Audited.auditing_enabled = false
|
355
|
+
```
|
356
|
+
|
357
|
+
If you have auditing disabled by default on your model you can enable auditing
|
358
|
+
temporarily.
|
359
|
+
|
360
|
+
```ruby
|
361
|
+
User.auditing_enabled = false
|
362
|
+
@user.save_with_auditing
|
363
|
+
```
|
364
|
+
|
365
|
+
or:
|
366
|
+
|
367
|
+
```ruby
|
368
|
+
User.auditing_enabled = false
|
369
|
+
@user.with_auditing do
|
370
|
+
@user.save
|
371
|
+
end
|
372
|
+
```
|
373
|
+
|
315
374
|
### Custom `Audit` model
|
316
375
|
|
317
376
|
If you want to extend or modify the audit model, create a new class that
|
@@ -332,6 +391,16 @@ Audited.config do |config|
|
|
332
391
|
end
|
333
392
|
```
|
334
393
|
|
394
|
+
### Enum Storage
|
395
|
+
|
396
|
+
In 4.10, the default behavior for enums changed from storing the value synthesized by Rails to the value stored in the DB. You can restore the previous behavior by setting the store_synthesized_enums configuration value:
|
397
|
+
|
398
|
+
```ruby
|
399
|
+
# config/initializers/audited.rb
|
400
|
+
|
401
|
+
Audited.store_synthesized_enums = true
|
402
|
+
```
|
403
|
+
|
335
404
|
## Support
|
336
405
|
|
337
406
|
You can find documentation at: http://rdoc.info/github/collectiveidea/audited
|