diff --git a/app/controllers/concerns/accountable_concern.rb b/app/controllers/concerns/accountable_concern.rb index c1349915f84..9c16d573c57 100644 --- a/app/controllers/concerns/accountable_concern.rb +++ b/app/controllers/concerns/accountable_concern.rb @@ -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 diff --git a/app/models/account.rb b/app/models/account.rb index 5fa1f0cebf6..fcf44aab77b 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -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) } diff --git a/app/models/concerns/account/associations.rb b/app/models/concerns/account/associations.rb index 62c55da5de1..8a5fd774378 100644 --- a/app/models/concerns/account/associations.rb +++ b/app/models/concerns/account/associations.rb @@ -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' diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index be400fecd4a..9c7864d36ab 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -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) }