Add action_logs association to account

This commit is contained in:
Matt Jankowski 2025-09-04 09:22:42 -04:00
parent e7c30cd072
commit 9b359d8daf
4 changed files with 9 additions and 6 deletions

View File

@ -4,10 +4,8 @@ module AccountableConcern
extend ActiveSupport::Concern
def log_action(action, target)
Admin::ActionLog.create(
account: current_account,
action: action,
target: target
)
current_account
.action_logs
.create(action:, target:)
end
end

View File

@ -143,7 +143,7 @@ class Account < ApplicationRecord
scope :matches_username, ->(value) { where('lower((username)::text) LIKE lower(?)', "#{value}%") }
scope :matches_display_name, ->(value) { where(arel_table[:display_name].matches("#{value}%")) }
scope :without_unapproved, -> { left_outer_joins(:user).merge(User.approved.confirmed).or(remote) }
scope :auditable, -> { where(id: Admin::ActionLog.select(:account_id).distinct) }
scope :auditable, -> { where.associated(:action_logs).distinct }
scope :searchable, -> { without_unapproved.without_suspended.where(moved_to_account_id: nil) }
scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).joins(:account_stat) }
scope :by_recent_status, -> { includes(:account_stat).merge(AccountStat.by_recent_status).references(:account_stat) }

View File

@ -11,6 +11,7 @@ module Account::Associations
has_many :account_moderation_notes
has_many :account_pins
has_many :account_warnings
has_many :action_logs, class_name: 'Admin::ActionLog'
has_many :aliases, class_name: 'AccountAlias'
has_many :bookmarks
has_many :conversations, class_name: 'AccountConversation'

View File

@ -6,6 +6,10 @@ RSpec.describe Account do
it_behaves_like 'Account::Search'
it_behaves_like 'Reviewable'
describe 'Associations' do
it { is_expected.to have_many(:action_logs).class_name('Admin::ActionLog') }
end
context 'with an account record' do
subject { Fabricate(:account) }