paper_trail_manager 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 007f0fa99ee11e2fdd0d615ec29d66e74788062b3a8e479091c31427d54add6c
4
- data.tar.gz: a71dfd4c73909f185c580a11eae304ac0fb75e8c16fe92fe890ddeb90d7ace71
3
+ metadata.gz: 80cf0bf04cd19250486c5f63d4c8e77550cd284660086ab3dedd0e720b876045
4
+ data.tar.gz: 9c1e1dac59e08f4111f3eb77eeeae8a4c7ac1cc6a162eb22f9eda673963baecb
5
5
  SHA512:
6
- metadata.gz: b019f63c912f3627025427264b6b48be3347e8fe9ec1145ee1b97347e807e0d5642ff6c06ec5085635d6fe5d18354397865bc85734ade8c015284fa484287220
7
- data.tar.gz: 0f60e85a369b84075a088f2e2cbca20d85895c7ff42c38fcb7d1595f7e503954bd5ea3c19cfa8b393b433ab003e4309f367caeb03dc3997e2e7f913fda167220
6
+ metadata.gz: 5a8551d300e427b19f5545974fac2d117e18762311b4a0934100cf9a4976088ee62d60e30d01c2630b2c6c77ad8012ebe588f048ae5c4a812eaa37c3029d6cd5
7
+ data.tar.gz: dbc3aa2206a36873d6f7cb06c4b15d226c3bcc86cc10a6cb80c83139a888c840d2831b3b1d2df087e0cc35361fcc0e2ff482559b465ed1633cdae7557c93977c
data/CHANGES.md CHANGED
@@ -1,6 +1,17 @@
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
+
4
15
  * 0.8.0
5
16
  * Fix `allow_show?` calling `allow_index_block` instead of `allow_show_block` — `allow_show_when` configuration was previously silently ignored (security fix)
6
17
  * Fix gemspec `authors` field being overwritten by misplaced `email` assignment
@@ -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
 
@@ -54,12 +54,12 @@ class PaperTrailManager
54
54
  begin
55
55
  @version = PaperTrail::Version.find(params[:id])
56
56
  rescue ActiveRecord::RecordNotFound
57
- flash[:error] = 'No such version.'
57
+ flash[:error] = t('paper_trail_manager.flash.not_found')
58
58
  return(redirect_to action: :index)
59
59
  end
60
60
 
61
61
  unless change_show_allowed?(@version)
62
- flash[:error] = 'You do not have permission to show that change.'
62
+ flash[:error] = t('paper_trail_manager.flash.show_denied')
63
63
  return(redirect_to action: :index)
64
64
  end
65
65
 
@@ -74,12 +74,12 @@ class PaperTrailManager
74
74
  begin
75
75
  @version = PaperTrail::Version.find(params[:id])
76
76
  rescue ActiveRecord::RecordNotFound
77
- flash[:error] = 'No such version.'
77
+ flash[:error] = t('paper_trail_manager.flash.not_found')
78
78
  return(redirect_to(changes_path))
79
79
  end
80
80
 
81
81
  unless change_revert_allowed?(@version)
82
- flash[:error] = 'You do not have permission to revert this change.'
82
+ flash[:error] = t('paper_trail_manager.flash.revert_denied')
83
83
  return(redirect_to changes_path)
84
84
  end
85
85
 
@@ -93,14 +93,14 @@ class PaperTrailManager
93
93
 
94
94
  if @result
95
95
  if @version.event == 'create'
96
- flash[:notice] = 'Rolled back newly-created record by destroying it.'
96
+ flash[:notice] = t('paper_trail_manager.flash.rollback_create')
97
97
  redirect_to changes_path
98
98
  else
99
- flash[:notice] = 'Rolled back changes to this record.'
99
+ flash[:notice] = t('paper_trail_manager.flash.rollback_update')
100
100
  redirect_to change_item_url(@version)
101
101
  end
102
102
  else
103
- flash[:error] = "Couldn't rollback. Sorry."
103
+ flash[:error] = t('paper_trail_manager.flash.rollback_failed')
104
104
  redirect_to changes_path
105
105
  end
106
106
  end
@@ -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
- <%= button_to 'Roll back', change_path(version), method: :put, class: 'rollback', form: { data: { turbo_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' %>
@@ -1,22 +1,23 @@
1
- <h1>Changes</h1>
1
+ <h1><%= t('paper_trail_manager.changes.index.title') %></h1>
2
2
 
3
3
  <p>
4
- Show:
5
- <%= ([link_to('All', changes_path)] + change_item_types.map { |type| link_to(type.pluralize, changes_path(type: type)) }).join(' | ').html_safe %>
4
+ <%= t('paper_trail_manager.changes.index.show_label') %>
5
+ <%= ([link_to(t('paper_trail_manager.changes.index.all'), changes_path)] + change_item_types.map { |type| link_to(type.pluralize, changes_path(type: type)) }).join(' | ').html_safe %>
6
6
  </p>
7
7
 
8
8
  <%= form_tag changes_path, method: :get, class: 'changes_date_filter' do %>
9
9
  <%= hidden_field_tag :type, params[:type] if params[:type] %>
10
10
  <%= hidden_field_tag :id, params[:id] if params[:id] %>
11
- <label for="from">From:</label>
11
+ <label for="from"><%= t('paper_trail_manager.changes.filter.from') %></label>
12
12
  <%= date_field_tag :from, params[:from], id: 'from' %>
13
- <label for="to">To:</label>
13
+ <label for="to"><%= t('paper_trail_manager.changes.filter.to') %></label>
14
14
  <%= date_field_tag :to, params[:to], id: 'to' %>
15
- <%= submit_tag 'Filter', name: nil %>
15
+ <%= submit_tag t('paper_trail_manager.changes.filter.submit'), name: nil %>
16
16
  <% if params[:from].present? || params[:to].present? %>
17
- <%= link_to 'Clear', changes_path(type: params[:type], id: params[:id]), class: 'clear_filter' %>
17
+ <%= link_to t('paper_trail_manager.changes.filter.clear'), changes_path(type: params[:type], id: params[:id]), class: 'clear_filter' %>
18
18
  <% end %>
19
19
  <% end %>
20
+
20
21
  <div class="table-responsive">
21
22
  <table class='changes_table table table-bordered'>
22
23
  <tfoot>
@@ -28,8 +29,8 @@
28
29
  </tfoot>
29
30
  <thead>
30
31
  <tr class='changes_header'>
31
- <th class='change_time'>Time</th>
32
- <th class='change_details'>Attribute with previous and current values</th>
32
+ <th class='change_time'><%= t('paper_trail_manager.changes.index.time') %></th>
33
+ <th class='change_details'><%= t('paper_trail_manager.changes.index.details') %></th>
33
34
  </tr>
34
35
  </thead>
35
36
  <tbody>
@@ -40,7 +41,7 @@
40
41
  <% end %>
41
42
  <% else %>
42
43
  <tr>
43
- <td colspan='2'> &mdash; No changes found &mdash; </td>
44
+ <td colspan='2'> &mdash; <%= t('paper_trail_manager.changes.index.no_changes') %> &mdash; </td>
44
45
  </tr>
45
46
  <% end %>
46
47
  </tbody>
@@ -1,10 +1,10 @@
1
- <h1>Change <%= @version.id %></h1>
1
+ <h1><%= t('paper_trail_manager.changes.show.title', id: @version.id) %></h1>
2
2
 
3
3
  <table class='changes_table'>
4
4
  <thead>
5
5
  <tr class='changes_header'>
6
- <th class='change_time'>Time</th>
7
- <th class='change_details'>Attribute with previous and current values</th>
6
+ <th class='change_time'><%= t('paper_trail_manager.changes.index.time') %></th>
7
+ <th class='change_details'><%= t('paper_trail_manager.changes.index.details') %></th>
8
8
  </tr>
9
9
  </thead>
10
10
  <tbody>
@@ -0,0 +1,30 @@
1
+ en:
2
+ paper_trail_manager:
3
+ changes:
4
+ index:
5
+ title: "Changes"
6
+ show_label: "Show:"
7
+ all: "All"
8
+ no_changes: "No changes found"
9
+ time: "Time"
10
+ details: "Attribute with previous and current values"
11
+ show:
12
+ title: "Change %{id}"
13
+ filter:
14
+ from: "From:"
15
+ to: "To:"
16
+ submit: "Filter"
17
+ clear: "Clear"
18
+ version:
19
+ change_id: "Change #%{id}"
20
+ roll_back: "Roll back"
21
+ confirm_rollback: "Are you sure?"
22
+ by: "by"
23
+ flash:
24
+ index_denied: "You do not have permission to list changes."
25
+ show_denied: "You do not have permission to show that change."
26
+ revert_denied: "You do not have permission to revert this change."
27
+ not_found: "No such version."
28
+ rollback_create: "Rolled back newly-created record by destroying it."
29
+ rollback_update: "Rolled back changes to this record."
30
+ rollback_failed: "Couldn't rollback. Sorry."
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+
5
+ class PaperTrailManager
6
+ class InstallGenerator < Rails::Generators::Base
7
+ source_root File.expand_path('templates', __dir__)
8
+ desc 'Install PaperTrailManager: add route and create initializer'
9
+
10
+ def add_route
11
+ route_string = "resources :changes, controller: 'paper_trail_manager/changes'"
12
+ routes_file = File.join(destination_root, 'config/routes.rb')
13
+
14
+ if File.exist?(routes_file) && File.read(routes_file).include?(route_string)
15
+ say_status :skip, 'Route already exists', :yellow
16
+ else
17
+ route route_string
18
+ end
19
+ end
20
+
21
+ def create_initializer
22
+ template 'initializer.rb', 'config/initializers/paper_trail_manager.rb'
23
+ end
24
+
25
+ def show_post_install
26
+ say ''
27
+ say '✅ PaperTrailManager installed!', :green
28
+ say ''
29
+ say 'Next steps:'
30
+ say ' 1. Restart your Rails server'
31
+ say ' 2. Visit /changes to browse your PaperTrail version history'
32
+ say ' 3. Edit config/initializers/paper_trail_manager.rb to customize authorization'
33
+ say ''
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # PaperTrailManager configuration
4
+ # See: https://github.com/DamageLabs/paper_trail_manager
5
+
6
+ # Control who can view the changes index.
7
+ # PaperTrailManager.allow_index_when do |controller|
8
+ # controller.current_user.present?
9
+ # end
10
+
11
+ # Control who can view individual change details.
12
+ # Defaults to the allow_index rules if not set separately.
13
+ # PaperTrailManager.allow_show_when do |controller, version|
14
+ # controller.current_user.present?
15
+ # end
16
+
17
+ # Control who can revert changes.
18
+ # PaperTrailManager.allow_revert_when do |controller, version|
19
+ # controller.current_user&.admin?
20
+ # end
21
+
22
+ # Configure how to look up users referenced in PaperTrail's whodunnit column.
23
+ # PaperTrailManager.whodunnit_class = User
24
+ # PaperTrailManager.whodunnit_name_method = :name
25
+
26
+ # Specify a method to identify items on the index page.
27
+ # PaperTrailManager.item_name_method = :name
28
+
29
+ # Customize the user path helper (set to nil to disable user links).
30
+ # PaperTrailManager.user_path_method = :user_path
31
+
32
+ # When embedding inside another Rails engine:
33
+ # PaperTrailManager.base_controller = 'MyEngine::ApplicationController'
34
+ # PaperTrailManager.route_helpers = MyEngine::Engine.routes.url_helpers
35
+ # PaperTrailManager.layout = 'my_engine/application'
@@ -14,6 +14,10 @@ rescue LoadError
14
14
  end
15
15
 
16
16
  class PaperTrailManager < Rails::Engine
17
+ initializer 'paper_trail_manager.i18n' do
18
+ config.i18n.load_path += Dir[root.join('config', 'locales', '*.yml')]
19
+ end
20
+
17
21
  initializer 'paper_trail_manager.pagination' do
18
22
  if defined?(WillPaginate)
19
23
  ::ActionView::Base.define_method(:paginate) { |*args, **kwargs, &block| will_paginate(*args, **kwargs, &block) }
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'paper_trail_manager'
8
- spec.version = '0.8.0'
8
+ spec.version = '0.9.0'
9
9
  spec.authors = ['Igal Koshevoy', 'Reid Beels']
10
10
  spec.email = ['mail@reidbeels.com']
11
11
  spec.summary = 'A user interface for `paper_trail` versioning data in Rails applications.'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igal Koshevoy
@@ -208,6 +208,7 @@ files:
208
208
  - app/views/paper_trail_manager/changes/index.atom.builder
209
209
  - app/views/paper_trail_manager/changes/index.html.erb
210
210
  - app/views/paper_trail_manager/changes/show.html.erb
211
+ - config/locales/en.yml
211
212
  - gemfiles/rails_6.1_paper_trail_12.0_kaminari.gemfile
212
213
  - gemfiles/rails_6.1_paper_trail_12.0_will_paginate.gemfile
213
214
  - gemfiles/rails_7.0_paper_trail_12.0_kaminari.gemfile
@@ -216,6 +217,8 @@ files:
216
217
  - gemfiles/rails_7.0_paper_trail_15.0_will_paginate.gemfile
217
218
  - gemfiles/rails_7.1_paper_trail_15.0_kaminari.gemfile
218
219
  - gemfiles/rails_7.1_paper_trail_15.0_will_paginate.gemfile
220
+ - lib/generators/paper_trail_manager/install/install_generator.rb
221
+ - lib/generators/paper_trail_manager/install/templates/initializer.rb
219
222
  - lib/paper_trail_manager.rb
220
223
  - paper_trail_manager.gemspec
221
224
  - spec/app_template.rb