From 44cb03d4f9d77f919e8a3a1b813fccc6903893e2 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 25 Jan 2024 12:13:55 -0500 Subject: [PATCH] Add Account migration scopes --- app/models/account.rb | 4 +++- app/models/relationship_filter.rb | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/account.rb b/app/models/account.rb index 2bf00b2be59..1395ff96704 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -119,8 +119,10 @@ class Account < ApplicationRecord scope :silenced, -> { where.not(silenced_at: nil) } scope :suspended, -> { where.not(suspended_at: nil) } scope :sensitized, -> { where.not(sensitized_at: nil) } + scope :migrated, -> { where.not(moved_to_account_id: nil) } scope :without_suspended, -> { where(suspended_at: nil) } scope :without_silenced, -> { where(silenced_at: nil) } + scope :without_migrated, -> { where(moved_to_account_id: nil) } scope :without_instance_actor, -> { where.not(id: INSTANCE_ACTOR_ID) } scope :recent, -> { reorder(id: :desc) } scope :bots, -> { where(actor_type: %w(Application Service)) } @@ -131,7 +133,7 @@ class Account < ApplicationRecord 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 :searchable, -> { without_unapproved.without_suspended.where(moved_to_account_id: nil) } + scope :searchable, -> { without_unapproved.without_suspended.without_migrated } 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) } scope :by_recent_activity, -> { left_joins(:user, :account_stat).order(coalesced_activity_timestamps.desc).order(id: :desc) } diff --git a/app/models/relationship_filter.rb b/app/models/relationship_filter.rb index 828610e46a4..bcbafa8af15 100644 --- a/app/models/relationship_filter.rb +++ b/app/models/relationship_filter.rb @@ -92,9 +92,9 @@ class RelationshipFilter def status_scope(value) case value when 'moved' - Account.where.not(moved_to_account_id: nil) + Account.migrated when 'primary' - Account.where(moved_to_account_id: nil) + Account.without_migrated else raise Mastodon::InvalidParameterError, "Unknown status: #{value}" end