mirror of
https://github.com/mastodon/mastodon.git
synced 2026-04-20 05:59:41 -05:00
Merge 3cc6400707 into 28284b8452
This commit is contained in:
commit
5f449d432f
|
|
@ -26,6 +26,7 @@ class Report < ApplicationRecord
|
|||
|
||||
include Paginable
|
||||
include RateLimitable
|
||||
include Report::Resolution
|
||||
|
||||
COMMENT_SIZE_LIMIT = 1_000
|
||||
|
||||
|
|
@ -45,8 +46,6 @@ class Report < ApplicationRecord
|
|||
has_many :notes, class_name: 'ReportNote', inverse_of: :report, dependent: :destroy
|
||||
has_many :notifications, as: :activity, dependent: :destroy
|
||||
|
||||
scope :unresolved, -> { where(action_taken_at: nil) }
|
||||
scope :resolved, -> { where.not(action_taken_at: nil) }
|
||||
scope :with_accounts, -> { includes([:account, :target_account, :action_taken_by_account, :assigned_account].index_with([:account_stat, { user: [:invite_request, :invite, :ips] }])) }
|
||||
|
||||
# A report is considered local if the reporter is local
|
||||
|
|
@ -109,28 +108,6 @@ class Report < ApplicationRecord
|
|||
update!(assigned_account_id: nil)
|
||||
end
|
||||
|
||||
def resolve!(acting_account)
|
||||
update!(action_taken_at: Time.now.utc, action_taken_by_account_id: acting_account.id)
|
||||
end
|
||||
|
||||
def unresolve!
|
||||
update!(action_taken_at: nil, action_taken_by_account_id: nil)
|
||||
end
|
||||
|
||||
def action_taken?
|
||||
action_taken_at.present?
|
||||
end
|
||||
|
||||
alias action_taken action_taken?
|
||||
|
||||
def unresolved?
|
||||
!action_taken?
|
||||
end
|
||||
|
||||
def unresolved_siblings?
|
||||
Report.where.not(id: id).where(target_account_id: target_account_id).unresolved.exists?
|
||||
end
|
||||
|
||||
def to_log_human_identifier
|
||||
id
|
||||
end
|
||||
|
|
|
|||
31
app/models/report/resolution.rb
Normal file
31
app/models/report/resolution.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Report::Resolution
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
scope :resolved, -> { where.not(action_taken_at: nil) }
|
||||
scope :unresolved, -> { where(action_taken_at: nil) }
|
||||
end
|
||||
|
||||
def action_taken?
|
||||
action_taken_at?
|
||||
end
|
||||
alias action_taken action_taken?
|
||||
|
||||
def resolve!(acting_account)
|
||||
update!(action_taken_at: Time.now.utc, action_taken_by_account: acting_account)
|
||||
end
|
||||
|
||||
def unresolve!
|
||||
update!(action_taken_at: nil, action_taken_by_account_id: nil)
|
||||
end
|
||||
|
||||
def unresolved?
|
||||
!action_taken?
|
||||
end
|
||||
|
||||
def unresolved_siblings?
|
||||
Report.excluding(self).where(target_account_id:).unresolved.exists?
|
||||
end
|
||||
end
|
||||
100
spec/models/report/resolution_spec.rb
Normal file
100
spec/models/report/resolution_spec.rb
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Report::Resolution do
|
||||
describe 'Scopes' do
|
||||
let!(:resolved) { Fabricate :report, action_taken_at: 5.days.ago }
|
||||
let!(:unresolved) { Fabricate :report, action_taken_at: nil }
|
||||
|
||||
describe '.resolved' do
|
||||
it 'returns reports which have had action taken' do
|
||||
expect(Report.resolved)
|
||||
.to contain_exactly(resolved)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.unresolved' do
|
||||
it 'returns reports which have not had action taken' do
|
||||
expect(Report.unresolved)
|
||||
.to contain_exactly(unresolved)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#resolve!' do
|
||||
let(:acting_account) { Fabricate(:account) }
|
||||
let(:report) { Fabricate(:report, action_taken_at: nil, action_taken_by_account_id: nil) }
|
||||
|
||||
it 'resolves report and records action taken' do
|
||||
expect { report.resolve!(acting_account) }
|
||||
.to change(report, :action_taken?).to(true)
|
||||
.and change(report, :action_taken_by_account).to(acting_account)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#unresolve!' do
|
||||
let(:acting_account) { Fabricate(:account) }
|
||||
let(:report) { Fabricate(:report, action_taken_at: Time.now.utc, action_taken_by_account_id: acting_account.id) }
|
||||
|
||||
it 'unresolves report and removed action taken account' do
|
||||
expect { report.unresolve! }
|
||||
.to change(report, :action_taken?).to(false)
|
||||
.and change(report, :action_taken_by_account).to(be_nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#unresolved?' do
|
||||
subject { Fabricate(:report, action_taken_at: action_taken) }
|
||||
|
||||
context 'when action has been taken' do
|
||||
let(:action_taken) { Time.now.utc }
|
||||
|
||||
it { is_expected.to_not be_unresolved }
|
||||
end
|
||||
|
||||
context 'when action has not been taken' do
|
||||
let(:action_taken) { nil }
|
||||
|
||||
it { is_expected.to be_unresolved }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#action_taken?' do
|
||||
subject { Fabricate(:report, action_taken_at: action_taken) }
|
||||
|
||||
context 'when action has been taken' do
|
||||
let(:action_taken) { Time.now.utc }
|
||||
|
||||
it { is_expected.to be_action_taken }
|
||||
end
|
||||
|
||||
context 'when action has not been taken' do
|
||||
let(:action_taken) { nil }
|
||||
|
||||
it { is_expected.to_not be_action_taken }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#unresolved_siblings?' do
|
||||
subject { Fabricate :report }
|
||||
|
||||
context 'when the target account has other unresolved reports' do
|
||||
before { Fabricate :report, action_taken_at: nil, target_account: subject.target_account }
|
||||
|
||||
it { is_expected.to be_unresolved_siblings }
|
||||
end
|
||||
|
||||
context 'when the target account has a resolved report' do
|
||||
before { Fabricate :report, action_taken_at: 3.days.ago, target_account: subject.target_account }
|
||||
|
||||
it { is_expected.to_not be_unresolved_siblings }
|
||||
end
|
||||
|
||||
context 'when the target account has no other reports' do
|
||||
before { Report.where(target_account: subject.target_account).destroy_all }
|
||||
|
||||
it { is_expected.to_not be_unresolved_siblings }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -54,54 +54,6 @@ RSpec.describe Report do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'resolve!' do
|
||||
subject(:report) { Fabricate(:report, action_taken_at: nil, action_taken_by_account_id: nil) }
|
||||
|
||||
let(:acting_account) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
report.resolve!(acting_account)
|
||||
end
|
||||
|
||||
it 'records action taken' do
|
||||
expect(report.action_taken?).to be true
|
||||
expect(report.action_taken_by_account_id).to eq acting_account.id
|
||||
end
|
||||
end
|
||||
|
||||
describe 'unresolve!' do
|
||||
subject(:report) { Fabricate(:report, action_taken_at: Time.now.utc, action_taken_by_account_id: acting_account.id) }
|
||||
|
||||
let(:acting_account) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
report.unresolve!
|
||||
end
|
||||
|
||||
it 'unresolves' do
|
||||
expect(report.action_taken?).to be false
|
||||
expect(report.action_taken_by_account_id).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'unresolved?' do
|
||||
subject { report.unresolved? }
|
||||
|
||||
let(:report) { Fabricate(:report, action_taken_at: action_taken) }
|
||||
|
||||
context 'when action is taken' do
|
||||
let(:action_taken) { Time.now.utc }
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
|
||||
context 'when action not is taken' do
|
||||
let(:action_taken) { nil }
|
||||
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'history' do
|
||||
subject(:action_logs) { report.history }
|
||||
|
||||
|
|
@ -134,28 +86,6 @@ RSpec.describe Report do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#unresolved_siblings?' do
|
||||
subject { Fabricate :report }
|
||||
|
||||
context 'when the target account has other unresolved reports' do
|
||||
before { Fabricate :report, action_taken_at: nil, target_account: subject.target_account }
|
||||
|
||||
it { is_expected.to be_unresolved_siblings }
|
||||
end
|
||||
|
||||
context 'when the target account has a resolved report' do
|
||||
before { Fabricate :report, action_taken_at: 3.days.ago, target_account: subject.target_account }
|
||||
|
||||
it { is_expected.to_not be_unresolved_siblings }
|
||||
end
|
||||
|
||||
context 'when the target account has no other reports' do
|
||||
before { described_class.where(target_account: subject.target_account).destroy_all }
|
||||
|
||||
it { is_expected.to_not be_unresolved_siblings }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Delegations' do
|
||||
it { is_expected.to delegate_method(:local?).to(:account) }
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user