demingfactor-paper_trail_manager 0.7.3
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 +7 -0
- data/.github/workflows/test.yml +88 -0
- data/.gitignore +16 -0
- data/.rubocop.yml +33 -0
- data/.tool-versions +1 -0
- data/Appraisals +34 -0
- data/CHANGES.md +62 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +109 -0
- data/Rakefile +36 -0
- data/app/controllers/paper_trail_manager/changes_controller.rb +131 -0
- data/app/helpers/paper_trail_manager/changes_helper.rb +82 -0
- data/app/views/paper_trail_manager/changes/_version.html.erb +40 -0
- data/app/views/paper_trail_manager/changes/index.atom.builder +48 -0
- data/app/views/paper_trail_manager/changes/index.html.erb +35 -0
- data/app/views/paper_trail_manager/changes/show.html.erb +10 -0
- data/demingfactor-paper_trail_manager.gemspec +32 -0
- data/gemfiles/rails_4.2.2_paper_trail_3.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_4.2.2_paper_trail_3.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_4.2.2_paper_trail_4.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_4.2.2_paper_trail_4.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_4.2.2_paper_trail_5.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_4.2.2_paper_trail_5.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_4.2.2_paper_trail_6.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_4.2.2_paper_trail_6.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_4.2.2_paper_trail_7.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_4.2.2_paper_trail_7.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_4.2.2_paper_trail_8.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_4.2.2_paper_trail_8.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_5.0.0_paper_trail_5.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_5.0.0_paper_trail_5.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_5.0.0_paper_trail_6.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_5.0.0_paper_trail_6.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_5.0.0_paper_trail_7.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_5.0.0_paper_trail_7.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_5.0.0_paper_trail_8.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_5.0.0_paper_trail_8.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_5.1.0_paper_trail_10.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_5.1.0_paper_trail_10.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_5.1.0_paper_trail_7.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_5.1.0_paper_trail_7.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_5.1.0_paper_trail_8.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_5.1.0_paper_trail_8.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_5.1.0_paper_trail_9.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_5.1.0_paper_trail_9.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_5.2.0_paper_trail_10.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_5.2.0_paper_trail_10.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_5.2.0_paper_trail_9.0_kaminari.gemfile +11 -0
- data/gemfiles/rails_5.2.0_paper_trail_9.0_will_paginate.gemfile +11 -0
- data/gemfiles/rails_6.0.0_paper_trail_10.0_kaminari.gemfile +12 -0
- data/gemfiles/rails_6.0.0_paper_trail_10.0_will_paginate.gemfile +12 -0
- data/gemfiles/rails_6.1.0_paper_trail_11.1_kaminari.gemfile +12 -0
- data/gemfiles/rails_6.1.0_paper_trail_11.1_will_paginate.gemfile +12 -0
- data/lib/paper_trail_manager.rb +67 -0
- data/spec/app_template.rb +30 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/integration/paper_trail_manager_spec.rb +185 -0
- data/spec/rails_helper.rb +29 -0
- data/spec/spec_helper.rb +91 -0
- data/spec/support/factories.rb +15 -0
- data/spec/support/rspec_html_matchers.rb +7 -0
- metadata +263 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
atom_feed do |feed|
|
4
|
+
feed.title('Changes')
|
5
|
+
date = @versions.first.try(:created_at) || Time.zone.at(0)
|
6
|
+
feed.updated(date)
|
7
|
+
|
8
|
+
@versions.each do |version|
|
9
|
+
next unless change_show_allowed?(version)
|
10
|
+
|
11
|
+
feed.entry(version, url: change_url(version)) do |entry|
|
12
|
+
changes = changes_for(version)
|
13
|
+
|
14
|
+
user = if PaperTrailManager.whodunnit_class && version.whodunnit
|
15
|
+
begin
|
16
|
+
PaperTrailManager.whodunnit_class.find(version.whodunnit)
|
17
|
+
rescue StandardError
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
entry.title "#{version.event.upcase} #{version.item_type} «#{change_title_for(version)}» #{user ? 'by ' + user.send(PaperTrailManager.whodunnit_name_method) : ''}"
|
23
|
+
entry.updated version.created_at.utc.xmlschema
|
24
|
+
|
25
|
+
xm = ::Builder::XmlMarkup.new
|
26
|
+
xm.div do
|
27
|
+
xm.p do
|
28
|
+
xm.span << 'Go to: '
|
29
|
+
xm.span << link_to('Change', change_url(version))
|
30
|
+
xm.span << ' | '
|
31
|
+
xm.span << link_to('Record', change_item_url(version))
|
32
|
+
end
|
33
|
+
xm.table do
|
34
|
+
changes.keys.sort.each do |key|
|
35
|
+
xm.tr do
|
36
|
+
xm.td { xm.b key }
|
37
|
+
xm.td changes[key][:previous].inspect
|
38
|
+
xm.td { xm.span << '→' }
|
39
|
+
xm.td changes[key][:current].inspect
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
entry.content(xm.to_s, type: 'html')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<h1>Changes</h1>
|
2
|
+
|
3
|
+
<p class='changes_feed'><%= link_to 'Changes feed', changes_path(:format => 'atom') %></p>
|
4
|
+
|
5
|
+
<p>
|
6
|
+
Show:
|
7
|
+
<%= ([link_to('All', changes_path)] + change_item_types.map { |type| link_to(type.pluralize, changes_path(:type => type)) }).join(' | ').html_safe %>
|
8
|
+
</p>
|
9
|
+
|
10
|
+
<table class='changes_table'>
|
11
|
+
<tfoot>
|
12
|
+
<tr>
|
13
|
+
<td colspan='2'>
|
14
|
+
<%= paginate @versions %>
|
15
|
+
</td>
|
16
|
+
</tr>
|
17
|
+
</tfoot>
|
18
|
+
<thead>
|
19
|
+
<tr class='changes_header'>
|
20
|
+
<th class='change_time'>Time</th>
|
21
|
+
<th class='change_details'>Attribute with previous and current values</th>
|
22
|
+
</tr>
|
23
|
+
</thead>
|
24
|
+
<tbody>
|
25
|
+
<% if @versions.any? %>
|
26
|
+
<% @versions.each do |version| %>
|
27
|
+
<% next unless change_show_allowed?(version) %>
|
28
|
+
<%= render :partial => 'version', :object => version %>
|
29
|
+
<% end %>
|
30
|
+
<% else %>
|
31
|
+
<td rowspan='2'> — No changes found — </td>
|
32
|
+
<% end %>
|
33
|
+
</tbody>
|
34
|
+
</table>
|
35
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h1>Change <%= @version.id %></h1>
|
2
|
+
|
3
|
+
<table class='changes_table'>
|
4
|
+
<tr class='changes_header'>
|
5
|
+
<th class='change_time'>Time</th>
|
6
|
+
<th class='change_details'>Attribute with previous and current values</th>
|
7
|
+
<%= render :partial => 'version', :object => @version %>
|
8
|
+
</tr>
|
9
|
+
</table>
|
10
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'demingfactor-paper_trail_manager'
|
8
|
+
spec.version = '0.7.3'
|
9
|
+
spec.authors = ['Igal Koshevoy', 'Reid Beels', 'Demingfactor']
|
10
|
+
spec.authors = ['dev@demingfactor.com']
|
11
|
+
spec.summary = 'A user interface for `paper_trail` versioning data in Rails applications.'
|
12
|
+
spec.description = 'Browse, subscribe, view and revert changes to records when using Rails and the `paper_trail` gem.'
|
13
|
+
spec.homepage = 'https://github.com/demingfactor/paper_trail_manager'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'paper_trail', ['>= 3.0']
|
22
|
+
spec.add_dependency 'rails', ['>= 3.0', '< 7.0']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'appraisal', '~> 2.5'
|
25
|
+
spec.add_development_dependency 'factory_girl_rails', '~> 4.0'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
27
|
+
spec.add_development_dependency 'rspec-activemodel-mocks', '~> 1.0'
|
28
|
+
spec.add_development_dependency 'rspec-html-matchers', '~> 0.9.2'
|
29
|
+
spec.add_development_dependency 'rspec-its', '~> 1.0'
|
30
|
+
spec.add_development_dependency 'rspec-rails', '~> 3.0'
|
31
|
+
spec.add_development_dependency 'sqlite3', ['>= 1.3.6', '<= 1.5.4']
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 6.0.0"
|
6
|
+
gem "jquery-rails"
|
7
|
+
gem "sqlite3", "~> 1.5.4"
|
8
|
+
gem "paper_trail", "~> 10.0"
|
9
|
+
gem "will_paginate", "~> 3.0"
|
10
|
+
gem "webpacker"
|
11
|
+
|
12
|
+
gemspec path: "../"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 6.1.0"
|
6
|
+
gem "jquery-rails"
|
7
|
+
gem "sqlite3", "~> 1.5.4"
|
8
|
+
gem "paper_trail", "~> 11.1"
|
9
|
+
gem "will_paginate", "~> 3.0"
|
10
|
+
gem "webpacker"
|
11
|
+
|
12
|
+
gemspec path: "../"
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails'
|
4
|
+
require 'paper_trail'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'will_paginate'
|
8
|
+
rescue LoadError
|
9
|
+
begin
|
10
|
+
require 'kaminari'
|
11
|
+
rescue LoadError
|
12
|
+
raise LoadError, 'will_paginate or kaminari must be in Gemfile or load_path'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class PaperTrailManager < Rails::Engine
|
17
|
+
initializer 'paper_trail_manager.pagination' do
|
18
|
+
::ActionView::Base.send(:alias_method, :paginate, :will_paginate) if defined?(WillPaginate)
|
19
|
+
end
|
20
|
+
|
21
|
+
@@whodunnit_name_method = :name
|
22
|
+
cattr_accessor :whodunnit_class, :whodunnit_name_method, :route_helpers,
|
23
|
+
:layout, :base_controller, :user_path_method, :item_name_method
|
24
|
+
|
25
|
+
self.base_controller = 'ApplicationController'
|
26
|
+
self.user_path_method = :user_path
|
27
|
+
|
28
|
+
(Pathname(__FILE__).dirname + '..').tap do |base|
|
29
|
+
paths['app/controller'] = base + 'app/controllers'
|
30
|
+
paths['app/view'] = base + 'app/views'
|
31
|
+
end
|
32
|
+
|
33
|
+
cattr_accessor :allow_index_block, :allow_show_block, :allow_revert_block
|
34
|
+
|
35
|
+
block = proc { true }
|
36
|
+
self.allow_index_block = block
|
37
|
+
self.allow_show_block = block
|
38
|
+
self.allow_revert_block = block
|
39
|
+
|
40
|
+
def self.allow_index_when(&block)
|
41
|
+
self.allow_index_block = block
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.allow_index?(controller)
|
45
|
+
allow_index_block.call controller
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.allow_show_when(&block)
|
49
|
+
self.allow_show_block = block
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.allow_show?(controller, version)
|
53
|
+
allow_index_block.call controller, version
|
54
|
+
end
|
55
|
+
|
56
|
+
# Describe when to allow reverts. Call this with a block that accepts
|
57
|
+
# arguments for +controller+ and +version+.
|
58
|
+
def self.allow_revert_when(&block)
|
59
|
+
self.allow_revert_block = block
|
60
|
+
end
|
61
|
+
|
62
|
+
# Allow revert given the +controller+ and +version+? If no
|
63
|
+
# ::allow_revert_when was specified, always return +true+.
|
64
|
+
def self.allow_revert?(controller, version)
|
65
|
+
allow_revert_block.call controller, version
|
66
|
+
end
|
67
|
+
end
|