paper_trail_manager 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +13 -47
- data/.gitignore +2 -2
- data/.ruby-version +1 -0
- data/Appraisals +9 -17
- data/CHANGES.md +29 -0
- data/README.md +130 -66
- data/Rakefile +5 -3
- data/app/controllers/paper_trail_manager/changes_controller.rb +24 -9
- data/app/helpers/paper_trail_manager/changes_helper.rb +2 -2
- data/app/views/paper_trail_manager/changes/_version.html.erb +5 -5
- data/app/views/paper_trail_manager/changes/index.html.erb +44 -30
- data/app/views/paper_trail_manager/changes/show.html.erb +10 -7
- data/config/locales/en.yml +30 -0
- data/gemfiles/rails_6.1_paper_trail_12.0_kaminari.gemfile +10 -0
- data/gemfiles/rails_6.1_paper_trail_12.0_will_paginate.gemfile +10 -0
- data/gemfiles/rails_7.0_paper_trail_12.0_kaminari.gemfile +10 -0
- data/gemfiles/rails_7.0_paper_trail_12.0_will_paginate.gemfile +10 -0
- data/gemfiles/rails_7.0_paper_trail_15.0_kaminari.gemfile +10 -0
- data/gemfiles/rails_7.0_paper_trail_15.0_will_paginate.gemfile +10 -0
- data/gemfiles/rails_7.1_paper_trail_15.0_kaminari.gemfile +10 -0
- data/gemfiles/rails_7.1_paper_trail_15.0_will_paginate.gemfile +10 -0
- data/lib/generators/paper_trail_manager/install/install_generator.rb +36 -0
- data/lib/generators/paper_trail_manager/install/templates/initializer.rb +35 -0
- data/lib/paper_trail_manager.rb +8 -2
- data/paper_trail_manager.gemspec +14 -14
- data/spec/app_template.rb +19 -10
- data/spec/integration/authorization_spec.rb +84 -0
- data/spec/integration/date_filter_spec.rb +84 -0
- data/spec/integration/navigation_spec.rb +1 -1
- data/spec/integration/paper_trail_manager_spec.rb +6 -6
- data/spec/integration/response_formats_spec.rb +73 -0
- data/spec/support/factories.rb +2 -2
- data/spec/unit/authorization_spec.rb +42 -0
- data/spec/unit/changes_helper_spec.rb +81 -0
- metadata +78 -59
- data/gemfiles/rails_4.2.2_paper_trail_3.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_4.2.2_paper_trail_3.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_4.2.2_paper_trail_4.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_4.2.2_paper_trail_4.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_4.2.2_paper_trail_5.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_4.2.2_paper_trail_5.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_4.2.2_paper_trail_6.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_4.2.2_paper_trail_6.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_4.2.2_paper_trail_7.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_4.2.2_paper_trail_7.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_4.2.2_paper_trail_8.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_4.2.2_paper_trail_8.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_5.0.0_paper_trail_5.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_5.0.0_paper_trail_5.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_5.0.0_paper_trail_6.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_5.0.0_paper_trail_6.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_5.0.0_paper_trail_7.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_5.0.0_paper_trail_7.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_5.0.0_paper_trail_8.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_5.0.0_paper_trail_8.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_5.1.0_paper_trail_10.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_5.1.0_paper_trail_10.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_5.1.0_paper_trail_7.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_5.1.0_paper_trail_7.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_5.1.0_paper_trail_8.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_5.1.0_paper_trail_8.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_5.1.0_paper_trail_9.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_5.1.0_paper_trail_9.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_5.2.0_paper_trail_10.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_5.2.0_paper_trail_10.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_5.2.0_paper_trail_9.0_kaminari.gemfile +0 -13
- data/gemfiles/rails_5.2.0_paper_trail_9.0_will_paginate.gemfile +0 -13
- data/gemfiles/rails_6.0.0_paper_trail_10.0_kaminari.gemfile +0 -14
- data/gemfiles/rails_6.0.0_paper_trail_10.0_will_paginate.gemfile +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 80cf0bf04cd19250486c5f63d4c8e77550cd284660086ab3dedd0e720b876045
|
|
4
|
+
data.tar.gz: 9c1e1dac59e08f4111f3eb77eeeae8a4c7ac1cc6a162eb22f9eda673963baecb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5a8551d300e427b19f5545974fac2d117e18762311b4a0934100cf9a4976088ee62d60e30d01c2630b2c6c77ad8012ebe588f048ae5c4a812eaa37c3029d6cd5
|
|
7
|
+
data.tar.gz: dbc3aa2206a36873d6f7cb06c4b15d226c3bcc86cc10a6cb80c83139a888c840d2831b3b1d2df087e0cc35361fcc0e2ff482559b465ed1633cdae7557c93977c
|
data/.github/workflows/test.yml
CHANGED
|
@@ -19,64 +19,30 @@ jobs:
|
|
|
19
19
|
fail-fast: false
|
|
20
20
|
matrix:
|
|
21
21
|
ruby:
|
|
22
|
-
-
|
|
23
|
-
- 2
|
|
22
|
+
- '3.1'
|
|
23
|
+
- '3.2'
|
|
24
|
+
- '3.3'
|
|
24
25
|
gemfile:
|
|
25
|
-
- gemfiles/
|
|
26
|
-
- gemfiles/
|
|
27
|
-
- gemfiles/
|
|
28
|
-
- gemfiles/
|
|
29
|
-
- gemfiles/
|
|
30
|
-
- gemfiles/
|
|
31
|
-
- gemfiles/rails_4.2.2_paper_trail_6.0_kaminari.gemfile
|
|
32
|
-
- gemfiles/rails_4.2.2_paper_trail_6.0_will_paginate.gemfile
|
|
33
|
-
- gemfiles/rails_4.2.2_paper_trail_7.0_kaminari.gemfile
|
|
34
|
-
- gemfiles/rails_4.2.2_paper_trail_7.0_will_paginate.gemfile
|
|
35
|
-
- gemfiles/rails_4.2.2_paper_trail_8.0_kaminari.gemfile
|
|
36
|
-
- gemfiles/rails_4.2.2_paper_trail_8.0_will_paginate.gemfile
|
|
37
|
-
- gemfiles/rails_5.0.0_paper_trail_5.0_kaminari.gemfile
|
|
38
|
-
- gemfiles/rails_5.0.0_paper_trail_5.0_will_paginate.gemfile
|
|
39
|
-
- gemfiles/rails_5.0.0_paper_trail_6.0_kaminari.gemfile
|
|
40
|
-
- gemfiles/rails_5.0.0_paper_trail_6.0_will_paginate.gemfile
|
|
41
|
-
- gemfiles/rails_5.0.0_paper_trail_7.0_kaminari.gemfile
|
|
42
|
-
- gemfiles/rails_5.0.0_paper_trail_7.0_will_paginate.gemfile
|
|
43
|
-
- gemfiles/rails_5.0.0_paper_trail_8.0_kaminari.gemfile
|
|
44
|
-
- gemfiles/rails_5.0.0_paper_trail_8.0_will_paginate.gemfile
|
|
45
|
-
- gemfiles/rails_5.1.0_paper_trail_10.0_kaminari.gemfile
|
|
46
|
-
- gemfiles/rails_5.1.0_paper_trail_10.0_will_paginate.gemfile
|
|
47
|
-
- gemfiles/rails_5.1.0_paper_trail_7.0_kaminari.gemfile
|
|
48
|
-
- gemfiles/rails_5.1.0_paper_trail_7.0_will_paginate.gemfile
|
|
49
|
-
- gemfiles/rails_5.1.0_paper_trail_8.0_kaminari.gemfile
|
|
50
|
-
- gemfiles/rails_5.1.0_paper_trail_8.0_will_paginate.gemfile
|
|
51
|
-
- gemfiles/rails_5.1.0_paper_trail_9.0_kaminari.gemfile
|
|
52
|
-
- gemfiles/rails_5.1.0_paper_trail_9.0_will_paginate.gemfile
|
|
53
|
-
- gemfiles/rails_5.2.0_paper_trail_10.0_kaminari.gemfile
|
|
54
|
-
- gemfiles/rails_5.2.0_paper_trail_10.0_will_paginate.gemfile
|
|
55
|
-
- gemfiles/rails_5.2.0_paper_trail_9.0_kaminari.gemfile
|
|
56
|
-
- gemfiles/rails_5.2.0_paper_trail_9.0_will_paginate.gemfile
|
|
57
|
-
- gemfiles/rails_6.0.0_paper_trail_10.0_kaminari.gemfile
|
|
58
|
-
- gemfiles/rails_6.0.0_paper_trail_10.0_will_paginate.gemfile
|
|
26
|
+
- gemfiles/rails_7.0_paper_trail_12.0_kaminari.gemfile
|
|
27
|
+
- gemfiles/rails_7.0_paper_trail_12.0_will_paginate.gemfile
|
|
28
|
+
- gemfiles/rails_7.0_paper_trail_15.0_kaminari.gemfile
|
|
29
|
+
- gemfiles/rails_7.0_paper_trail_15.0_will_paginate.gemfile
|
|
30
|
+
- gemfiles/rails_7.1_paper_trail_15.0_kaminari.gemfile
|
|
31
|
+
- gemfiles/rails_7.1_paper_trail_15.0_will_paginate.gemfile
|
|
59
32
|
|
|
60
33
|
env:
|
|
61
|
-
BUNDLER_VERSION: 1.17.3
|
|
62
34
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
|
63
35
|
|
|
64
36
|
steps:
|
|
65
|
-
- uses: actions/checkout@
|
|
66
|
-
- uses:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
- uses: ruby/setup-ruby@v1
|
|
67
39
|
with:
|
|
68
40
|
ruby-version: ${{ matrix.ruby }}
|
|
69
|
-
|
|
70
|
-
with:
|
|
71
|
-
path: vendor/bundle
|
|
72
|
-
key: ${{ runner.os }}-${{ matrix.ruby}}-gems-${{ hashFiles('**/paper_trail_manager.gemspec') }}
|
|
73
|
-
restore-keys: |
|
|
74
|
-
${{ runner.os }}-${{ matrix.ruby }}-gems-
|
|
41
|
+
bundler-cache: true
|
|
75
42
|
- name: Install System Dependencies
|
|
76
43
|
run: |
|
|
77
44
|
sudo apt-get update
|
|
78
|
-
sudo apt-get install sqlite3 libsqlite3-dev
|
|
79
|
-
gem install bundler -v $BUNDLER_VERSION
|
|
45
|
+
sudo apt-get install -y sqlite3 libsqlite3-dev
|
|
80
46
|
- name: bundle install
|
|
81
47
|
run: |
|
|
82
48
|
bundle config path vendor/bundle
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.3.0
|
data/Appraisals
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
{
|
|
4
|
-
'
|
|
5
|
-
'
|
|
6
|
-
'
|
|
7
|
-
'5.2.0' => %w[9.0 10.0],
|
|
8
|
-
'6.0.0' => %w[10.0]
|
|
4
|
+
'6.1' => %w[12.0],
|
|
5
|
+
'7.0' => %w[12.0 15.0],
|
|
6
|
+
'7.1' => %w[15.0]
|
|
9
7
|
}.each do |rails_version, paper_trail_versions|
|
|
10
8
|
paper_trail_versions.each do |paper_trail_version|
|
|
11
9
|
appraise "rails-#{rails_version}-paper_trail-#{paper_trail_version}-will-paginate" do
|
|
12
|
-
gem 'rails', "~> #{rails_version}"
|
|
13
|
-
gem '
|
|
14
|
-
gem 'sqlite3', rails_version == '6.0.0' ? '~> 1.4' : '~> 1.3.6'
|
|
10
|
+
gem 'rails', "~> #{rails_version}.0"
|
|
11
|
+
gem 'sqlite3', '~> 1.7'
|
|
15
12
|
gem 'paper_trail', "~> #{paper_trail_version}"
|
|
16
|
-
gem 'will_paginate', '~>
|
|
17
|
-
|
|
18
|
-
gem 'webpacker' if rails_version == '6.0.0'
|
|
13
|
+
gem 'will_paginate', '~> 4.0'
|
|
19
14
|
end
|
|
20
15
|
|
|
21
16
|
appraise "rails-#{rails_version}-paper_trail-#{paper_trail_version}-kaminari" do
|
|
22
|
-
gem 'rails', "~> #{rails_version}"
|
|
23
|
-
gem '
|
|
24
|
-
gem 'sqlite3', rails_version == '6.0.0' ? '~> 1.4' : '~> 1.3.6'
|
|
17
|
+
gem 'rails', "~> #{rails_version}.0"
|
|
18
|
+
gem 'sqlite3', '~> 1.7'
|
|
25
19
|
gem 'paper_trail', "~> #{paper_trail_version}"
|
|
26
|
-
gem 'kaminari', '>= 0
|
|
27
|
-
|
|
28
|
-
gem 'webpacker' if rails_version == '6.0.0'
|
|
20
|
+
gem 'kaminari', '>= 1.0'
|
|
29
21
|
end
|
|
30
22
|
end
|
|
31
23
|
end
|
data/CHANGES.md
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
Changes to `paper_trail_manager`
|
|
2
2
|
================================
|
|
3
3
|
|
|
4
|
+
* 0.9.0
|
|
5
|
+
* Add date range filtering to changes index via `from` and `to` query parameters
|
|
6
|
+
* Add date filter UI with date inputs, filter button, and clear link
|
|
7
|
+
* Add Rails install generator (`rails generate paper_trail_manager:install`)
|
|
8
|
+
* Add I18n support for all UI strings (30 translation keys, default English locale)
|
|
9
|
+
* Add authorization integration tests (unauthorized index/show/revert, non-existent records)
|
|
10
|
+
* Add unit tests for ChangesHelper methods (text_or_nil, changes_for, change_item_types, version_reify)
|
|
11
|
+
* Add specs for JSON and Atom response formats with filter coverage
|
|
12
|
+
* Host apps can override any translation key in their own locale files
|
|
13
|
+
* Test count: 19 → 50
|
|
14
|
+
|
|
15
|
+
* 0.8.0
|
|
16
|
+
* Fix `allow_show?` calling `allow_index_block` instead of `allow_show_block` — `allow_show_when` configuration was previously silently ignored (security fix)
|
|
17
|
+
* Fix gemspec `authors` field being overwritten by misplaced `email` assignment
|
|
18
|
+
* Fix `PER_PAGE` constant (50) not being used as default pagination
|
|
19
|
+
* Fix broken HTML structure in show view (nested `<tr>` tags) and index view (unwrapped `<td>`)
|
|
20
|
+
* Add date range filtering to changes index via `from` and `to` query parameters
|
|
21
|
+
* Add date filter UI with date inputs, filter button, and clear link
|
|
22
|
+
* Add authorization integration tests (unauthorized index/show/revert, non-existent records)
|
|
23
|
+
* Add unit tests for ChangesHelper methods (text_or_nil, changes_for, change_item_types, version_reify)
|
|
24
|
+
* Add specs for JSON and Atom response formats with filter coverage
|
|
25
|
+
* Add date range filter tests
|
|
26
|
+
* Drop support for Rails < 7.0
|
|
27
|
+
* Drop Rails 6.1 from CI matrix (incompatible with Ruby 3.1+)
|
|
28
|
+
* Fix `rails new` asset pipeline error in CI for Rails 7.0/7.1
|
|
29
|
+
* Fix `Psych::DisallowedClass` error on revert tests (Ruby 3.1+ YAML deserialization)
|
|
30
|
+
* Add support for Ruby 3.1, 3.2, and 3.3
|
|
31
|
+
* Add support for PaperTrail 12.x and 15.x
|
|
32
|
+
|
|
4
33
|
* 0.7.0
|
|
5
34
|
* Add support for Rails 5 and 6
|
|
6
35
|
* Add support for paper_trail 5.x – 10.x
|
data/README.md
CHANGED
|
@@ -1,109 +1,173 @@
|
|
|
1
|
-
[](http://travis-ci.org/fusion94/paper_trail_manager)
|
|
2
|
-
|
|
3
1
|
# PaperTrailManager
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
[](https://github.com/DamageLabs/paper_trail_manager/actions/workflows/test.yml)
|
|
4
|
+
[](https://rubygems.org/gems/paper_trail_manager)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.ruby-lang.org/)
|
|
7
|
+
[](https://rubyonrails.org/)
|
|
8
|
+
|
|
9
|
+
Browse, view, and revert changes to records in Ruby on Rails applications using the [paper_trail](https://github.com/paper-trail-gem/paper_trail) gem.
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
- **Ruby** >= 3.1
|
|
14
|
+
- **Rails** >= 7.0, < 8.0
|
|
15
|
+
- **PaperTrail** >= 12.0
|
|
16
|
+
- A pagination library: [will_paginate](https://github.com/mislav/will_paginate) or [Kaminari](https://github.com/kaminari/kaminari)
|
|
8
17
|
|
|
9
18
|
## Installation
|
|
10
19
|
|
|
11
|
-
|
|
20
|
+
Add to your `Gemfile`:
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
gem 'paper_trail_manager'
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If you don't already use a pagination library, add one:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
gem 'kaminari'
|
|
30
|
+
# or
|
|
31
|
+
gem 'will_paginate'
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Install:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
bundle install
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Add the route to `config/routes.rb`:
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
resources :changes, controller: 'paper_trail_manager/changes'
|
|
44
|
+
```
|
|
12
45
|
|
|
13
|
-
|
|
46
|
+
Restart your server and visit `/changes` to browse, view, and revert your changes.
|
|
14
47
|
|
|
15
|
-
|
|
48
|
+
## Configuration
|
|
16
49
|
|
|
17
|
-
|
|
50
|
+
Create an initializer (e.g. `config/initializers/paper_trail_manager.rb`) to customize behavior.
|
|
18
51
|
|
|
19
|
-
|
|
20
|
-
#or
|
|
21
|
-
gem 'will_paginate'
|
|
52
|
+
### Authorization
|
|
22
53
|
|
|
23
|
-
|
|
54
|
+
Control access to the index, show, and revert actions independently:
|
|
24
55
|
|
|
25
|
-
|
|
56
|
+
```ruby
|
|
57
|
+
# Control who can view the changes index
|
|
58
|
+
PaperTrailManager.allow_index_when do |controller|
|
|
59
|
+
controller.current_user.present?
|
|
60
|
+
end
|
|
26
61
|
|
|
27
|
-
|
|
62
|
+
# Control who can view individual change details (defaults to allow_index rules)
|
|
63
|
+
PaperTrailManager.allow_show_when do |controller, version|
|
|
64
|
+
controller.current_user&.admin? || version.whodunnit == controller.current_user&.id&.to_s
|
|
65
|
+
end
|
|
28
66
|
|
|
29
|
-
|
|
67
|
+
# Control who can revert changes
|
|
68
|
+
PaperTrailManager.allow_revert_when do |controller, version|
|
|
69
|
+
controller.current_user&.admin?
|
|
70
|
+
end
|
|
71
|
+
```
|
|
30
72
|
|
|
31
|
-
|
|
73
|
+
> **Note:** If you only call `allow_index_when`, the same block is used as the default for `allow_show_when`. Call `allow_show_when` separately to override show authorization independently.
|
|
32
74
|
|
|
33
|
-
|
|
75
|
+
### Whodunnit
|
|
34
76
|
|
|
35
|
-
|
|
77
|
+
Configure how to look up users referenced in PaperTrail's `whodunnit` column:
|
|
36
78
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
79
|
+
```ruby
|
|
80
|
+
PaperTrailManager.whodunnit_class = User
|
|
81
|
+
PaperTrailManager.whodunnit_name_method = :nicename # defaults to :name
|
|
82
|
+
```
|
|
40
83
|
|
|
41
|
-
|
|
84
|
+
### Item Names
|
|
42
85
|
|
|
43
|
-
|
|
44
|
-
controller.current_user and controller.current_user.admin?
|
|
45
|
-
end
|
|
86
|
+
Specify a method to identify items on the index page:
|
|
46
87
|
|
|
47
|
-
|
|
88
|
+
```ruby
|
|
89
|
+
PaperTrailManager.item_name_method = :nicename
|
|
90
|
+
```
|
|
48
91
|
|
|
49
|
-
|
|
50
|
-
PaperTrailManager.whodunnit_name_method = :nicename # defaults to :name
|
|
92
|
+
### User Links
|
|
51
93
|
|
|
52
|
-
|
|
94
|
+
Customize (or disable) the user path helper:
|
|
53
95
|
|
|
54
|
-
|
|
96
|
+
```ruby
|
|
97
|
+
PaperTrailManager.user_path_method = :admin_path # defaults to :user_path
|
|
98
|
+
PaperTrailManager.user_path_method = nil # no user link
|
|
99
|
+
```
|
|
55
100
|
|
|
56
|
-
|
|
101
|
+
### Pagination
|
|
57
102
|
|
|
58
|
-
|
|
59
|
-
PaperTrailManager.user_path_method = nil # no "show user" page in app
|
|
103
|
+
The index page defaults to 50 items per page. Override via query parameter:
|
|
60
104
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
105
|
+
```
|
|
106
|
+
/changes?per_page=25
|
|
107
|
+
```
|
|
64
108
|
|
|
65
|
-
|
|
66
|
-
PaperTrailManager.route_helpers = MyEngine::Engine.routes.url_helpers
|
|
109
|
+
### Engine Integration
|
|
67
110
|
|
|
68
|
-
|
|
111
|
+
When embedding PaperTrailManager inside another Rails engine:
|
|
69
112
|
|
|
70
|
-
|
|
113
|
+
```ruby
|
|
114
|
+
PaperTrailManager.base_controller = "MyEngine::ApplicationController"
|
|
115
|
+
PaperTrailManager.route_helpers = MyEngine::Engine.routes.url_helpers
|
|
116
|
+
PaperTrailManager.layout = 'my_engine/application'
|
|
117
|
+
```
|
|
71
118
|
|
|
72
119
|
## Development
|
|
73
120
|
|
|
74
121
|
Setup:
|
|
75
122
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
123
|
+
```sh
|
|
124
|
+
git clone https://github.com/DamageLabs/paper_trail_manager.git
|
|
125
|
+
cd paper_trail_manager
|
|
126
|
+
bundle install
|
|
127
|
+
```
|
|
79
128
|
|
|
80
129
|
Running tests:
|
|
81
130
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
131
|
+
```sh
|
|
132
|
+
appraisal rake
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The first run downloads gems for each Rails version in the test matrix, which may take a while.
|
|
136
|
+
|
|
137
|
+
### Test Matrix
|
|
138
|
+
|
|
139
|
+
Tests run against multiple combinations via [Appraisal](https://github.com/thoughtbot/appraisal):
|
|
140
|
+
|
|
141
|
+
| Rails | PaperTrail | Pagination |
|
|
142
|
+
|-------|-----------|------------|
|
|
143
|
+
| 7.0 | 12.0 | kaminari, will_paginate |
|
|
144
|
+
| 7.0 | 15.0 | kaminari, will_paginate |
|
|
145
|
+
| 7.1 | 15.0 | kaminari, will_paginate |
|
|
146
|
+
|
|
147
|
+
CI runs each combination across Ruby 3.1, 3.2, and 3.3 (18 jobs total).
|
|
148
|
+
|
|
149
|
+
### Adding Support for New Versions
|
|
150
|
+
|
|
151
|
+
1. Update the `Appraisals` file with new version combinations
|
|
152
|
+
2. Run `appraisal generate && appraisal install`
|
|
153
|
+
3. Fix any breaking changes
|
|
154
|
+
4. Submit a pull request
|
|
155
|
+
|
|
156
|
+
## Recent Changes (0.8.0)
|
|
157
|
+
|
|
158
|
+
- **Security fix:** `allow_show?` now correctly delegates to `allow_show_block` (was incorrectly using `allow_index_block`)
|
|
159
|
+
- **Bug fix:** Gemspec `authors` field was being overwritten by `email`
|
|
160
|
+
- **Bug fix:** `PER_PAGE` constant (50) now used as pagination default
|
|
161
|
+
- **CI:** Dropped Rails 6.1 (incompatible with Ruby 3.1+), fixed Psych deserialization, added asset pipeline skip
|
|
162
|
+
- **Tests:** Added unit tests for authorization block delegation
|
|
163
|
+
- Modernized for Ruby 3.1–3.3 and Rails 7.0–7.1
|
|
164
|
+
|
|
165
|
+
See [CHANGES.md](CHANGES.md) for full history.
|
|
102
166
|
|
|
103
167
|
## License
|
|
104
168
|
|
|
105
|
-
|
|
169
|
+
MIT — see [LICENSE.txt](LICENSE.txt) for details.
|
|
106
170
|
|
|
107
|
-
##
|
|
171
|
+
## History
|
|
108
172
|
|
|
109
|
-
This project was originally
|
|
173
|
+
This project was originally developed by [Igal Koshevoy](https://github.com/igal). Igal passed away on April 9th, 2013, and [Tony Guntharp](https://github.com/fusion94) took over maintenance of the project.
|
data/Rakefile
CHANGED
|
@@ -29,8 +29,10 @@ end
|
|
|
29
29
|
|
|
30
30
|
task :generate_spec_app do
|
|
31
31
|
sh 'rm -rf spec/dummy'
|
|
32
|
-
sh 'rails new spec/dummy --skip-bootsnap --skip-bundle
|
|
33
|
-
--skip-git --skip-action-mailer --skip-puma --skip-test
|
|
34
|
-
--skip-spring --skip-
|
|
32
|
+
sh 'rails new spec/dummy --skip-bootsnap --skip-bundle \
|
|
33
|
+
--skip-git --skip-action-mailer --skip-puma --skip-test \
|
|
34
|
+
--skip-spring --skip-hotwire --skip-jbuilder \
|
|
35
|
+
--skip-action-mailbox --skip-action-text --skip-active-storage \
|
|
36
|
+
--skip-asset-pipeline \
|
|
35
37
|
--template=spec/app_template.rb'
|
|
36
38
|
end
|
|
@@ -15,7 +15,7 @@ class PaperTrailManager
|
|
|
15
15
|
# List changes
|
|
16
16
|
def index
|
|
17
17
|
unless change_index_allowed?
|
|
18
|
-
flash[:error] = '
|
|
18
|
+
flash[:error] = t('paper_trail_manager.flash.index_denied')
|
|
19
19
|
return(redirect_to root_url)
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -23,12 +23,18 @@ class PaperTrailManager
|
|
|
23
23
|
@versions = @versions.where(item_type: params[:type]) if params[:type]
|
|
24
24
|
@versions = @versions.where(item_id: params[:id]) if params[:id]
|
|
25
25
|
|
|
26
|
+
# Date range filtering
|
|
27
|
+
@from = parse_date(params[:from])
|
|
28
|
+
@to = parse_date(params[:to])
|
|
29
|
+
@versions = @versions.where('created_at >= ?', @from.beginning_of_day) if @from
|
|
30
|
+
@versions = @versions.where('created_at <= ?', @to.end_of_day) if @to
|
|
31
|
+
|
|
26
32
|
# Ensure pagination parameters have sensible values
|
|
27
33
|
@page = params[:page].to_i
|
|
28
34
|
@page = nil if @page.zero?
|
|
29
35
|
|
|
30
36
|
@per_page = params[:per_page].to_i
|
|
31
|
-
@per_page =
|
|
37
|
+
@per_page = PER_PAGE if @per_page.zero?
|
|
32
38
|
|
|
33
39
|
@versions = if defined?(WillPaginate)
|
|
34
40
|
@versions.paginate(page: @page, per_page: @per_page)
|
|
@@ -48,12 +54,12 @@ class PaperTrailManager
|
|
|
48
54
|
begin
|
|
49
55
|
@version = PaperTrail::Version.find(params[:id])
|
|
50
56
|
rescue ActiveRecord::RecordNotFound
|
|
51
|
-
flash[:error] = '
|
|
57
|
+
flash[:error] = t('paper_trail_manager.flash.not_found')
|
|
52
58
|
return(redirect_to action: :index)
|
|
53
59
|
end
|
|
54
60
|
|
|
55
61
|
unless change_show_allowed?(@version)
|
|
56
|
-
flash[:error] = '
|
|
62
|
+
flash[:error] = t('paper_trail_manager.flash.show_denied')
|
|
57
63
|
return(redirect_to action: :index)
|
|
58
64
|
end
|
|
59
65
|
|
|
@@ -68,12 +74,12 @@ class PaperTrailManager
|
|
|
68
74
|
begin
|
|
69
75
|
@version = PaperTrail::Version.find(params[:id])
|
|
70
76
|
rescue ActiveRecord::RecordNotFound
|
|
71
|
-
flash[:error] = '
|
|
77
|
+
flash[:error] = t('paper_trail_manager.flash.not_found')
|
|
72
78
|
return(redirect_to(changes_path))
|
|
73
79
|
end
|
|
74
80
|
|
|
75
81
|
unless change_revert_allowed?(@version)
|
|
76
|
-
flash[:error] = '
|
|
82
|
+
flash[:error] = t('paper_trail_manager.flash.revert_denied')
|
|
77
83
|
return(redirect_to changes_path)
|
|
78
84
|
end
|
|
79
85
|
|
|
@@ -87,14 +93,14 @@ class PaperTrailManager
|
|
|
87
93
|
|
|
88
94
|
if @result
|
|
89
95
|
if @version.event == 'create'
|
|
90
|
-
flash[:notice] = '
|
|
96
|
+
flash[:notice] = t('paper_trail_manager.flash.rollback_create')
|
|
91
97
|
redirect_to changes_path
|
|
92
98
|
else
|
|
93
|
-
flash[:notice] = '
|
|
99
|
+
flash[:notice] = t('paper_trail_manager.flash.rollback_update')
|
|
94
100
|
redirect_to change_item_url(@version)
|
|
95
101
|
end
|
|
96
102
|
else
|
|
97
|
-
flash[:error] =
|
|
103
|
+
flash[:error] = t('paper_trail_manager.flash.rollback_failed')
|
|
98
104
|
redirect_to changes_path
|
|
99
105
|
end
|
|
100
106
|
end
|
|
@@ -127,5 +133,14 @@ class PaperTrailManager
|
|
|
127
133
|
PaperTrailManager.allow_revert?(self, version)
|
|
128
134
|
end
|
|
129
135
|
helper_method :change_revert_allowed?
|
|
136
|
+
|
|
137
|
+
# Parse a date string, returning nil for invalid/missing values
|
|
138
|
+
def parse_date(value)
|
|
139
|
+
return nil if value.blank?
|
|
140
|
+
|
|
141
|
+
Date.parse(value)
|
|
142
|
+
rescue Date::Error, ArgumentError
|
|
143
|
+
nil
|
|
144
|
+
end
|
|
130
145
|
end
|
|
131
146
|
end
|
|
@@ -59,9 +59,9 @@ class PaperTrailManager
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def change_item_types
|
|
62
|
-
ActiveRecord::Base.
|
|
62
|
+
ActiveRecord::Base.descendants.select do |klass|
|
|
63
63
|
klass.include?(PaperTrail::Model::InstanceMethods)
|
|
64
|
-
end.map(&:to_s)
|
|
64
|
+
end.map(&:to_s).sort
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
# Returns HTML link for the item stored in the version, e.g. a link to a Company record stored in the version.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<tr class='change_row <%= "change_event_#{version.event} #{version.event} #{version.event}, #{version.item_type.downcase}" %>'>
|
|
2
2
|
<td class='change_time'>
|
|
3
|
-
<span class='change_id'
|
|
3
|
+
<span class='change_id'><%= t('paper_trail_manager.changes.version.change_id', id: version.id) %></span>
|
|
4
4
|
<div class='date'> <%= version.created_at.strftime('%Y-%m-%d') %> </div>
|
|
5
5
|
<div class='time'> <%= version.created_at.strftime('%H:%M:%S') %> </div>
|
|
6
6
|
</td>
|
|
@@ -11,16 +11,16 @@
|
|
|
11
11
|
<% if PaperTrailManager.whodunnit_class && version.whodunnit %>
|
|
12
12
|
<% if user = PaperTrailManager.whodunnit_class.find(version.whodunnit) rescue nil %>
|
|
13
13
|
<% if PaperTrailManager.user_path_method && user %>
|
|
14
|
-
by <%= link_to(h(user.send(PaperTrailManager.whodunnit_name_method)), send(:user_path_method, user)) %>
|
|
14
|
+
<%= t('paper_trail_manager.changes.version.by') %> <%= link_to(h(user.send(PaperTrailManager.whodunnit_name_method)), send(:user_path_method, user)) %>
|
|
15
15
|
<% else %>
|
|
16
|
-
by <%= h(user.send(PaperTrailManager.whodunnit_name_method)) %>
|
|
16
|
+
<%= t('paper_trail_manager.changes.version.by') %> <%= h(user.send(PaperTrailManager.whodunnit_name_method)) %>
|
|
17
17
|
<% end %>
|
|
18
18
|
<% else %>
|
|
19
|
-
by <%= version.whodunnit %>
|
|
19
|
+
<%= t('paper_trail_manager.changes.version.by') %> <%= version.whodunnit %>
|
|
20
20
|
<% end %>
|
|
21
21
|
<% end %>
|
|
22
22
|
<% if change_revert_allowed?(version) %>
|
|
23
|
-
<%=
|
|
23
|
+
<%= button_to t('paper_trail_manager.changes.version.roll_back'), change_path(version), method: :put, class: 'rollback', form: { data: { turbo_confirm: t('paper_trail_manager.changes.version.confirm_rollback') } } %>
|
|
24
24
|
<% end %>
|
|
25
25
|
</p>
|
|
26
26
|
<% if version.event == 'update' or version.event == 'create' %>
|