audited 4.9.0 → 5.0.2
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 +4 -4
- data/.github/workflows/ci.yml +115 -0
- data/.standard.yml +5 -0
- data/Appraisals +22 -16
- data/CHANGELOG.md +68 -1
- data/Gemfile +1 -1
- data/README.md +49 -11
- data/Rakefile +6 -6
- data/gemfiles/rails60.gemfile +1 -1
- data/gemfiles/rails61.gemfile +10 -0
- data/gemfiles/rails70.gemfile +10 -0
- data/lib/audited/audit.rb +36 -28
- data/lib/audited/auditor.rb +69 -43
- 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/audited-rspec.rb +3 -1
- data/lib/audited.rb +25 -8
- 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 +2 -0
- data/lib/generators/audited/templates/install.rb +2 -0
- 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 +16 -14
- data/spec/audited/audit_spec.rb +69 -47
- data/spec/audited/auditor_spec.rb +310 -246
- data/spec/audited/sweeper_spec.rb +19 -18
- 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 +3 -3
- data/spec/rails_app/config/database.yml +3 -2
- 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 +14 -14
- data/spec/support/active_record/models.rb +31 -12
- 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 +26 -19
- 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 +1 -1
- data/test/install_generator_test.rb +18 -19
- data/test/test_helper.rb +5 -5
- data/test/upgrade_generator_test.rb +13 -18
- metadata +31 -30
- data/.rubocop.yml +0 -25
- data/.travis.yml +0 -58
- data/gemfiles/rails42.gemfile +0 -11
- data/spec/rails_app/app/controllers/application_controller.rb +0 -2
- 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
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bb58e8eb5b0de02a18ac5d089ccade2913c399ec66bcbf97551fd9a9f4afb6b
|
4
|
+
data.tar.gz: 905621826a752e1796e0b81a7b448eec483e0ef27ce5de9f02845e0f5fd8be87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62448f486877e8a6c86505a7e5f53b805bf4f3a14cad907f83e69cd5175f43a4c3083a08ab4342bad18f5b8b1b104aa20d2d3c375ff86b7e60d48db9cbe00346
|
7
|
+
data.tar.gz: 4bf37e3891074e6f329961c796db27191ead60d225860d3150f310a3888ed3ab52eab1564398ce2f26ad470ba2872979dd14ee48cddf0baaa8f7cbfb63c19091
|
@@ -0,0 +1,115 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- master
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0]
|
16
|
+
appraisal:
|
17
|
+
- rails50
|
18
|
+
- rails51
|
19
|
+
- rails52
|
20
|
+
- rails60
|
21
|
+
- rails61
|
22
|
+
- rails70
|
23
|
+
db: [POSTGRES, MYSQL, SQLITE]
|
24
|
+
exclude:
|
25
|
+
# MySQL has issues on Ruby 2.3
|
26
|
+
# https://github.com/ruby/setup-ruby/issues/150
|
27
|
+
- ruby: 2.3
|
28
|
+
db: MYSQL
|
29
|
+
|
30
|
+
# Rails 5.0 supports Ruby 2.2-2.4
|
31
|
+
- appraisal: rails50
|
32
|
+
ruby: 2.5
|
33
|
+
- appraisal: rails50
|
34
|
+
ruby: 2.6
|
35
|
+
- appraisal: rails50
|
36
|
+
ruby: 2.7
|
37
|
+
- appraisal: rails50
|
38
|
+
ruby: 3.0
|
39
|
+
|
40
|
+
# Rails 5.1 supports Ruby 2.2-2.5
|
41
|
+
- appraisal: rails51
|
42
|
+
ruby: 2.6
|
43
|
+
- appraisal: rails51
|
44
|
+
ruby: 2.7
|
45
|
+
- appraisal: rails51
|
46
|
+
ruby: 3.0
|
47
|
+
|
48
|
+
# Rails 5.2 supports Ruby 2.2-2.5
|
49
|
+
- appraisal: rails52
|
50
|
+
ruby: 2.6
|
51
|
+
- appraisal: rails52
|
52
|
+
ruby: 2.7
|
53
|
+
- appraisal: rails52
|
54
|
+
ruby: 3.0
|
55
|
+
|
56
|
+
# Rails 6.0 supports Ruby 2.5-2.7
|
57
|
+
- appraisal: rails60
|
58
|
+
ruby: 2.3
|
59
|
+
- appraisal: rails60
|
60
|
+
ruby: 2.4
|
61
|
+
- appraisal: rails60
|
62
|
+
ruby: 3.0
|
63
|
+
|
64
|
+
# Rails 6.1 supports Ruby 2.5+
|
65
|
+
- appraisal: rails61
|
66
|
+
ruby: 2.3
|
67
|
+
- appraisal: rails61
|
68
|
+
ruby: 2.4
|
69
|
+
|
70
|
+
# Rails 7 supports Ruby 2.7+
|
71
|
+
- appraisal: rails70
|
72
|
+
ruby: 2.3
|
73
|
+
- appraisal: rails70
|
74
|
+
ruby: 2.4
|
75
|
+
- appraisal: rails70
|
76
|
+
ruby: 2.5
|
77
|
+
- appraisal: rails70
|
78
|
+
ruby: 2.6
|
79
|
+
|
80
|
+
services:
|
81
|
+
postgres:
|
82
|
+
image: postgres
|
83
|
+
env:
|
84
|
+
POSTGRES_USER: postgres
|
85
|
+
POSTGRES_PASSWORD: postgres
|
86
|
+
POSTGRES_DB: audited_test
|
87
|
+
ports:
|
88
|
+
- 5432:5432
|
89
|
+
# needed because the postgres container does not provide a healthcheck
|
90
|
+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
91
|
+
|
92
|
+
env:
|
93
|
+
DB_DATABASE: audited_test
|
94
|
+
DB_USER: root
|
95
|
+
DB_PASSWORD: 'root'
|
96
|
+
DB_HOST: localhost
|
97
|
+
|
98
|
+
steps:
|
99
|
+
- name: Setup MySQL
|
100
|
+
run: |
|
101
|
+
sudo /etc/init.d/mysql start
|
102
|
+
mysql -e 'CREATE DATABASE audited_test;' -uroot -proot
|
103
|
+
mysql -e 'SHOW DATABASES;' -uroot -proot
|
104
|
+
- uses: actions/checkout@v2
|
105
|
+
- name: Copy Gemfile
|
106
|
+
run: sed 's/\.\././' gemfiles/${{ matrix.appraisal }}.gemfile > Gemfile
|
107
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
108
|
+
uses: ruby/setup-ruby@v1
|
109
|
+
with:
|
110
|
+
ruby-version: ${{ matrix.ruby }}
|
111
|
+
bundler-cache: true
|
112
|
+
- name: Run tests
|
113
|
+
env:
|
114
|
+
DB: ${{ matrix.db }}
|
115
|
+
run: bundle exec rake
|
data/.standard.yml
ADDED
data/Appraisals
CHANGED
@@ -1,38 +1,44 @@
|
|
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
|
5
|
-
gem
|
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"
|
17
9
|
end
|
18
10
|
|
19
|
-
appraise
|
20
|
-
gem
|
11
|
+
appraise "rails51" do
|
12
|
+
gem "rails", "~> 5.1.4"
|
21
13
|
gem "mysql2", ">= 0.3.18", "< 0.6.0"
|
22
14
|
gem "pg", ">= 0.18", "< 2.0"
|
23
15
|
gem "sqlite3", "~> 1.3.6"
|
24
16
|
end
|
25
17
|
|
26
|
-
appraise
|
27
|
-
gem
|
18
|
+
appraise "rails52" do
|
19
|
+
gem "rails", ">= 5.2.0", "< 5.3"
|
28
20
|
gem "mysql2", ">= 0.4.4", "< 0.6.0"
|
29
21
|
gem "pg", ">= 0.18", "< 2.0"
|
30
22
|
gem "sqlite3", "~> 1.3.6"
|
31
23
|
end
|
32
24
|
|
33
|
-
appraise
|
34
|
-
gem
|
25
|
+
appraise "rails60" do
|
26
|
+
gem "rails", ">= 6.0.0", "< 6.1"
|
35
27
|
gem "mysql2", ">= 0.4.4"
|
36
28
|
gem "pg", ">= 0.18", "< 2.0"
|
37
29
|
gem "sqlite3", "~> 1.4"
|
38
30
|
end
|
31
|
+
|
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"
|
37
|
+
end
|
38
|
+
|
39
|
+
appraise "rails70" do
|
40
|
+
gem "rails", ">= 7.0.0.alpha2", "< 7.1"
|
41
|
+
gem "mysql2", ">= 0.4.4"
|
42
|
+
gem "pg", ">= 1.1"
|
43
|
+
gem "sqlite3", ">= 1.4"
|
44
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,73 @@
|
|
1
1
|
# Audited ChangeLog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 5.0.2 (2021-09-16)
|
4
|
+
|
5
|
+
Added
|
6
|
+
|
7
|
+
- Relax ActiveRecord version constraint to support Rails 7
|
8
|
+
[#597](https://github.com/collectiveidea/audited/pull/597)
|
9
|
+
|
10
|
+
Improved
|
11
|
+
|
12
|
+
- Improve loading - @mvastola
|
13
|
+
[#592](https://github.com/collectiveidea/audited/pull/592)
|
14
|
+
- Update README - @danirod, clement1234
|
15
|
+
[#596](https://github.com/collectiveidea/audited/pull/596)
|
16
|
+
[#594](https://github.com/collectiveidea/audited/pull/594)
|
17
|
+
|
18
|
+
|
19
|
+
## 5.0.1 (2021-06-11)
|
20
|
+
|
21
|
+
Improved
|
22
|
+
|
23
|
+
- Don't load associated model when auditing is disabled - @nut4k1
|
24
|
+
[#584](https://github.com/collectiveidea/audited/pull/584)
|
25
|
+
|
26
|
+
## 5.0.0 (2021-06-10)
|
27
|
+
|
28
|
+
Improved
|
29
|
+
|
30
|
+
- Fixes an issue where array attributes were not deserialized properly - @cfeckardt, @yuki24
|
31
|
+
[#448](https://github.com/collectiveidea/audited/pull/448)
|
32
|
+
[#576](https://github.com/collectiveidea/audited/pull/576)
|
33
|
+
- Improve error message on audit_comment and allow for i18n override - @james
|
34
|
+
[#523](https://github.com/collectiveidea/audited/pull/523/)
|
35
|
+
- Don't require a comment if only non-audited fields are changed - @james
|
36
|
+
[#522](https://github.com/collectiveidea/audited/pull/522/)
|
37
|
+
- Readme updates - @gourshete
|
38
|
+
[#525](https://github.com/collectiveidea/audited/pull/525)
|
39
|
+
- Allow restoring previous enum behavior with flag - @travisofthenorth
|
40
|
+
[#526](https://github.com/collectiveidea/audited/pull/526)
|
41
|
+
- Follow Rails Autoloading conventions - @duncanjbrown
|
42
|
+
[#532](https://github.com/collectiveidea/audited/pull/532)
|
43
|
+
- Fix own_and_associated_audits for STI Models - @eric-hemasystems
|
44
|
+
[#533](https://github.com/collectiveidea/audited/pull/533)
|
45
|
+
- Rails 6.1 Improvements - @okuramasafumi, @marcrohloff
|
46
|
+
[#563](https://github.com/collectiveidea/audited/pull/563)
|
47
|
+
[#544](https://github.com/collectiveidea/audited/pull/544)
|
48
|
+
- Use Thread local variables instead of Fibers - @arathunku
|
49
|
+
[#568](https://github.com/collectiveidea/audited/pull/568)
|
50
|
+
|
51
|
+
Changed
|
52
|
+
|
53
|
+
- Drop support for Rails 4 - @travisofthenorth
|
54
|
+
[#527](https://github.com/collectiveidea/audited/pull/527)
|
55
|
+
|
56
|
+
## 4.10.0 (2021-01-07)
|
57
|
+
|
58
|
+
Added
|
59
|
+
|
60
|
+
- Add redacted option
|
61
|
+
[#485](https://github.com/collectiveidea/audited/pull/485)
|
62
|
+
- Rails 6.1. support
|
63
|
+
[#554](https://github.com/collectiveidea/audited/pull/554)
|
64
|
+
[#559](https://github.com/collectiveidea/audited/pull/559)
|
65
|
+
|
66
|
+
Improved
|
67
|
+
|
68
|
+
- Avoid extra query on first audit version
|
69
|
+
[#513](https://github.com/collectiveidea/audited/pull/513)
|
70
|
+
|
4
71
|
|
5
72
|
## 4.9.0 (2019-07-17)
|
6
73
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,20 +1,29 @@
|
|
1
|
-
Audited
|
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
|
+
[![Security](https://hakiri.io/github/collectiveidea/audited/master.svg)](https://hakiri.io/github/collectiveidea/audited/master)
|
6
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
|
2
7
|
=======
|
3
8
|
|
4
9
|
**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
10
|
|
6
|
-
Audited currently (4.x) works with Rails 6.0, 5.2, 5.1, 5.0 and 4.2.
|
7
11
|
|
12
|
+
Audited currently (5.x) works with Rails 7.0, 6.1, 6.0, 5.2, 5.1, and 5.0.
|
13
|
+
|
14
|
+
For Rails 4, use gem version 4.x
|
8
15
|
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
16
|
|
10
17
|
## Supported Rubies
|
11
18
|
|
12
|
-
Audited supports and is [tested against](
|
19
|
+
Audited supports and is [tested against](https://github.com/collectiveidea/audited/actions/workflows/ci.yml) the following Ruby versions:
|
13
20
|
|
14
|
-
* 2.3
|
15
|
-
* 2.4
|
16
|
-
* 2.5
|
17
|
-
* 2.6
|
21
|
+
* 2.3
|
22
|
+
* 2.4
|
23
|
+
* 2.5
|
24
|
+
* 2.6
|
25
|
+
* 2.7
|
26
|
+
* 3.0
|
18
27
|
|
19
28
|
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
29
|
|
@@ -27,7 +36,16 @@ Audited is currently ActiveRecord-only. In a previous life, Audited worked with
|
|
27
36
|
Add the gem to your Gemfile:
|
28
37
|
|
29
38
|
```ruby
|
30
|
-
gem "audited", "~>
|
39
|
+
gem "audited", "~> 5.0"
|
40
|
+
```
|
41
|
+
|
42
|
+
And if you're using ```require: false``` you must add initializers like this:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
#./config/initializers/audited.rb
|
46
|
+
require "audited"
|
47
|
+
|
48
|
+
Audited::Railtie.initializers.each(&:run)
|
31
49
|
```
|
32
50
|
|
33
51
|
Then, from your Rails app directory, create the `audits` table:
|
@@ -143,7 +161,7 @@ class User < ActiveRecord::Base
|
|
143
161
|
end
|
144
162
|
```
|
145
163
|
|
146
|
-
You can update an audit if
|
164
|
+
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
165
|
|
148
166
|
```ruby
|
149
167
|
class User < ActiveRecord::Base
|
@@ -153,7 +171,7 @@ end
|
|
153
171
|
|
154
172
|
### Limiting stored audits
|
155
173
|
|
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:
|
174
|
+
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
175
|
|
158
176
|
```ruby
|
159
177
|
Audited.max_audits = 10 # keep only 10 latest audits
|
@@ -192,7 +210,7 @@ class PostsController < ApplicationController
|
|
192
210
|
end
|
193
211
|
```
|
194
212
|
|
195
|
-
To use a method other than `current_user`, put the following in an initializer:
|
213
|
+
To use a method other than `current_user`, put the following in an initializer file (`config/initializers/audited.rb`):
|
196
214
|
|
197
215
|
```ruby
|
198
216
|
Audited.current_user_method = :authenticated_user
|
@@ -234,6 +252,16 @@ end
|
|
234
252
|
post.audits.last.user # => 'console-user-username'
|
235
253
|
```
|
236
254
|
|
255
|
+
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:
|
256
|
+
|
257
|
+
```rb
|
258
|
+
Audited.store[:audited_user] = "username"
|
259
|
+
|
260
|
+
# or
|
261
|
+
|
262
|
+
Audited.store[:audited_user] = User.find(1)
|
263
|
+
```
|
264
|
+
|
237
265
|
### Associated Audits
|
238
266
|
|
239
267
|
Sometimes it's useful to associate an audit with a model other than the one being changed. For instance, given the following models:
|
@@ -378,6 +406,16 @@ Audited.config do |config|
|
|
378
406
|
end
|
379
407
|
```
|
380
408
|
|
409
|
+
### Enum Storage
|
410
|
+
|
411
|
+
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:
|
412
|
+
|
413
|
+
```ruby
|
414
|
+
# config/initializers/audited.rb
|
415
|
+
|
416
|
+
Audited.store_synthesized_enums = true
|
417
|
+
```
|
418
|
+
|
381
419
|
## Support
|
382
420
|
|
383
421
|
You can find documentation at: http://rdoc.info/github/collectiveidea/audited
|
data/Rakefile
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "bundler/gem_helper"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
require "rake/testtask"
|
6
|
+
require "appraisal"
|
7
7
|
|
8
|
-
Bundler::GemHelper.install_tasks(name:
|
8
|
+
Bundler::GemHelper.install_tasks(name: "audited")
|
9
9
|
|
10
10
|
RSpec::Core::RakeTask.new(:spec)
|
11
11
|
|
12
12
|
Rake::TestTask.new do |t|
|
13
13
|
t.libs << "test"
|
14
|
-
t.test_files = FileList[
|
14
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
15
15
|
t.verbose = true
|
16
16
|
end
|
17
17
|
|
data/gemfiles/rails60.gemfile
CHANGED