diff --git a/Gemfile b/Gemfile index 351b948..59b3c2f 100644 --- a/Gemfile +++ b/Gemfile @@ -89,3 +89,5 @@ group :test do gem "capybara" gem "selenium-webdriver" end + +gem "avo-record_link_field", "~> 0.0.2" diff --git a/Gemfile.lock b/Gemfile.lock index 5b099c1..ed86b56 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,6 +95,7 @@ GEM view_component (>= 3.7.0) zeitwerk (>= 2.6.12) avo-heroicons (0.1.1) + avo-record_link_field (0.0.2) base64 (0.2.0) bcrypt_pbkdf (1.1.1) benchmark (0.4.0) @@ -444,6 +445,7 @@ PLATFORMS DEPENDENCIES avo (>= 3.2.1) + avo-record_link_field (~> 0.0.2) bootsnap brakeman capybara diff --git a/app/avo/resources/version.rb b/app/avo/resources/version.rb index 4cf384b..ee61856 100644 --- a/app/avo/resources/version.rb +++ b/app/avo/resources/version.rb @@ -13,6 +13,7 @@ class Avo::Resources::Version < Avo::BaseResource field :item_id, as: :number field :event, as: :text field :whodunnit, as: :text + field :user, as: :record_link field :object, as: :code field :created_at, as: :date_time end diff --git a/config/initializers/monkey_patches.rb b/config/initializers/monkey_patches.rb new file mode 100644 index 0000000..300803a --- /dev/null +++ b/config/initializers/monkey_patches.rb @@ -0,0 +1,21 @@ +# 🔧🐒 + +Rails.configuration.to_prepare do + Avo::BaseApplicationController.class_eval do + before_action :set_paper_trail_whodunnit + def user_for_paper_trail + Avo::Current.user&.id + end + end + + PaperTrail::Version.class_eval do + def user + begin + User.find(whodunnit) if whodunnit + rescue ActiveRecord::RecordNotFound + nil + end + end + end +end +