paper_trail_history 0.2.0 → 0.2.1

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: 9d4cf46205ebd10b78ce9d159df2a384e2b00071a80efad39bf2e79bbcb84b05
4
- data.tar.gz: 7b1155089a6b7328d76d63d137fb527e0e68219da77da09f1358d824c6f2bfe5
3
+ metadata.gz: e8f45c5efd0324c99a10d738d2c8db6e6f06b809ded91d04ae2ea1b5a7d6a30a
4
+ data.tar.gz: 3e4280f2afc76462071723e6bf61e2bc28339e7159e69f2223a3b08cde8b36aa
5
5
  SHA512:
6
- metadata.gz: 92abd0ba47e73f3980186c8f52819b58b7cdf33becc042d49703233a070c3a43a312f45d2d69ecd9bc10e67bb974675c93749f05eb528dd1806f410763e36ff4
7
- data.tar.gz: f9a7cd1637b73274d866138706ad49ff1f1b1222575f4aca7dff2f8114584c9b30bcfb20f71ed731fb0af1234cb6bebef631f5eb2d23584a0bcd571dbee8cbec
6
+ metadata.gz: 1013e6d19a201f4d8c16c6ddcbf7592d7342b3f67a8b3f24f6819f0a7f5f8861b7bda50d1f91dd0830886f898bdd358e4b35e78dc39a070e2b29a608faa713e6
7
+ data.tar.gz: e4c97d3b9b7795d5d427352b21b42bdf67f8143e526486a4a7fcf5d4b649cbdb0b0fab64852a02465b3f0feee314aca4fd08da5a867464fefb428b71ba4a7a1c
@@ -14,9 +14,9 @@ module PaperTrailHistory
14
14
  result = VersionService.restore_version(@version.id)
15
15
 
16
16
  if result[:success]
17
- redirect_back_or_to(version_path(@version), notice: result[:message])
17
+ redirect_back_or_to(version_path(@version, model_name: @version.item_type), notice: result[:message])
18
18
  else
19
- redirect_back_or_to(version_path(@version),
19
+ redirect_back_or_to(version_path(@version, model_name: @version.item_type),
20
20
  alert: t('paper_trail_history.errors.restore_failed', error: result[:error]))
21
21
  end
22
22
  end
@@ -24,8 +24,10 @@ module PaperTrailHistory
24
24
  private
25
25
 
26
26
  def find_version
27
- @version = PaperTrail::Version.find(params[:id])
28
- rescue ActiveRecord::RecordNotFound
27
+ @version = VersionService.find_version(params[:id], params[:model_name])
28
+
29
+ return if @version
30
+
29
31
  redirect_to root_path, alert: t('paper_trail_history.errors.version_not_found')
30
32
  end
31
33
  end
@@ -3,5 +3,16 @@
3
3
  module PaperTrailHistory
4
4
  # Helper module providing utility methods for PaperTrailHistory views
5
5
  module ApplicationHelper
6
+ # Generate version path with model_name context when available
7
+ def version_link_path(version, options = {})
8
+ model_name = options[:model_name] || version.item_type
9
+ version_path(version.id, model_name: model_name)
10
+ end
11
+
12
+ # Generate restore version path with model_name context
13
+ def restore_version_link_path(version, options = {})
14
+ model_name = options[:model_name] || version.item_type
15
+ restore_version_path(version.id, model_name: model_name)
16
+ end
6
17
  end
7
18
  end
@@ -19,6 +19,19 @@ module PaperTrailHistory
19
19
  apply_record_filters(versions, params).order(created_at: :desc)
20
20
  end
21
21
 
22
+ def self.find_version(version_id, model_name = nil)
23
+ if model_name.present?
24
+ # Direct query when model_name is known (fast)
25
+ trackable_model = TrackableModel.find(model_name)
26
+ return nil unless trackable_model
27
+
28
+ trackable_model.version_class.unscoped.find_by(id: version_id)
29
+ else
30
+ # Fall back to searching across all tables (backwards compatible)
31
+ find_version_across_tables(version_id)
32
+ end
33
+ end
34
+
22
35
  def self.restore_version(version_id)
23
36
  version = find_version_across_tables(version_id)
24
37
  return validate_version_for_restore(version) unless version_restorable?(version)
@@ -16,8 +16,8 @@
16
16
  <% versions.each do |decorated_version| %>
17
17
  <tr>
18
18
  <td>
19
- <%= link_to "##{decorated_version.version.id}",
20
- version_path(decorated_version.version.id),
19
+ <%= link_to "##{decorated_version.version.id}",
20
+ version_link_path(decorated_version.version),
21
21
  class: "text-decoration-none" %>
22
22
  </td>
23
23
  <td>
@@ -41,13 +41,13 @@
41
41
  <% end %>
42
42
  <td>
43
43
  <div class="btn-group btn-group-sm">
44
- <%= link_to "View", version_path(decorated_version.version.id), class: "btn btn-outline-primary btn-sm" %>
44
+ <%= link_to "View", version_link_path(decorated_version.version), class: "btn btn-outline-primary btn-sm" %>
45
45
  <% if decorated_version.can_restore? %>
46
- <%= button_to "Restore",
47
- restore_version_path(decorated_version.version.id),
46
+ <%= button_to "Restore",
47
+ restore_version_link_path(decorated_version.version),
48
48
  method: :patch,
49
- data: {
50
- confirm: "Are you sure you want to restore this version?"
49
+ data: {
50
+ confirm: "Are you sure you want to restore this version?"
51
51
  },
52
52
  class: "btn btn-outline-warning btn-sm" %>
53
53
  <% end %>
@@ -10,11 +10,11 @@
10
10
  <h1>Version Details</h1>
11
11
  <div>
12
12
  <% if @decorated_version.can_restore? %>
13
- <%= button_to "Restore This Version",
14
- restore_version_path(@version),
13
+ <%= button_to "Restore This Version",
14
+ restore_version_link_path(@version),
15
15
  method: :patch,
16
- data: {
17
- confirm: "Are you sure you want to restore this version? This will overwrite the current data."
16
+ data: {
17
+ confirm: "Are you sure you want to restore this version? This will overwrite the current data."
18
18
  },
19
19
  class: "btn btn-warning" %>
20
20
  <% end %>
@@ -68,11 +68,11 @@
68
68
  This will restore the record to the state it was in at this version.
69
69
  <strong>This action cannot be undone</strong>, but will create a new version entry.
70
70
  </p>
71
- <%= button_to "Restore This Version",
72
- restore_version_path(@version),
71
+ <%= button_to "Restore This Version",
72
+ restore_version_link_path(@version),
73
73
  method: :patch,
74
- data: {
75
- confirm: "Are you sure you want to restore this version? This will overwrite the current data and cannot be undone."
74
+ data: {
75
+ confirm: "Are you sure you want to restore this version? This will overwrite the current data and cannot be undone."
76
76
  },
77
77
  class: "btn btn-warning" %>
78
78
  </div>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaperTrailHistory
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail_history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Deutscher
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-12-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: paper_trail
@@ -86,7 +85,6 @@ metadata:
86
85
  source_code_uri: https://github.com/its-bede/paper_trail_history
87
86
  changelog_uri: https://github.com/its-bede/paper_trail_history/blob/main/CHANGELOG.md
88
87
  rubygems_mfa_required: 'true'
89
- post_install_message:
90
88
  rdoc_options: []
91
89
  require_paths:
92
90
  - lib
@@ -101,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
99
  - !ruby/object:Gem::Version
102
100
  version: '0'
103
101
  requirements: []
104
- rubygems_version: 3.5.23
105
- signing_key:
102
+ rubygems_version: 3.6.9
106
103
  specification_version: 4
107
104
  summary: A Rails engine providing a web interface for managing PaperTrail versions.
108
105
  test_files: []