2017-02-14 14:59:26 -05:00
|
|
|
# frozen_string_literal: true
|
2017-05-01 20:14:47 -04:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: reports
|
|
|
|
#
|
2018-04-23 05:29:17 -04:00
|
|
|
# id :bigint(8) not null, primary key
|
|
|
|
# status_ids :bigint(8) default([]), not null, is an Array
|
2017-05-01 20:14:47 -04:00
|
|
|
# comment :text default(""), not null
|
|
|
|
# action_taken :boolean default(FALSE), not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2018-04-23 05:29:17 -04:00
|
|
|
# account_id :bigint(8) not null
|
|
|
|
# action_taken_by_account_id :bigint(8)
|
|
|
|
# target_account_id :bigint(8) not null
|
|
|
|
# assigned_account_id :bigint(8)
|
2019-03-17 10:34:56 -04:00
|
|
|
# uri :string
|
2017-05-01 20:14:47 -04:00
|
|
|
#
|
2017-02-14 14:59:26 -05:00
|
|
|
|
|
|
|
class Report < ApplicationRecord
|
2019-06-19 20:52:34 -04:00
|
|
|
include Paginable
|
|
|
|
|
2017-02-14 14:59:26 -05:00
|
|
|
belongs_to :account
|
|
|
|
belongs_to :target_account, class_name: 'Account'
|
2018-01-19 14:56:47 -05:00
|
|
|
belongs_to :action_taken_by_account, class_name: 'Account', optional: true
|
2018-04-02 16:04:14 -04:00
|
|
|
belongs_to :assigned_account, class_name: 'Account', optional: true
|
|
|
|
|
|
|
|
has_many :notes, class_name: 'ReportNote', foreign_key: :report_id, inverse_of: :report, dependent: :destroy
|
2017-02-14 14:59:26 -05:00
|
|
|
|
|
|
|
scope :unresolved, -> { where(action_taken: false) }
|
|
|
|
scope :resolved, -> { where(action_taken: true) }
|
2019-06-19 20:52:34 -04:00
|
|
|
scope :with_accounts, -> { includes([:account, :target_account, :action_taken_by_account, :assigned_account].each_with_object({}) { |k, h| h[k] = { user: [:invite_request, :invite] } }) }
|
2017-04-14 05:10:28 -04:00
|
|
|
|
2017-09-07 03:55:42 -04:00
|
|
|
validates :comment, length: { maximum: 1000 }
|
|
|
|
|
2019-03-17 10:34:56 -04:00
|
|
|
def local?
|
|
|
|
false # Force uri_for to use uri attribute
|
|
|
|
end
|
|
|
|
|
|
|
|
before_validation :set_uri, only: :create
|
|
|
|
|
2018-02-28 00:54:55 -05:00
|
|
|
def object_type
|
|
|
|
:flag
|
|
|
|
end
|
|
|
|
|
2017-04-14 05:10:28 -04:00
|
|
|
def statuses
|
2019-08-22 15:55:56 -04:00
|
|
|
Status.with_discarded.where(id: status_ids).includes(:account, :media_attachments, :mentions)
|
2017-04-14 05:10:28 -04:00
|
|
|
end
|
2017-04-23 18:44:37 -04:00
|
|
|
|
|
|
|
def media_attachments
|
2017-04-30 12:15:49 -04:00
|
|
|
MediaAttachment.where(status_id: status_ids)
|
2017-04-23 18:44:37 -04:00
|
|
|
end
|
2018-04-10 14:27:59 -04:00
|
|
|
|
|
|
|
def assign_to_self!(current_account)
|
|
|
|
update!(assigned_account_id: current_account.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def unassign!
|
|
|
|
update!(assigned_account_id: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolve!(acting_account)
|
2020-03-20 22:08:09 -04:00
|
|
|
if account_id == -99 && target_account.trust_level == Account::TRUST_LEVELS[:untrusted]
|
|
|
|
# This is an automated report and it is being dismissed, so it's
|
|
|
|
# a false positive, in which case update the account's trust level
|
|
|
|
# to prevent further spam checks
|
|
|
|
|
|
|
|
target_account.update(trust_level: Account::TRUST_LEVELS[:trusted])
|
|
|
|
end
|
|
|
|
|
2019-09-11 10:32:44 -04:00
|
|
|
RemovalWorker.push_bulk(Status.with_discarded.discarded.where(id: status_ids).pluck(:id)) { |status_id| [status_id, { immediate: true }] }
|
2018-04-10 14:27:59 -04:00
|
|
|
update!(action_taken: true, action_taken_by_account_id: acting_account.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def unresolve!
|
|
|
|
update!(action_taken: false, action_taken_by_account_id: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def unresolved?
|
|
|
|
!action_taken?
|
|
|
|
end
|
|
|
|
|
2018-09-01 18:11:58 -04:00
|
|
|
def unresolved_siblings?
|
|
|
|
Report.where.not(id: id).where(target_account_id: target_account_id).unresolved.exists?
|
|
|
|
end
|
|
|
|
|
2018-04-10 14:27:59 -04:00
|
|
|
def history
|
|
|
|
time_range = created_at..updated_at
|
|
|
|
|
|
|
|
sql = [
|
|
|
|
Admin::ActionLog.where(
|
|
|
|
target_type: 'Report',
|
|
|
|
target_id: id,
|
|
|
|
created_at: time_range
|
|
|
|
).unscope(:order),
|
|
|
|
|
|
|
|
Admin::ActionLog.where(
|
|
|
|
target_type: 'Account',
|
|
|
|
target_id: target_account_id,
|
|
|
|
created_at: time_range
|
|
|
|
).unscope(:order),
|
|
|
|
|
|
|
|
Admin::ActionLog.where(
|
|
|
|
target_type: 'Status',
|
|
|
|
target_id: status_ids,
|
|
|
|
created_at: time_range
|
|
|
|
).unscope(:order),
|
|
|
|
].map { |query| "(#{query.to_sql})" }.join(' UNION ALL ')
|
|
|
|
|
|
|
|
Admin::ActionLog.from("(#{sql}) AS admin_action_logs")
|
|
|
|
end
|
2019-03-17 10:34:56 -04:00
|
|
|
|
|
|
|
def set_uri
|
|
|
|
self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil? && account.local?
|
|
|
|
end
|
2017-02-14 14:59:26 -05:00
|
|
|
end
|