logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

action_log.rb (1132B)


  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: admin_action_logs
  5. #
  6. # id :integer not null, primary key
  7. # account_id :integer
  8. # action :string default(""), not null
  9. # target_type :string
  10. # target_id :integer
  11. # recorded_changes :text default(""), not null
  12. # created_at :datetime not null
  13. # updated_at :datetime not null
  14. #
  15. class Admin::ActionLog < ApplicationRecord
  16. serialize :recorded_changes
  17. belongs_to :account
  18. belongs_to :target, polymorphic: true
  19. default_scope -> { order('id desc') }
  20. def action
  21. super.to_sym
  22. end
  23. before_validation :set_changes
  24. private
  25. def set_changes
  26. case action
  27. when :destroy, :create
  28. self.recorded_changes = target.attributes
  29. when :update, :promote, :demote
  30. self.recorded_changes = target.previous_changes
  31. when :change_email
  32. self.recorded_changes = ActiveSupport::HashWithIndifferentAccess.new(
  33. email: [target.email, nil],
  34. unconfirmed_email: [nil, target.unconfirmed_email]
  35. )
  36. end
  37. end
  38. end