audited 4.9.0 → 5.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/buildlight.yml +15 -0
  3. data/.github/workflows/ci.yml +145 -0
  4. data/.github/workflows/publish_gem.yml +28 -0
  5. data/.standard.yml +5 -0
  6. data/Appraisals +35 -16
  7. data/CHANGELOG.md +162 -1
  8. data/Gemfile +1 -1
  9. data/README.md +73 -18
  10. data/Rakefile +5 -7
  11. data/gemfiles/rails50.gemfile +2 -0
  12. data/gemfiles/rails51.gemfile +2 -0
  13. data/gemfiles/rails52.gemfile +3 -1
  14. data/gemfiles/rails60.gemfile +1 -1
  15. data/gemfiles/rails61.gemfile +10 -0
  16. data/gemfiles/rails70.gemfile +10 -0
  17. data/gemfiles/rails71.gemfile +10 -0
  18. data/lib/audited/audit.rb +41 -29
  19. data/lib/audited/auditor.rb +134 -56
  20. data/lib/audited/railtie.rb +16 -0
  21. data/lib/audited/rspec_matchers.rb +5 -3
  22. data/lib/audited/sweeper.rb +3 -10
  23. data/lib/audited/version.rb +3 -1
  24. data/lib/audited-rspec.rb +3 -1
  25. data/lib/audited.rb +31 -9
  26. data/lib/generators/audited/install_generator.rb +9 -7
  27. data/lib/generators/audited/migration.rb +12 -2
  28. data/lib/generators/audited/migration_helper.rb +3 -1
  29. data/lib/generators/audited/templates/add_association_to_audits.rb +2 -0
  30. data/lib/generators/audited/templates/add_comment_to_audits.rb +2 -0
  31. data/lib/generators/audited/templates/add_remote_address_to_audits.rb +2 -0
  32. data/lib/generators/audited/templates/add_request_uuid_to_audits.rb +2 -0
  33. data/lib/generators/audited/templates/add_version_to_auditable_index.rb +2 -0
  34. data/lib/generators/audited/templates/install.rb +2 -0
  35. data/lib/generators/audited/templates/rename_association_to_associated.rb +2 -0
  36. data/lib/generators/audited/templates/rename_changes_to_audited_changes.rb +2 -0
  37. data/lib/generators/audited/templates/rename_parent_to_association.rb +2 -0
  38. data/lib/generators/audited/templates/revert_polymorphic_indexes_order.rb +2 -0
  39. data/lib/generators/audited/upgrade_generator.rb +16 -14
  40. data/spec/audited/audit_spec.rb +70 -48
  41. data/spec/audited/auditor_spec.rb +477 -246
  42. data/spec/audited/sweeper_spec.rb +19 -18
  43. data/spec/audited_spec.rb +14 -0
  44. data/spec/audited_spec_helpers.rb +11 -7
  45. data/spec/rails_app/app/assets/config/manifest.js +2 -0
  46. data/spec/rails_app/config/application.rb +32 -3
  47. data/spec/rails_app/config/database.yml +3 -2
  48. data/spec/rails_app/config/environment.rb +1 -1
  49. data/spec/rails_app/config/environments/test.rb +10 -5
  50. data/spec/rails_app/config/initializers/secret_token.rb +2 -2
  51. data/spec/spec_helper.rb +14 -14
  52. data/spec/support/active_record/models.rb +62 -13
  53. data/spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb +1 -2
  54. data/spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb +1 -2
  55. data/spec/support/active_record/schema.rb +26 -19
  56. data/test/db/version_1.rb +2 -2
  57. data/test/db/version_2.rb +2 -2
  58. data/test/db/version_3.rb +2 -3
  59. data/test/db/version_4.rb +2 -3
  60. data/test/db/version_5.rb +0 -1
  61. data/test/db/version_6.rb +1 -1
  62. data/test/install_generator_test.rb +18 -19
  63. data/test/test_helper.rb +5 -5
  64. data/test/upgrade_generator_test.rb +13 -18
  65. metadata +49 -31
  66. data/.rubocop.yml +0 -25
  67. data/.travis.yml +0 -58
  68. data/gemfiles/rails42.gemfile +0 -11
  69. data/spec/rails_app/app/controllers/application_controller.rb +0 -2
  70. data/spec/rails_app/config/environments/development.rb +0 -21
  71. data/spec/rails_app/config/environments/production.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91cd155edfaec5e9cbe81994bdc5e12e8fd91b58886d8397a6f310ddade5ae03
4
- data.tar.gz: 5d7b4f209cf8d8803dff66e4f19b8f85c586373ea757f1e84c1422d56feee1c0
3
+ metadata.gz: 32e366c7864b72cc3729bd15673e391ff3f45fee1b6ab0f2789ed8499588002f
4
+ data.tar.gz: 6a3f24da58730f880eaa1e7e607f33ef5bf74a035b477249e7d34f827e36728c
5
5
  SHA512:
6
- metadata.gz: 48bab7914ba66c2e7e82bf1bb6936b113b4536ab1297e9d8cdad80036788506bc825594daf37d308b8acbff3321e7ea1936fe6bdb3481f48f311a8caaec9e4ec
7
- data.tar.gz: f30cdcce78fd2c9202d3147af5d6e6844fb77f5e81300b79261d29f0d931580e67dd3bb04799d0247d3a8b4893314996a05d3ff25d477c43dbc3cf713ecd59fd
6
+ metadata.gz: fb1332090ad6d301af3d61a2948b8376f33dad8bea9c431ad480432f3c8d80837b9202f718e69be2dcdb0bb7bab8a329d77ae45e2fc50c533b6c79979e5d2b49
7
+ data.tar.gz: 632aae39c6307342b8430308f2f093e03a1b172f8ce0c08a3ed87f380f48b39e5fff63b2132fa93f9a5d0dec4a08b391671f52b5d2173a680c951aa27b4537f9
@@ -0,0 +1,15 @@
1
+ name: Buildlight
2
+
3
+ on:
4
+ workflow_run:
5
+ workflows:
6
+ - CI
7
+ branches:
8
+ - main
9
+
10
+ jobs:
11
+ webhook:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Webhook
15
+ uses: collectiveidea/buildlight@main
@@ -0,0 +1,145 @@
1
+ name: CI
2
+
3
+ on:
4
+ - pull_request
5
+ - push
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2]
14
+ appraisal:
15
+ - rails50
16
+ - rails51
17
+ - rails52
18
+ - rails60
19
+ - rails61
20
+ - rails70
21
+ - rails71
22
+ db: [POSTGRES, MYSQL, SQLITE]
23
+ exclude:
24
+ # MySQL has issues on Ruby 2.3
25
+ # https://github.com/ruby/setup-ruby/issues/150
26
+ - ruby: 2.3
27
+ db: MYSQL
28
+
29
+ # PostgreSQL is segfaulting on 2.3
30
+ # Doesn't seem worth solving.
31
+ - ruby: 2.3
32
+ db: POSTGRES
33
+
34
+ # Rails 5.0 supports Ruby 2.2-2.4
35
+ - appraisal: rails50
36
+ ruby: 2.5
37
+ - appraisal: rails50
38
+ ruby: 2.6
39
+ - appraisal: rails50
40
+ ruby: 2.7
41
+ - appraisal: rails50
42
+ ruby: 3.0
43
+ - appraisal: rails50
44
+ ruby: 3.1
45
+ - appraisal: rails50
46
+ ruby: 3.2
47
+
48
+ # Rails 5.1 supports Ruby 2.2-2.5
49
+ - appraisal: rails51
50
+ ruby: 2.6
51
+ - appraisal: rails51
52
+ ruby: 2.7
53
+ - appraisal: rails51
54
+ ruby: 3.0
55
+ - appraisal: rails51
56
+ ruby: 3.1
57
+ - appraisal: rails51
58
+ ruby: 3.2
59
+
60
+ # Rails 5.2 supports Ruby 2.2-2.5
61
+ - appraisal: rails52
62
+ ruby: 2.6
63
+ - appraisal: rails52
64
+ ruby: 2.7
65
+ - appraisal: rails52
66
+ ruby: 3.0
67
+ - appraisal: rails52
68
+ ruby: 3.1
69
+ - appraisal: rails52
70
+ ruby: 3.2
71
+
72
+ # Rails 6.0 supports Ruby 2.5-2.7
73
+ - appraisal: rails60
74
+ ruby: 2.3
75
+ - appraisal: rails60
76
+ ruby: 2.4
77
+ - appraisal: rails60
78
+ ruby: 3.0
79
+ - appraisal: rails60
80
+ ruby: 3.1
81
+ - appraisal: rails60
82
+ ruby: 3.2
83
+
84
+ # Rails 6.1 supports Ruby 2.5+
85
+ - appraisal: rails61
86
+ ruby: 2.3
87
+ - appraisal: rails61
88
+ ruby: 2.4
89
+
90
+ # Rails 7 supports Ruby 2.7+
91
+ - appraisal: rails70
92
+ ruby: 2.3
93
+ - appraisal: rails70
94
+ ruby: 2.4
95
+ - appraisal: rails70
96
+ ruby: 2.5
97
+ - appraisal: rails70
98
+ ruby: 2.6
99
+
100
+ # Rails 7.1 supports Ruby 2.7+
101
+ - appraisal: rails71
102
+ ruby: 2.3
103
+ - appraisal: rails71
104
+ ruby: 2.4
105
+ - appraisal: rails71
106
+ ruby: 2.5
107
+ - appraisal: rails71
108
+ ruby: 2.6
109
+
110
+ services:
111
+ postgres:
112
+ image: postgres
113
+ env:
114
+ POSTGRES_USER: postgres
115
+ POSTGRES_PASSWORD: postgres
116
+ POSTGRES_DB: audited_test
117
+ ports:
118
+ - 5432:5432
119
+ # needed because the postgres container does not provide a healthcheck
120
+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
121
+
122
+ env:
123
+ DB_DATABASE: audited_test
124
+ DB_USER: root
125
+ DB_PASSWORD: 'root'
126
+ DB_HOST: localhost
127
+
128
+ steps:
129
+ - name: Setup MySQL
130
+ run: |
131
+ sudo /etc/init.d/mysql start
132
+ mysql -e 'CREATE DATABASE audited_test;' -uroot -proot
133
+ mysql -e 'SHOW DATABASES;' -uroot -proot
134
+ - uses: actions/checkout@v3
135
+ - name: Copy Gemfile
136
+ run: sed 's/\.\././' gemfiles/${{ matrix.appraisal }}.gemfile > Gemfile
137
+ - name: Set up Ruby ${{ matrix.ruby }}
138
+ uses: ruby/setup-ruby@v1
139
+ with:
140
+ ruby-version: ${{ matrix.ruby }}
141
+ bundler-cache: true
142
+ - name: Run tests
143
+ env:
144
+ DB: ${{ matrix.db }}
145
+ run: bundle exec rake
@@ -0,0 +1,28 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - v*
7
+
8
+ jobs:
9
+ push:
10
+ if: github.repository == 'collectiveidea/audited'
11
+ runs-on: ubuntu-latest
12
+ environment: publishing
13
+
14
+ permissions:
15
+ contents: write
16
+ id-token: write
17
+
18
+ steps:
19
+ # Set up
20
+ - uses: actions/checkout@v4
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ bundler-cache: true
25
+ ruby-version: ruby
26
+
27
+ # Release
28
+ - uses: rubygems/release-gem@v1
data/.standard.yml ADDED
@@ -0,0 +1,5 @@
1
+ ruby_version: 2.3
2
+ ignore:
3
+ - lib/generators/audited/templates/**/*
4
+ - vendor/bundle/**/*
5
+ - gemfiles/vendor/bundle/**/*
data/Appraisals CHANGED
@@ -1,38 +1,57 @@
1
1
  # Include DB adapters matching the version requirements in
2
2
  # rails/activerecord/lib/active_record/connection_adapters/*adapter.rb
3
3
 
4
- appraise 'rails42' do
5
- gem 'rails', '~> 4.2.0'
6
- gem 'protected_attributes'
7
- gem "mysql2", ">= 0.3.13", "< 0.6.0"
8
- gem "pg", "~> 0.15"
9
- gem "sqlite3", "~> 1.3.6"
10
- end
11
-
12
- appraise 'rails50' do
13
- gem 'rails', '~> 5.0.0'
4
+ appraise "rails50" do
5
+ gem "rails", "~> 5.0.0"
14
6
  gem "mysql2", ">= 0.3.18", "< 0.6.0"
15
7
  gem "pg", ">= 0.18", "< 2.0"
16
8
  gem "sqlite3", "~> 1.3.6"
9
+ gem "psych", "~> 3.1"
10
+ gem "loofah", "2.20.0"
17
11
  end
18
12
 
19
- appraise 'rails51' do
20
- gem 'rails', '~> 5.1.4'
13
+ appraise "rails51" do
14
+ gem "rails", "~> 5.1.4"
21
15
  gem "mysql2", ">= 0.3.18", "< 0.6.0"
22
16
  gem "pg", ">= 0.18", "< 2.0"
23
17
  gem "sqlite3", "~> 1.3.6"
18
+ gem "psych", "~> 3.1"
19
+ gem "loofah", "2.20.0"
24
20
  end
25
21
 
26
- appraise 'rails52' do
27
- gem 'rails', '>= 5.2.0', '< 5.3'
22
+ appraise "rails52" do
23
+ gem "rails", ">= 5.2.8.1", "< 5.3"
28
24
  gem "mysql2", ">= 0.4.4", "< 0.6.0"
29
25
  gem "pg", ">= 0.18", "< 2.0"
30
26
  gem "sqlite3", "~> 1.3.6"
27
+ gem "psych", "~> 3.1"
28
+ gem "loofah", "2.20.0"
31
29
  end
32
30
 
33
- appraise 'rails60' do
34
- gem 'rails', '>= 6.0.0.rc1', '< 6.1'
31
+ appraise "rails60" do
32
+ gem "rails", ">= 6.0.0", "< 6.1"
35
33
  gem "mysql2", ">= 0.4.4"
36
34
  gem "pg", ">= 0.18", "< 2.0"
37
35
  gem "sqlite3", "~> 1.4"
38
36
  end
37
+
38
+ appraise "rails61" do
39
+ gem "rails", ">= 6.1.0", "< 6.2"
40
+ gem "mysql2", ">= 0.4.4"
41
+ gem "pg", ">= 1.1", "< 2.0"
42
+ gem "sqlite3", "~> 1.4"
43
+ end
44
+
45
+ appraise "rails70" do
46
+ gem "rails", ">= 7.0.0", "< 7.1"
47
+ gem "mysql2", ">= 0.4.4"
48
+ gem "pg", ">= 1.1"
49
+ gem "sqlite3", ">= 1.4"
50
+ end
51
+
52
+ appraise "rails71" do
53
+ gem "rails", ">= 7.1.0.beta1", "< 7.2"
54
+ gem "mysql2", ">= 0.4.4"
55
+ gem "pg", ">= 1.1"
56
+ gem "sqlite3", ">= 1.4"
57
+ end
data/CHANGELOG.md CHANGED
@@ -1,6 +1,167 @@
1
1
  # Audited ChangeLog
2
2
 
3
- ## Unreleased
3
+ ### 5.4.3 (2024-01-11)
4
+
5
+ - Ignore readonly columns in audit - @sriddbs
6
+ [#692](https://github.com/collectiveidea/audited/pull/692)
7
+ - Robustify Rails version checks - @blaet
8
+ [#689](https://github.com/collectiveidea/audited/pull/689)
9
+ - Ignore callbacks if not specifed on the model
10
+ [#679](https://github.com/collectiveidea/audited/pull/679)
11
+
12
+ ## 5.4.2 (2023-11-30)
13
+
14
+ - Revert replacing RequetStore with ActiveSupport::CurrentAttributes until it is fully tested.
15
+
16
+ ## 5.4.1 (2023-11-30)
17
+
18
+ - Replace RequestStore with ActiveSupport::CurrentAttributes - @the-spectator
19
+ [#673](https://github.com/collectiveidea/audited/pull/673/)
20
+ - Don't require railtie when used outside of Rails - @nicduke38degrees
21
+ [#665](https://github.com/collectiveidea/audited/pull/665)
22
+
23
+ ## 5.4.0 (2023-09-30)
24
+
25
+ - Add Rails 7.1 support - @yuki24
26
+ [#686](https://github.com/collectiveidea/audited/pull/686)
27
+
28
+ ## 5.3.3 (2023-03-24)
29
+
30
+ - Use RequestStore instead of Thread.current for thread-safe requests - @tiagocassio
31
+ [#669](https://github.com/collectiveidea/audited/pull/669)
32
+ - Clean up Touch audits - @mcyoung, @akostadinov
33
+ [#668](https://github.com/collectiveidea/audited/pull/668)
34
+
35
+ ## 5.3.2 (2023-02-22)
36
+
37
+ - Touch audit bug fixes - @mcyoung
38
+ [#662](https://github.com/collectiveidea/audited/pull/662)
39
+
40
+ ## 5.3.1 (2023-02-21)
41
+
42
+ - Ensure touch support doesn't cause double audits - @mcyoung
43
+ [#660](https://github.com/collectiveidea/audited/pull/660)
44
+ - Testing Improvements - @vlad-psh
45
+ [#628](https://github.com/collectiveidea/audited/pull/628)
46
+ - Testing Improvements - @mcyoung
47
+ [#658](https://github.com/collectiveidea/audited/pull/658)
48
+
49
+ ## 5.3.0 (2023-02-14)
50
+
51
+ - Audit touch calls - @mcyoung
52
+ [#657](https://github.com/collectiveidea/audited/pull/657)
53
+ - Allow using with Padrino and other non-Rails projects - @nicduke38degrees
54
+ [#655](https://github.com/collectiveidea/audited/pull/655)
55
+ - Testing updates - @jdufresne
56
+ [#652](https://github.com/collectiveidea/audited/pull/652)
57
+ [#653](https://github.com/collectiveidea/audited/pull/653)
58
+
59
+ ## 5.2.0 (2023-01-23)
60
+
61
+ Improved
62
+
63
+ - config.audit_class can take a string or constant - @rocket-turtle
64
+ Fixes overzealous change in 5.1.0 where it only took a string.
65
+ [#648](https://github.com/collectiveidea/audited/pull/648)
66
+ - README link fix - @jeremiahlukus
67
+ [#646](https://github.com/collectiveidea/audited/pull/646)
68
+ - Typo fix in GitHub Actions - @jdufresne
69
+ [#644](https://github.com/collectiveidea/audited/pull/644)
70
+
71
+ ## 5.1.0 (2022-12-23)
72
+
73
+ Changed
74
+
75
+ - config.audit_class takes a string - @simmerz
76
+ [#609](https://github.com/collectiveidea/audited/pull/609)
77
+ - Filter encrypted attributes automatically - @vlad-psh
78
+ [#630](https://github.com/collectiveidea/audited/pull/630)
79
+
80
+ Improved
81
+
82
+ - README improvements - @jess, @mstroming
83
+ [#605](https://github.com/collectiveidea/audited/pull/605)
84
+ [#640](https://github.com/collectiveidea/audited/issues/640)
85
+ - Ignore deadlocks in concurrent audit combinations - @Crammaman
86
+ [#621](https://github.com/collectiveidea/audited/pull/621)
87
+ - Fix timestamped_migrations deprecation warning - @shouichi
88
+ [#624](https://github.com/collectiveidea/audited/pull/624)
89
+ - Ensure audits are re-enabled after blocks - @dcorlett
90
+ [#632](https://github.com/collectiveidea/audited/pull/632)
91
+ - Replace raw string where clause with query methods - @macowie
92
+ [#642](https://github.com/collectiveidea/audited/pull/642)
93
+ - Test against more Ruby/Rails Versions - @enomotodev, @danielmorrison
94
+ [#610](https://github.com/collectiveidea/audited/pull/610)
95
+ [#643](https://github.com/collectiveidea/audited/pull/643)
96
+
97
+ ## 5.0.2 (2021-09-16)
98
+
99
+ Added
100
+
101
+ - Relax ActiveRecord version constraint to support Rails 7
102
+ [#597](https://github.com/collectiveidea/audited/pull/597)
103
+
104
+ Improved
105
+
106
+ - Improve loading - @mvastola
107
+ [#592](https://github.com/collectiveidea/audited/pull/592)
108
+ - Update README - @danirod, @clement1234
109
+ [#596](https://github.com/collectiveidea/audited/pull/596)
110
+ [#594](https://github.com/collectiveidea/audited/pull/594)
111
+
112
+
113
+ ## 5.0.1 (2021-06-11)
114
+
115
+ Improved
116
+
117
+ - Don't load associated model when auditing is disabled - @nut4k1
118
+ [#584](https://github.com/collectiveidea/audited/pull/584)
119
+
120
+ ## 5.0.0 (2021-06-10)
121
+
122
+ Improved
123
+
124
+ - Fixes an issue where array attributes were not deserialized properly - @cfeckardt, @yuki24
125
+ [#448](https://github.com/collectiveidea/audited/pull/448)
126
+ [#576](https://github.com/collectiveidea/audited/pull/576)
127
+ - Improve error message on audit_comment and allow for i18n override - @james
128
+ [#523](https://github.com/collectiveidea/audited/pull/523/)
129
+ - Don't require a comment if only non-audited fields are changed - @james
130
+ [#522](https://github.com/collectiveidea/audited/pull/522/)
131
+ - Readme updates - @gourshete
132
+ [#525](https://github.com/collectiveidea/audited/pull/525)
133
+ - Allow restoring previous enum behavior with flag - @travisofthenorth
134
+ [#526](https://github.com/collectiveidea/audited/pull/526)
135
+ - Follow Rails Autoloading conventions - @duncanjbrown
136
+ [#532](https://github.com/collectiveidea/audited/pull/532)
137
+ - Fix own_and_associated_audits for STI Models - @eric-hemasystems
138
+ [#533](https://github.com/collectiveidea/audited/pull/533)
139
+ - Rails 6.1 Improvements - @okuramasafumi, @marcrohloff
140
+ [#563](https://github.com/collectiveidea/audited/pull/563)
141
+ [#544](https://github.com/collectiveidea/audited/pull/544)
142
+ - Use Thread local variables instead of Fibers - @arathunku
143
+ [#568](https://github.com/collectiveidea/audited/pull/568)
144
+
145
+ Changed
146
+
147
+ - Drop support for Rails 4 - @travisofthenorth
148
+ [#527](https://github.com/collectiveidea/audited/pull/527)
149
+
150
+ ## 4.10.0 (2021-01-07)
151
+
152
+ Added
153
+
154
+ - Add redacted option
155
+ [#485](https://github.com/collectiveidea/audited/pull/485)
156
+ - Rails 6.1. support
157
+ [#554](https://github.com/collectiveidea/audited/pull/554)
158
+ [#559](https://github.com/collectiveidea/audited/pull/559)
159
+
160
+ Improved
161
+
162
+ - Avoid extra query on first audit version
163
+ [#513](https://github.com/collectiveidea/audited/pull/513)
164
+
4
165
 
5
166
  ## 4.9.0 (2019-07-17)
6
167
 
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec name: "audited"
data/README.md CHANGED
@@ -1,20 +1,30 @@
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)
1
+ Audited
2
+ [![Gem Version](https://img.shields.io/gem/v/audited.svg)](http://rubygems.org/gems/audited)
3
+ ![Build Status](https://github.com/collectiveidea/audited/actions/workflows/ci.yml/badge.svg)
4
+ [![Code Climate](https://codeclimate.com/github/collectiveidea/audited.svg)](https://codeclimate.com/github/collectiveidea/audited)
5
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
2
6
  =======
3
7
 
4
8
  **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
9
 
6
- Audited currently (4.x) works with Rails 6.0, 5.2, 5.1, 5.0 and 4.2.
7
10
 
11
+ Audited currently (5.x) works with Rails 7.1, 7.0, 6.1, 6.0, 5.2, 5.1, and 5.0.
12
+
13
+ For Rails 4, use gem version 4.x
8
14
  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
15
 
10
16
  ## Supported Rubies
11
17
 
12
- Audited supports and is [tested against](http://travis-ci.org/collectiveidea/audited) the following Ruby versions:
18
+ Audited supports and is [tested against](https://github.com/collectiveidea/audited/actions/workflows/ci.yml) the following Ruby versions:
13
19
 
14
- * 2.3.7
15
- * 2.4.4
16
- * 2.5.1
17
- * 2.6.3
20
+ * 2.3 (only tested on Sqlite due to testing issues with other DBs)
21
+ * 2.4
22
+ * 2.5
23
+ * 2.6
24
+ * 2.7
25
+ * 3.0
26
+ * 3.1
27
+ * 3.2
18
28
 
19
29
  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).
20
30
 
@@ -27,7 +37,16 @@ Audited is currently ActiveRecord-only. In a previous life, Audited worked with
27
37
  Add the gem to your Gemfile:
28
38
 
29
39
  ```ruby
30
- gem "audited", "~> 4.9"
40
+ gem "audited"
41
+ ```
42
+
43
+ And if you're using ```require: false``` you must add initializers like this:
44
+
45
+ ```ruby
46
+ #./config/initializers/audited.rb
47
+ require "audited"
48
+
49
+ Audited::Railtie.initializers.each(&:run)
31
50
  ```
32
51
 
33
52
  Then, from your Rails app directory, create the `audits` table:
@@ -114,18 +133,24 @@ end
114
133
 
115
134
  ### Specifying callbacks
116
135
 
117
- By default, a new audit is created for any Create, Update or Destroy action. You can, however, limit the actions audited.
136
+ By default, a new audit is created for any Create, Update, Touch (Rails 6+) or Destroy action. You can, however, limit the actions audited.
118
137
 
119
138
  ```ruby
120
139
  class User < ActiveRecord::Base
121
140
  # All fields and actions
122
141
  # audited
123
142
 
124
- # Single field, only audit Update and Destroy (not Create)
143
+ # Single field, only audit Update and Destroy (not Create or Touch)
125
144
  # audited only: :name, on: [:update, :destroy]
126
145
  end
127
146
  ```
128
147
 
148
+ You can ignore the default callbacks globally unless the callback action is specified in your model using the `:on` option. To configure default callback exclusion, put the following in an initializer file (`config/initializers/audited.rb`):
149
+
150
+ ```ruby
151
+ Audited.ignored_default_callbacks = [:create, :update] # ignore callbacks create and update
152
+ ```
153
+
129
154
  ### Comments
130
155
 
131
156
  You can attach comments to each audit using an `audit_comment` attribute on your model.
@@ -143,7 +168,7 @@ class User < ActiveRecord::Base
143
168
  end
144
169
  ```
145
170
 
146
- You can update an audit if only 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.
171
+ 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.
147
172
 
148
173
  ```ruby
149
174
  class User < ActiveRecord::Base
@@ -153,7 +178,7 @@ end
153
178
 
154
179
  ### Limiting stored audits
155
180
 
156
- You can limit the number of audits stored for your model. To configure limiting for all audited models, put the following in an initializer:
181
+ 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`):
157
182
 
158
183
  ```ruby
159
184
  Audited.max_audits = 10 # keep only 10 latest audits
@@ -192,7 +217,7 @@ class PostsController < ApplicationController
192
217
  end
193
218
  ```
194
219
 
195
- To use a method other than `current_user`, put the following in an initializer:
220
+ To use a method other than `current_user`, put the following in an initializer file (`config/initializers/audited.rb`):
196
221
 
197
222
  ```ruby
198
223
  Audited.current_user_method = :authenticated_user
@@ -219,7 +244,7 @@ class ApplicationController < ActionController::Base
219
244
  if current_user
220
245
  current_user
221
246
  else
222
- 'Elon Musk'
247
+ 'Alexander Fleming'
223
248
  end
224
249
  end
225
250
  end
@@ -234,6 +259,16 @@ end
234
259
  post.audits.last.user # => 'console-user-username'
235
260
  ```
236
261
 
262
+ 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:
263
+
264
+ ```rb
265
+ Audited.store[:audited_user] = "username"
266
+
267
+ # or
268
+
269
+ Audited.store[:audited_user] = User.find(1)
270
+ ```
271
+
237
272
  ### Associated Audits
238
273
 
239
274
  Sometimes it's useful to associate an audit with a model other than the one being changed. For instance, given the following models:
@@ -258,6 +293,7 @@ class User < ActiveRecord::Base
258
293
  end
259
294
 
260
295
  class Company < ActiveRecord::Base
296
+ audited
261
297
  has_many :users
262
298
  has_associated_audits
263
299
  end
@@ -286,8 +322,6 @@ If you want to audit only under specific conditions, you can provide conditional
286
322
  class User < ActiveRecord::Base
287
323
  audited if: :active?
288
324
 
289
- private
290
-
291
325
  def active?
292
326
  last_login > 6.months.ago
293
327
  end
@@ -358,6 +392,17 @@ User.auditing_enabled = false
358
392
  end
359
393
  ```
360
394
 
395
+ ### Encrypted attributes
396
+
397
+ If you're using ActiveRecord's encryption (available from Rails 7) to encrypt some attributes, Audited will automatically filter values of these attributes. No additional configuration is required. Changes to encrypted attributes will be logged as `[FILTERED]`.
398
+
399
+ ```ruby
400
+ class User < ActiveRecord::Base
401
+ audited
402
+ encrypts :password
403
+ end
404
+ ```
405
+
361
406
  ### Custom `Audit` model
362
407
 
363
408
  If you want to extend or modify the audit model, create a new class that
@@ -374,13 +419,23 @@ Then set it in an initializer:
374
419
  # config/initializers/audited.rb
375
420
 
376
421
  Audited.config do |config|
377
- config.audit_class = CustomAudit
422
+ config.audit_class = "CustomAudit"
378
423
  end
379
424
  ```
380
425
 
426
+ ### Enum Storage
427
+
428
+ 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:
429
+
430
+ ```ruby
431
+ # config/initializers/audited.rb
432
+
433
+ Audited.store_synthesized_enums = true
434
+ ```
435
+
381
436
  ## Support
382
437
 
383
- You can find documentation at: http://rdoc.info/github/collectiveidea/audited
438
+ You can find documentation at: https://www.rubydoc.info/gems/audited
384
439
 
385
440
  Or join the [mailing list](http://groups.google.com/group/audited) to get help or offer suggestions.
386
441
 
data/Rakefile CHANGED
@@ -1,17 +1,15 @@
1
1
  #!/usr/bin/env rake
2
2
 
3
- require 'bundler/gem_helper'
4
- require 'rspec/core/rake_task'
5
- require 'rake/testtask'
6
- require 'appraisal'
7
-
8
- Bundler::GemHelper.install_tasks(name: 'audited')
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rake/testtask"
6
+ require "appraisal"
9
7
 
10
8
  RSpec::Core::RakeTask.new(:spec)
11
9
 
12
10
  Rake::TestTask.new do |t|
13
11
  t.libs << "test"
14
- t.test_files = FileList['test/**/*_test.rb']
12
+ t.test_files = FileList["test/**/*_test.rb"]
15
13
  t.verbose = true
16
14
  end
17
15
 
@@ -6,5 +6,7 @@ gem "rails", "~> 5.0.0"
6
6
  gem "mysql2", ">= 0.3.18", "< 0.6.0"
7
7
  gem "pg", ">= 0.18", "< 2.0"
8
8
  gem "sqlite3", "~> 1.3.6"
9
+ gem "psych", "~> 3.1"
10
+ gem "loofah", "2.20.0"
9
11
 
10
12
  gemspec name: "audited", path: "../"