Skip to content

Commit 2d3087f

Browse files
Gargronhiyuki2578
authored andcommitted
Change deletes to preserve soft-deleted statuses in unresolved reports (mastodon#11805)
Change all account actions except "none" to resolve all unresolved reports Refactor `SuspendAccountService` to be more readable
1 parent 05cdfc1 commit 2d3087f

21 files changed

Lines changed: 98 additions & 45 deletions

app/controllers/admin/accounts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def approve
4141

4242
def reject
4343
authorize @account.user, :reject?
44-
SuspendAccountService.new.call(@account, including_user: true, destroy: true, skip_distribution: true)
44+
SuspendAccountService.new.call(@account, reserve_email: false, reserve_username: false)
4545
redirect_to admin_pending_accounts_path
4646
end
4747

app/controllers/admin/report_notes_controller.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ class ReportNotesController < BaseController
55
before_action :set_report_note, only: [:destroy]
66

77
def create
8-
authorize ReportNote, :create?
8+
authorize :report_note, :create?
99

1010
@report_note = current_account.report_notes.new(resource_params)
11-
@report = @report_note.report
11+
@report = @report_note.report
1212

1313
if @report_note.save
1414
if params[:create_and_resolve]
@@ -26,9 +26,8 @@ def create
2626

2727
redirect_to admin_report_path(@report), notice: I18n.t('admin.report_notes.created_msg')
2828
else
29-
@report_notes = @report.notes.latest
30-
@report_history = @report.history
31-
@form = Form::StatusBatch.new
29+
@report_notes = (@report.notes.latest + @report.history + @report.target_account.targeted_account_warnings.latest.custom).sort_by(&:created_at)
30+
@form = Form::StatusBatch.new
3231

3332
render template: 'admin/reports/show'
3433
end

app/controllers/api/v1/admin/accounts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def approve
5858

5959
def reject
6060
authorize @account.user, :reject?
61-
SuspendAccountService.new.call(@account, including_user: true, destroy: true, skip_distribution: true)
61+
SuspendAccountService.new.call(@account, reserve_email: false, reserve_username: false)
6262
render json: @account, serializer: REST::Admin::AccountSerializer
6363
end
6464

app/lib/activitypub/activity/delete.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ def perform
1313

1414
def delete_person
1515
lock_or_return("delete_in_progress:#{@account.id}") do
16-
SuspendAccountService.new.call(@account)
17-
@account.destroy!
16+
SuspendAccountService.new.call(@account, reserve_username: false)
1817
end
1918
end
2019

app/models/account.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class Account < ApplicationRecord
116116
:approved?,
117117
:pending?,
118118
:disabled?,
119+
:unconfirmed_or_pending?,
119120
:role,
120121
:admin?,
121122
:moderator?,

app/models/admin/account_action.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,23 @@ def process_warning!
8383

8484
# A log entry is only interesting if the warning contains
8585
# custom text from someone. Otherwise it's just noise.
86+
8687
log_action(:create, warning) if warning.text.present?
8788
end
8889

8990
def process_reports!
90-
return if report_id.blank?
91+
# If we're doing "mark as resolved" on a single report,
92+
# then we want to keep other reports open in case they
93+
# contain new actionable information.
94+
#
95+
# Otherwise, we will mark all unresolved reports about
96+
# the account as resolved.
9197

92-
authorize(report, :update?)
98+
reports.each { |report| authorize(report, :update?) }
9399

94-
if type == 'none'
100+
reports.each do |report|
95101
log_action(:resolve, report)
96102
report.resolve!(current_account)
97-
else
98-
Report.where(target_account: target_account).unresolved.update_all(action_taken: true, action_taken_by_account_id: current_account.id)
99103
end
100104
end
101105

@@ -141,6 +145,16 @@ def status_ids
141145
@report.status_ids if @report && include_statuses
142146
end
143147

148+
def reports
149+
@reports ||= begin
150+
if type == 'none' && with_report?
151+
[report]
152+
else
153+
Report.where(target_account: target_account).unresolved
154+
end
155+
end
156+
end
157+
144158
def warning_preset
145159
@warning_preset ||= AccountWarningPreset.find(warning_preset_id) if warning_preset_id.present?
146160
end

app/models/form/account_batch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ def reject!
6969
records = accounts.includes(:user)
7070

7171
records.each { |account| authorize(account.user, :reject?) }
72-
.each { |account| SuspendAccountService.new.call(account, including_user: true, destroy: true, skip_distribution: true) }
72+
.each { |account| SuspendAccountService.new.call(account, reserve_email: false, reserve_username: false) }
7373
end
7474
end

app/models/form/status_batch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def change_sensitive(sensitive)
3535
def delete_statuses
3636
Status.where(id: status_ids).reorder(nil).find_each do |status|
3737
status.discard
38-
RemovalWorker.perform_async(status.id, redraft: false)
38+
RemovalWorker.perform_async(status.id, immediate: true)
3939
Tombstone.find_or_create_by(uri: status.uri, account: status.account, by_moderator: true)
4040
log_action :destroy, status
4141
end

app/models/report.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def unassign!
5959
end
6060

6161
def resolve!(acting_account)
62+
RemovalWorker.push_bulk(Status.with_discarded.discarded.where(id: status_ids).pluck(:id)) { |status_id| [status_id, { immediate: true }] }
6263
update!(action_taken: true, action_taken_by_account_id: acting_account.id)
6364
end
6465

app/models/status.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ def non_sensitive_with_media?
217217
!sensitive? && with_media?
218218
end
219219

220+
def reported?
221+
@reported ||= Report.where(target_account: account).unresolved.where('? = ANY(status_ids)', id).exists?
222+
end
223+
220224
def emojis
221225
return @emojis if defined?(@emojis)
222226

0 commit comments

Comments
 (0)