1 # frozen_string_literal: true
2 # == Schema Information
6 # id :bigint(8) not null, primary key
7 # status_ids :bigint(8) default([]), not null, is an Array
8 # comment :text default(""), not null
9 # action_taken :boolean default(FALSE), not null
10 # created_at :datetime not null
11 # updated_at :datetime not null
12 # account_id :bigint(8) not null
13 # action_taken_by_account_id :bigint(8)
14 # target_account_id :bigint(8) not null
15 # assigned_account_id :bigint(8)
20 class Report
< ApplicationRecord
24 rate_limit by
: :account, family
: :reports
27 belongs_to
:target_account, class_name
: 'Account'
28 belongs_to
:action_taken_by_account, class_name
: 'Account', optional
: true
29 belongs_to
:assigned_account, class_name
: 'Account', optional
: true
31 has_many
:notes, class_name
: 'ReportNote', foreign_key
: :report_id, inverse_of
: :report, dependent
: :destroy
33 scope
:unresolved, -> { where(action_taken
: false) }
34 scope
:resolved, -> { where(action_taken
: true) }
35 scope
:with_accounts, -> { includes([:account, :target_account, :action_taken_by_account, :assigned_account].index_with({ user
: [:invite_request, :invite] })) }
37 validates
:comment, length
: { maximum
: 1000 }
40 false # Force uri_for to use uri attribute
43 before_validation
:set_uri, only
: :create
50 Status
.with_discarded
.where(id
: status_ids
).includes(:account, :media_attachments, :mentions)
54 MediaAttachment
.where(status_id
: status_ids
)
57 def assign_to_self!
(current_account
)
58 update!
(assigned_account_id
: current_account
.id
)
62 update!
(assigned_account_id
: nil)
65 def resolve!
(acting_account
)
66 if account_id
== -99 && target_account
.trust_level
== Account
::TRUST_LEVELS[:untrusted]
67 # This is an automated report and it is being dismissed, so it's
68 # a false positive, in which case update the account's trust level
69 # to prevent further spam checks
71 target_account
.update(trust_level
: Account
::TRUST_LEVELS[:trusted])
74 RemovalWorker
.push_bulk(Status
.with_discarded
.discarded
.where(id
: status_ids
).pluck(:id)) { |status_id
| [status_id
, { immediate
: true }] }
75 update!
(action_taken
: true, action_taken_by_account_id
: acting_account
.id
)
79 update!
(action_taken
: false, action_taken_by_account_id
: nil)
86 def unresolved_siblings
?
87 Report
.where
.not(id
: id
).where(target_account_id
: target_account_id
).unresolved
.exists
?
91 time_range
= created_at
..updated_at
94 Admin
::ActionLog.where(
95 target_type
: 'Report',
97 created_at
: time_range
100 Admin
::ActionLog.where(
101 target_type
: 'Account',
102 target_id
: target_account_id
,
103 created_at
: time_range
106 Admin
::ActionLog.where(
107 target_type
: 'Status',
108 target_id
: status_ids
,
109 created_at
: time_range
111 ].map
{ |query
| "(#{query.to_sql})" }.join(' UNION ALL ')
113 Admin
::ActionLog.from("(#{sql}) AS admin_action_logs")
117 self.uri
= ActivityPub
::TagManager.instance
.generate_uri_for(self) if uri
.nil? && account
.local
?