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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +13 -47
  3. data/.gitignore +2 -2
  4. data/.ruby-version +1 -0
  5. data/Appraisals +9 -17
  6. data/CHANGES.md +29 -0
  7. data/README.md +130 -66
  8. data/Rakefile +5 -3
  9. data/app/controllers/paper_trail_manager/changes_controller.rb +24 -9
  10. data/app/helpers/paper_trail_manager/changes_helper.rb +2 -2
  11. data/app/views/paper_trail_manager/changes/_version.html.erb +5 -5
  12. data/app/views/paper_trail_manager/changes/index.html.erb +44 -30
  13. data/app/views/paper_trail_manager/changes/show.html.erb +10 -7
  14. data/config/locales/en.yml +30 -0
  15. data/gemfiles/rails_6.1_paper_trail_12.0_kaminari.gemfile +10 -0
  16. data/gemfiles/rails_6.1_paper_trail_12.0_will_paginate.gemfile +10 -0
  17. data/gemfiles/rails_7.0_paper_trail_12.0_kaminari.gemfile +10 -0
  18. data/gemfiles/rails_7.0_paper_trail_12.0_will_paginate.gemfile +10 -0
  19. data/gemfiles/rails_7.0_paper_trail_15.0_kaminari.gemfile +10 -0
  20. data/gemfiles/rails_7.0_paper_trail_15.0_will_paginate.gemfile +10 -0
  21. data/gemfiles/rails_7.1_paper_trail_15.0_kaminari.gemfile +10 -0
  22. data/gemfiles/rails_7.1_paper_trail_15.0_will_paginate.gemfile +10 -0
  23. data/lib/generators/paper_trail_manager/install/install_generator.rb +36 -0
  24. data/lib/generators/paper_trail_manager/install/templates/initializer.rb +35 -0
  25. data/lib/paper_trail_manager.rb +8 -2
  26. data/paper_trail_manager.gemspec +14 -14
  27. data/spec/app_template.rb +19 -10
  28. data/spec/integration/authorization_spec.rb +84 -0
  29. data/spec/integration/date_filter_spec.rb +84 -0
  30. data/spec/integration/navigation_spec.rb +1 -1
  31. data/spec/integration/paper_trail_manager_spec.rb +6 -6
  32. data/spec/integration/response_formats_spec.rb +73 -0
  33. data/spec/support/factories.rb +2 -2
  34. data/spec/unit/authorization_spec.rb +42 -0
  35. data/spec/unit/changes_helper_spec.rb +81 -0
  36. metadata +78 -59
  37. data/gemfiles/rails_4.2.2_paper_trail_3.0_kaminari.gemfile +0 -13
  38. data/gemfiles/rails_4.2.2_paper_trail_3.0_will_paginate.gemfile +0 -13
  39. data/gemfiles/rails_4.2.2_paper_trail_4.0_kaminari.gemfile +0 -13
  40. data/gemfiles/rails_4.2.2_paper_trail_4.0_will_paginate.gemfile +0 -13
  41. data/gemfiles/rails_4.2.2_paper_trail_5.0_kaminari.gemfile +0 -13
  42. data/gemfiles/rails_4.2.2_paper_trail_5.0_will_paginate.gemfile +0 -13
  43. data/gemfiles/rails_4.2.2_paper_trail_6.0_kaminari.gemfile +0 -13
  44. data/gemfiles/rails_4.2.2_paper_trail_6.0_will_paginate.gemfile +0 -13
  45. data/gemfiles/rails_4.2.2_paper_trail_7.0_kaminari.gemfile +0 -13
  46. data/gemfiles/rails_4.2.2_paper_trail_7.0_will_paginate.gemfile +0 -13
  47. data/gemfiles/rails_4.2.2_paper_trail_8.0_kaminari.gemfile +0 -13
  48. data/gemfiles/rails_4.2.2_paper_trail_8.0_will_paginate.gemfile +0 -13
  49. data/gemfiles/rails_5.0.0_paper_trail_5.0_kaminari.gemfile +0 -13
  50. data/gemfiles/rails_5.0.0_paper_trail_5.0_will_paginate.gemfile +0 -13
  51. data/gemfiles/rails_5.0.0_paper_trail_6.0_kaminari.gemfile +0 -13
  52. data/gemfiles/rails_5.0.0_paper_trail_6.0_will_paginate.gemfile +0 -13
  53. data/gemfiles/rails_5.0.0_paper_trail_7.0_kaminari.gemfile +0 -13
  54. data/gemfiles/rails_5.0.0_paper_trail_7.0_will_paginate.gemfile +0 -13
  55. data/gemfiles/rails_5.0.0_paper_trail_8.0_kaminari.gemfile +0 -13
  56. data/gemfiles/rails_5.0.0_paper_trail_8.0_will_paginate.gemfile +0 -13
  57. data/gemfiles/rails_5.1.0_paper_trail_10.0_kaminari.gemfile +0 -13
  58. data/gemfiles/rails_5.1.0_paper_trail_10.0_will_paginate.gemfile +0 -13
  59. data/gemfiles/rails_5.1.0_paper_trail_7.0_kaminari.gemfile +0 -13
  60. data/gemfiles/rails_5.1.0_paper_trail_7.0_will_paginate.gemfile +0 -13
  61. data/gemfiles/rails_5.1.0_paper_trail_8.0_kaminari.gemfile +0 -13
  62. data/gemfiles/rails_5.1.0_paper_trail_8.0_will_paginate.gemfile +0 -13
  63. data/gemfiles/rails_5.1.0_paper_trail_9.0_kaminari.gemfile +0 -13
  64. data/gemfiles/rails_5.1.0_paper_trail_9.0_will_paginate.gemfile +0 -13
  65. data/gemfiles/rails_5.2.0_paper_trail_10.0_kaminari.gemfile +0 -13
  66. data/gemfiles/rails_5.2.0_paper_trail_10.0_will_paginate.gemfile +0 -13
  67. data/gemfiles/rails_5.2.0_paper_trail_9.0_kaminari.gemfile +0 -13
  68. data/gemfiles/rails_5.2.0_paper_trail_9.0_will_paginate.gemfile +0 -13
  69. data/gemfiles/rails_6.0.0_paper_trail_10.0_kaminari.gemfile +0 -14
  70. 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: fcc29d8525d99579c156724e3ae0632d363f633419b1fe2e3d8424be01a2cc8f
4
- data.tar.gz: 4a18af9ec1ce747d7f1be7cb090172694ac1cd05ff7bfdfe8b4cfbf7a064f73b
3
+ metadata.gz: 80cf0bf04cd19250486c5f63d4c8e77550cd284660086ab3dedd0e720b876045
4
+ data.tar.gz: 9c1e1dac59e08f4111f3eb77eeeae8a4c7ac1cc6a162eb22f9eda673963baecb
5
5
  SHA512:
6
- metadata.gz: b8d7880ea9aee2269b2d99702559bc30323bc3ba932c850124c640e0508ed841f1eb9ed11c81c1af9a233903cfa83f9cc526c0e57e6648a1d3b163c2d48439a8
7
- data.tar.gz: d4daf880c144649090bf0d29d373783890d9b332f41a39c032aa11efb4489432272e60b683904884facdbdc1f62d4ee67d7f8109549e262c5ad3625f7c668240
6
+ metadata.gz: 5a8551d300e427b19f5545974fac2d117e18762311b4a0934100cf9a4976088ee62d60e30d01c2630b2c6c77ad8012ebe588f048ae5c4a812eaa37c3029d6cd5
7
+ data.tar.gz: dbc3aa2206a36873d6f7cb06c4b15d226c3bcc86cc10a6cb80c83139a888c840d2831b3b1d2df087e0cc35361fcc0e2ff482559b465ed1633cdae7557c93977c
@@ -19,64 +19,30 @@ jobs:
19
19
  fail-fast: false
20
20
  matrix:
21
21
  ruby:
22
- - 2.5.7
23
- - 2.6.5
22
+ - '3.1'
23
+ - '3.2'
24
+ - '3.3'
24
25
  gemfile:
25
- - gemfiles/rails_4.2.2_paper_trail_3.0_kaminari.gemfile
26
- - gemfiles/rails_4.2.2_paper_trail_3.0_will_paginate.gemfile
27
- - gemfiles/rails_4.2.2_paper_trail_4.0_kaminari.gemfile
28
- - gemfiles/rails_4.2.2_paper_trail_4.0_will_paginate.gemfile
29
- - gemfiles/rails_4.2.2_paper_trail_5.0_kaminari.gemfile
30
- - gemfiles/rails_4.2.2_paper_trail_5.0_will_paginate.gemfile
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@v2
66
- - uses: actions/setup-ruby@v1
37
+ - uses: actions/checkout@v4
38
+ - uses: ruby/setup-ruby@v1
67
39
  with:
68
40
  ruby-version: ${{ matrix.ruby }}
69
- - uses: actions/cache@v1
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
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
@@ -12,5 +11,6 @@ Gemfile.lock
12
11
  *.o
13
12
  *.a
14
13
  mkmf.log
15
- *.gemfile.lock
16
14
  spec/dummy
15
+ Gemfile.lock
16
+ gemfiles/*.lock
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
- '4.2.2' => %w[3.0 4.0 5.0 6.0 7.0 8.0],
5
- '5.0.0' => %w[5.0 6.0 7.0 8.0],
6
- '5.1.0' => %w[7.0 8.0 9.0 10.0],
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 'jquery-rails'
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', '~> 3.0'
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 'jquery-rails'
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.16'
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
- [![Build Status](https://secure.travis-ci.org/fusion94/paper_trail_manager.png)](http://travis-ci.org/fusion94/paper_trail_manager)
2
-
3
1
  # PaperTrailManager
4
2
 
5
- Browse, subscribe, view and revert changes to records when using Ruby on Rails 3 and the `paper_trail` gem.
3
+ [![CI](https://github.com/DamageLabs/paper_trail_manager/actions/workflows/test.yml/badge.svg)](https://github.com/DamageLabs/paper_trail_manager/actions/workflows/test.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/paper_trail_manager.svg)](https://rubygems.org/gems/paper_trail_manager)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Ruby](https://img.shields.io/badge/Ruby-3.1%2B-red.svg)](https://www.ruby-lang.org/)
7
+ [![Rails](https://img.shields.io/badge/Rails-7.0%2B-red.svg)](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
- This software has been in use for a year at http://calagator.org and http://epdx.org. It works well. It has reasonable tests. However, it could definitely use more work.
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
- If you have a Ruby on Rails 3 or 4 application where you're using the `paper_trail` gem to track changes to your records, you can make use of this like:
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
- Add the following line to your `Gemfile`:
46
+ Restart your server and visit `/changes` to browse, view, and revert your changes.
14
47
 
15
- gem 'paper_trail_manager'
48
+ ## Configuration
16
49
 
17
- PaperTrailManager will use your existing paging library ([will_paginate](https://github.com/mislav/will_paginate) or [Kaminari](https://github.com/amatsuda/kaminari)). If you don't currently use one in your app, add one of the following lines to your `Gemfile`:
50
+ Create an initializer (e.g. `config/initializers/paper_trail_manager.rb`) to customize behavior.
18
51
 
19
- gem 'kaminari'
20
- #or
21
- gem 'will_paginate'
52
+ ### Authorization
22
53
 
23
- Install the libary:
54
+ Control access to the index, show, and revert actions independently:
24
55
 
25
- bundle install
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
- Add the following line to your `config/routes.rb`:
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
- resources :changes, :controller => 'paper_trail_manager/changes'
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
- Restart the server and go to the `/changes` URI to browse, subscribe, view and revert your changes. The top-level URL will look something like this:
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
- http://localhost:3000/changes
75
+ ### Whodunnit
34
76
 
35
- ### Configuration
77
+ Configure how to look up users referenced in PaperTrail's `whodunnit` column:
36
78
 
37
- Several aspects of PaperTrailManager may be optionally configured
38
- by creating an initializer in your application
39
- (e.g. `config/initializers/paper_trail_manager.rb`).
79
+ ```ruby
80
+ PaperTrailManager.whodunnit_class = User
81
+ PaperTrailManager.whodunnit_name_method = :nicename # defaults to :name
82
+ ```
40
83
 
41
- To specify when reverts are allowed:
84
+ ### Item Names
42
85
 
43
- PaperTrailManager.allow_revert_when do |controller, version|
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
- To specify how to look up users/memebers/etc specified in Paper Trail's 'whodunnit' column:
88
+ ```ruby
89
+ PaperTrailManager.item_name_method = :nicename
90
+ ```
48
91
 
49
- PaperTrailManager.whodunnit_class = User
50
- PaperTrailManager.whodunnit_name_method = :nicename # defaults to :name
92
+ ### User Links
51
93
 
52
- To specify a method to call to identify an item on an index page:
94
+ Customize (or disable) the user path helper:
53
95
 
54
- PaperTrailManager.item_name_method = :nicename
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
- And for linking (or not) to the user with a custom path helper:
101
+ ### Pagination
57
102
 
58
- PaperTrailManager.user_path_method = :admin_path # defaults to :user_path
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
- When including PaperTrailManager within another Rails engine, you may need to
62
- override PaperTrailManager::ChangesController's parent class to reference the
63
- engine's ApplicationController configure it to use your engine's url helpers:
105
+ ```
106
+ /changes?per_page=25
107
+ ```
64
108
 
65
- PaperTrailManager.base_controller = "MyEngine::ApplicationController"
66
- PaperTrailManager.route_helpers = MyEngine::Engine.routes.url_helpers
109
+ ### Engine Integration
67
110
 
68
- You can also specify the layout:
111
+ When embedding PaperTrailManager inside another Rails engine:
69
112
 
70
- PaperTrailManager.layout = 'my_engine/application'
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
- * Clone the repository
77
- * Go into the directory
78
- * Run `bundle` to install the development dependencies
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
- * Run `appraisal rake` to run the tests against all supported gem combinations. Note that the first time tests are run, gems will need to be downloaded for each individual version of Rails this app is tested against, which may take a while.
83
-
84
- Adding support for new Rails versions:
85
-
86
- * This repo uses the [Appraisal](https://github.com/thoughtbot/appraisal) gem, to add a new rails version modify the Appraisals file
87
- - Add both a 'will_paginate' and a 'kaminari' version like so:
88
- ```
89
- appraise "rails-5.0-will-paginate" do
90
- gem "rails", "5.0.0"
91
- gem "will_paginate", "~> 3.0"
92
- end
93
- appraise "rails-5.0-will-kaminari" do
94
- gem "rails", "5.0.0"
95
- gem "kaminari", "~> 0.16"
96
- end
97
- ```
98
- * Run `appraisal generate`
99
- * Run `appraisal install`
100
- * Fix whatever breaks.
101
- * Please contribute your fixes with a Github pull request.
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
- This program is provided under an MIT open source license, read the [LICENSE.txt](http://github.com/igal/paper_trail_manager/blob/master/LICENSE.txt) file for details.
169
+ MIT see [LICENSE.txt](LICENSE.txt) for details.
106
170
 
107
- ## To Note:
171
+ ## History
108
172
 
109
- This project was originally devloped by [Igal Koshevoy](http://github.com/igal). Unfortunately @igal passed away on April 9th, 2013 and I took over the project afterwords.
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 --skip-yarn \
33
- --skip-git --skip-action-mailer --skip-puma --skip-test --skip-coffee \
34
- --skip-spring --skip-listen --skip-turbolinks \
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] = 'You do not have permission to list changes.'
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 = nil if @per_page.zero?
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] = 'No such version.'
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] = 'You do not have permission to show that change.'
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] = 'No such version.'
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] = 'You do not have permission to revert this change.'
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] = 'Rolled back newly-created record by destroying it.'
96
+ flash[:notice] = t('paper_trail_manager.flash.rollback_create')
91
97
  redirect_to changes_path
92
98
  else
93
- flash[:notice] = 'Rolled back changes to this record.'
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] = "Couldn't rollback. Sorry."
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.subclasses.select do |klass|
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'>Change #<%= version.id %></span>
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
- <%= link_to 'Roll back', change_path(version), :method => 'put', :class => 'rollback', :data => { :confirm => 'Are you sure?' } %>
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' %>