fix avo whodunnit and display user link

This commit is contained in:
24c02 2025-02-19 09:08:07 -05:00
parent b109e2a0b5
commit 0fddb6cde1
4 changed files with 26 additions and 0 deletions

View file

@ -89,3 +89,5 @@ group :test do
gem "capybara"
gem "selenium-webdriver"
end
gem "avo-record_link_field", "~> 0.0.2"

View file

@ -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

View file

@ -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

View file

@ -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