trusty-cms 7.0.6 → 7.0.7

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: 1200948dac13c1012f25a55e977598239c22b70b3391008962b378c235fa6cb7
4
- data.tar.gz: 6bdd05cafa5ff067e6a409bece0b952eed391e767260a0e069fbda25f46f68af
3
+ metadata.gz: 21602eb92fa965a61823801ab54c65663f5c91e13a5c379b0e6653868934285e
4
+ data.tar.gz: d479f8e082e2efc68e9feb96b461e3ebd66cf681ec6bb2a0c5e6f7cead81fb59
5
5
  SHA512:
6
- metadata.gz: 92bba35d94a6c81c165d6e3aac5d54f3de2f5b51025a0c09d6187ab32aa14703c0bb8e6b9fe5a1f7d1a419fa540ce6d6db4bd06e6c3ef64be09c622b52f34184
7
- data.tar.gz: 8b574e8d01b855debfb6b91859f589d79d111bcb9fe3b80eceb77d26a2ac65852cd3ab3693f727aa8a793a1f9a56ac05bb541af40f2cdae769583c07c1ba73e9
6
+ metadata.gz: 0a73dba1d21d9ad6998e71cb82aa8e704a63a173e66512d9aa029f26ce835e610356b58f321c5daad20e1cde525c1724fd222b3c571c2ea8ea062927f1f7f8a9
7
+ data.tar.gz: d12a09d633c3b63817c9fa725bd4b30d74d590cf69859d2d580348ba8bebf26ccc6c72bbda4aeae4d7f599a1cc69a2cb2c453d4ce85b68ce19af78f2e8255d31
data/Gemfile CHANGED
@@ -7,6 +7,9 @@ source 'https://rubygems.org'
7
7
  # requires trusty and therefore pulls in every
8
8
  # dependency mentioned in trusty.gemspec.
9
9
 
10
+ gem 'paper_trail'
11
+ gem 'paper_trail-association_tracking'
12
+ gem 'psych', '5.2.2'
10
13
  gem 'trustygems', '~> 0.2.0'
11
14
 
12
15
  gemspec
@@ -21,7 +24,6 @@ group :development, :test do
21
24
  gem 'mysql2'
22
25
  gem 'poltergeist', '~> 1.18.1'
23
26
  gem 'pry-byebug'
24
- gem 'psych', '5.2.2'
25
27
  gem 'rails-observers'
26
28
  gem 'ransack'
27
29
  gem 'rspec-rails'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trusty-cms (7.0.6)
4
+ trusty-cms (7.0.7)
5
5
  RedCloth (= 4.3.3)
6
6
  activestorage-validator
7
7
  acts_as_list (>= 0.9.5, < 1.3.0)
@@ -165,7 +165,16 @@ GEM
165
165
  factory_bot_rails (6.4.4)
166
166
  factory_bot (~> 6.5)
167
167
  railties (>= 5.0.0)
168
- ffi (1.17.0)
168
+ ffi (1.17.0-aarch64-linux-gnu)
169
+ ffi (1.17.0-aarch64-linux-musl)
170
+ ffi (1.17.0-arm-linux-gnu)
171
+ ffi (1.17.0-arm-linux-musl)
172
+ ffi (1.17.0-arm64-darwin)
173
+ ffi (1.17.0-x86-linux-gnu)
174
+ ffi (1.17.0-x86-linux-musl)
175
+ ffi (1.17.0-x86_64-darwin)
176
+ ffi (1.17.0-x86_64-linux-gnu)
177
+ ffi (1.17.0-x86_64-linux-musl)
169
178
  file_validators (3.0.0)
170
179
  activemodel (>= 3.2)
171
180
  mime-types (>= 1.0)
@@ -256,6 +265,11 @@ GEM
256
265
  nokogiri (1.17.2-x86_64-linux)
257
266
  racc (~> 1.4)
258
267
  orm_adapter (0.5.0)
268
+ paper_trail (16.0.0)
269
+ activerecord (>= 6.1)
270
+ request_store (~> 1.4)
271
+ paper_trail-association_tracking (2.2.1)
272
+ paper_trail (>= 12.0)
259
273
  poltergeist (1.18.1)
260
274
  capybara (>= 2.1, < 4)
261
275
  cliver (~> 0.3.1)
@@ -317,6 +331,8 @@ GEM
317
331
  regexp_parser (2.9.2)
318
332
  reline (0.5.11)
319
333
  io-console (~> 0.5)
334
+ request_store (1.7.0)
335
+ rack (>= 1.4)
320
336
  responders (3.1.1)
321
337
  actionpack (>= 5.2)
322
338
  railties (>= 5.2)
@@ -413,6 +429,8 @@ DEPENDENCIES
413
429
  file_validators
414
430
  launchy (~> 3.0.1)
415
431
  mysql2
432
+ paper_trail
433
+ paper_trail-association_tracking
416
434
  poltergeist (~> 1.18.1)
417
435
  pry-byebug
418
436
  psych (= 5.2.2)
@@ -1,6 +1,7 @@
1
1
  class Admin::PagesController < Admin::ResourceController
2
2
  before_action :initialize_meta_rows_and_buttons, only: %i[new edit create update]
3
3
  before_action :count_deleted_pages, only: [:destroy]
4
+ before_action :set_page, only: %i[edit restore]
4
5
  rescue_from ActiveRecord::RecordInvalid, with: :validation_error
5
6
 
6
7
  class PreviewStop < ActiveRecord::Rollback
@@ -38,9 +39,16 @@ class Admin::PagesController < Admin::ResourceController
38
39
  assets = Asset.order('created_at DESC')
39
40
  @term = assets.ransack(params[:search] || '')
40
41
  @term.result(distinct: true)
42
+ @versions = format_versions(@page.versions)
41
43
  response_for :edit
42
44
  end
43
45
 
46
+ def restore
47
+ index = params[:version_index].to_i
48
+ restore_page_version(@page, index)
49
+ redirect_to edit_admin_page_path(@page)
50
+ end
51
+
44
52
  def preview
45
53
  render_preview
46
54
  rescue PreviewStop => e
@@ -55,6 +63,10 @@ class Admin::PagesController < Admin::ResourceController
55
63
 
56
64
  private
57
65
 
66
+ def set_page
67
+ @page = Page.find(params[:id])
68
+ end
69
+
58
70
  def validation_error(e)
59
71
  flash[:error] = e.message
60
72
  render :new
@@ -67,6 +79,28 @@ class Admin::PagesController < Admin::ResourceController
67
79
  model.parent_id = params[:page_id]
68
80
  end
69
81
 
82
+ def format_versions(versions)
83
+ return nil unless versions.any?
84
+
85
+ versions
86
+ .sort_by(&:created_at).reverse
87
+ .map do |version|
88
+ {
89
+ index: version&.index,
90
+ update_date: version&.created_at&.strftime('%B %d, %Y'),
91
+ update_time: version&.created_at&.strftime('%I:%M %p'),
92
+ updated_by: User.unscoped.find_by(id: version&.whodunnit)&.name || 'Unknown User',
93
+ }
94
+ end
95
+ end
96
+
97
+ def restore_page_version(page, index)
98
+ lock_version = page.lock_version
99
+ restored_page = page.versions[index].reify(has_many: true)
100
+ restored_page.lock_version = lock_version
101
+ restored_page.save!
102
+ end
103
+
70
104
  def model_class
71
105
  if Page.descendants.any? { |d| d.to_s == params[:page_class] }
72
106
  verify_page_class(params[:page_class])
@@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base
12
12
  before_action :force_utf8_params if RUBY_VERSION =~ /1\.9/
13
13
  before_action :set_standard_body_style, only: %i[new edit update create]
14
14
  before_action :set_mailer
15
+ before_action :set_paper_trail_whodunnit
15
16
 
16
17
  attr_accessor :trusty_config, :cache
17
18
  attr_reader :pagination_parameters
data/app/models/page.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'trusty_cms/taggable'
2
2
 
3
3
  class Page < ActiveRecord::Base
4
+ has_paper_trail
5
+
4
6
  class MissingRootPageError < StandardError
5
7
  def initialize(message = 'Database missing root page')
6
8
  ; super
@@ -12,9 +14,9 @@ class Page < ActiveRecord::Base
12
14
 
13
15
  # Associations
14
16
  acts_as_tree order: 'position ASC'
15
- has_many :parts, -> { order(:id) }, class_name: 'PagePart', dependent: :destroy
17
+ has_many :parts, -> { order(:id) }, class_name: 'PagePart', foreign_key: :page_id, autosave: true, dependent: :destroy
16
18
  accepts_nested_attributes_for :parts, allow_destroy: true
17
- has_many :fields, -> { order(:id) }, class_name: 'PageField', dependent: :destroy
19
+ has_many :fields, -> { order(:id) }, class_name: 'PageField', foreign_key: :page_id, autosave: true, dependent: :destroy
18
20
  accepts_nested_attributes_for :fields, allow_destroy: true
19
21
  belongs_to :layout
20
22
  belongs_to :created_by, class_name: 'User'
@@ -1,3 +1,4 @@
1
1
  class PageField < ActiveRecord::Base
2
+ has_paper_trail
2
3
  validates_presence_of :name
3
4
  end
@@ -1,4 +1,6 @@
1
1
  class PagePart < ActiveRecord::Base
2
+ has_paper_trail
3
+
2
4
  # Default Order
3
5
  default_scope { order('name') }
4
6
 
@@ -0,0 +1,2 @@
1
+ PaperTrail.config.track_associations = true
2
+ PaperTrail.config.version_limit = 5
data/config/routes.rb CHANGED
@@ -13,6 +13,7 @@ TrustyCms::Application.routes.draw do
13
13
  resources :pages do
14
14
  resources :children, controller: 'pages'
15
15
  get 'remove', on: :member
16
+ put 'restore/:version_index', on: :member, to: 'pages#restore', as: :restore_version
16
17
  end
17
18
  resources :layouts do
18
19
  get 'remove', on: :member
@@ -0,0 +1,41 @@
1
+ # This migration creates the `versions` table, the only schema PT requires.
2
+ # All other migrations PT provides are optional.
3
+ class CreateVersions < ActiveRecord::Migration[7.0]
4
+
5
+ # The largest text column available in all supported RDBMS is
6
+ # 1024^3 - 1 bytes, roughly one gibibyte. We specify a size
7
+ # so that MySQL will use `longtext` instead of `text`. Otherwise,
8
+ # when serializing very large objects, `text` might not be big enough.
9
+ TEXT_BYTES = 1_073_741_823
10
+
11
+ def change
12
+ create_table :versions, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci" do |t|
13
+ # Consider using bigint type for performance if you are going to store only numeric ids.
14
+ # t.bigint :whodunnit
15
+ t.string :whodunnit
16
+
17
+ # Known issue in MySQL: fractional second precision
18
+ # -------------------------------------------------
19
+ #
20
+ # MySQL timestamp columns do not support fractional seconds unless
21
+ # defined with "fractional seconds precision". MySQL users should manually
22
+ # add fractional seconds precision to this migration, specifically, to
23
+ # the `created_at` column.
24
+ # (https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html)
25
+ #
26
+ # MySQL users should also upgrade to at least rails 4.2, which is the first
27
+ # version of ActiveRecord with support for fractional seconds in MySQL.
28
+ # (https://github.com/rails/rails/pull/14359)
29
+ #
30
+ # MySQL users should use the following line for `created_at`
31
+ # t.datetime :created_at, limit: 6
32
+ t.datetime :created_at
33
+
34
+ t.bigint :item_id, null: false
35
+ t.string :item_type, null: false, limit: 191
36
+ t.string :event, null: false
37
+ t.text :object, limit: TEXT_BYTES
38
+ end
39
+ add_index :versions, %i[item_type item_id]
40
+ end
41
+ end
@@ -0,0 +1,23 @@
1
+ # This migration and AddTransactionIdColumnToVersions provide the necessary
2
+ # schema for tracking associations.
3
+ class CreateVersionAssociations < ActiveRecord::Migration[7.0]
4
+ def self.up
5
+ create_table :version_associations do |t|
6
+ t.integer :version_id
7
+ t.string :foreign_key_name, null: false
8
+ t.integer :foreign_key_id
9
+ t.string :foreign_type
10
+ end
11
+ add_index :version_associations, [:version_id]
12
+ add_index :version_associations,
13
+ %i(foreign_key_name foreign_key_id foreign_type),
14
+ name: "index_version_associations_on_foreign_key"
15
+ end
16
+
17
+ def self.down
18
+ remove_index :version_associations, [:version_id]
19
+ remove_index :version_associations,
20
+ name: "index_version_associations_on_foreign_key"
21
+ drop_table :version_associations
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ # This migration and CreateVersionAssociations provide the necessary
2
+ # schema for tracking associations.
3
+ class AddTransactionIdColumnToVersions < ActiveRecord::Migration[7.0]
4
+ def self.up
5
+ add_column :versions, :transaction_id, :integer
6
+ add_index :versions, [:transaction_id]
7
+ end
8
+
9
+ def self.down
10
+ remove_index :versions, [:transaction_id]
11
+ remove_column :versions, :transaction_id
12
+ end
13
+ end
@@ -1,4 +1,4 @@
1
1
  module TrustyCms
2
- VERSION = '7.0.6'.freeze
2
+ VERSION = '7.0.7'.freeze
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trusty-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.6
4
+ version: 7.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - TrustyCms CMS dev team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-07 00:00:00.000000000 Z
11
+ date: 2025-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activestorage-validator
@@ -854,6 +854,7 @@ files:
854
854
  - config/initializers/assets.rb
855
855
  - config/initializers/devise.rb
856
856
  - config/initializers/kraken.rb
857
+ - config/initializers/paper_trail.rb
857
858
  - config/initializers/ransack.rb
858
859
  - config/initializers/response_cache_timeout.rb
859
860
  - config/initializers/secret_token.rb
@@ -912,6 +913,9 @@ files:
912
913
  - db/migrate/20200117141251_create_admin_users.rb
913
914
  - db/migrate/20210331134718_create_active_storage_tables.active_storage.rb
914
915
  - db/migrate/20241108172942_create_site_users.rb
916
+ - db/migrate/20250102212417_create_versions.rb
917
+ - db/migrate/20250103191133_create_version_associations.rb
918
+ - db/migrate/20250103191134_add_transaction_id_column_to_versions.rb
915
919
  - db/schema.rb
916
920
  - lib/active_record_extensions/active_record_extensions.rb
917
921
  - lib/annotatable.rb