Move account sensitize-related methods to concern (#28865)
parent
d033920b7e
commit
c78dc23b49
|
@ -90,6 +90,7 @@ class Account < ApplicationRecord
|
||||||
include Account::Interactions
|
include Account::Interactions
|
||||||
include Account::Merging
|
include Account::Merging
|
||||||
include Account::Search
|
include Account::Search
|
||||||
|
include Account::Sensitizes
|
||||||
include Account::Silences
|
include Account::Silences
|
||||||
include Account::StatusesSearch
|
include Account::StatusesSearch
|
||||||
include Account::Suspensions
|
include Account::Suspensions
|
||||||
|
@ -130,7 +131,6 @@ class Account < ApplicationRecord
|
||||||
scope :remote, -> { where.not(domain: nil) }
|
scope :remote, -> { where.not(domain: nil) }
|
||||||
scope :local, -> { where(domain: nil) }
|
scope :local, -> { where(domain: nil) }
|
||||||
scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
|
scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
|
||||||
scope :sensitized, -> { where.not(sensitized_at: nil) }
|
|
||||||
scope :without_instance_actor, -> { where.not(id: INSTANCE_ACTOR_ID) }
|
scope :without_instance_actor, -> { where.not(id: INSTANCE_ACTOR_ID) }
|
||||||
scope :recent, -> { reorder(id: :desc) }
|
scope :recent, -> { reorder(id: :desc) }
|
||||||
scope :bots, -> { where(actor_type: AUTOMATED_ACTOR_TYPES) }
|
scope :bots, -> { where(actor_type: AUTOMATED_ACTOR_TYPES) }
|
||||||
|
@ -243,18 +243,6 @@ class Account < ApplicationRecord
|
||||||
ResolveAccountService.new.call(acct) unless local?
|
ResolveAccountService.new.call(acct) unless local?
|
||||||
end
|
end
|
||||||
|
|
||||||
def sensitized?
|
|
||||||
sensitized_at.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def sensitize!(date = Time.now.utc)
|
|
||||||
update!(sensitized_at: date)
|
|
||||||
end
|
|
||||||
|
|
||||||
def unsensitize!
|
|
||||||
update!(sensitized_at: nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
def memorialize!
|
def memorialize!
|
||||||
update!(memorial: true)
|
update!(memorial: true)
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Account::Sensitizes
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
scope :sensitized, -> { where.not(sensitized_at: nil) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def sensitized?
|
||||||
|
sensitized_at.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def sensitize!(date = Time.now.utc)
|
||||||
|
update!(sensitized_at: date)
|
||||||
|
end
|
||||||
|
|
||||||
|
def unsensitize!
|
||||||
|
update!(sensitized_at: nil)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,18 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Account::Sensitizes do
|
||||||
|
describe 'Scopes' do
|
||||||
|
describe '.sensitized' do
|
||||||
|
let(:sensitized_account) { Fabricate :account, sensitized_at: 2.days.ago }
|
||||||
|
|
||||||
|
before { Fabricate :account, sensitized_at: false }
|
||||||
|
|
||||||
|
it 'returns an array of accounts who are sensitized' do
|
||||||
|
expect(Account.sensitized)
|
||||||
|
.to contain_exactly(sensitized_account)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue