diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2019-09-11 16:32:44 +0200 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2020-02-27 13:55:39 -0600 |
commit | 3681f7dcce8f82d2a4377a051952159cd03919c0 (patch) | |
tree | 1e11fbf90b822450b0e736408cb17442babc54a6 /app/models | |
parent | 422b59808b4818171e057e1a459de153816bf505 (diff) |
port tootsuite#11805 to monserfork: Change deletes to preserve soft-deleted statuses in unresolved reports
Change all account actions except "none" to resolve all unresolved reports Refactor `SuspendAccountService` to be more readable
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 3 | ||||
-rw-r--r-- | app/models/admin/account_action.rb | 28 | ||||
-rw-r--r-- | app/models/form/account_batch.rb | 2 | ||||
-rw-r--r-- | app/models/form/status_batch.rb | 2 | ||||
-rw-r--r-- | app/models/report.rb | 1 | ||||
-rw-r--r-- | app/models/status.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 4 |
7 files changed, 37 insertions, 7 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index bcb6d4888..cc7c5be42 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -131,6 +131,9 @@ class Account < ApplicationRecord :confirmed?, :approved?, :pending?, + :disabled?, + :unconfirmed_or_pending?, + :role, :admin?, :moderator?, :halfmod?, diff --git a/app/models/admin/account_action.rb b/app/models/admin/account_action.rb index 9789cb553..173e4620b 100644 --- a/app/models/admin/account_action.rb +++ b/app/models/admin/account_action.rb @@ -87,19 +87,23 @@ class Admin::AccountAction # A log entry is only interesting if the warning contains # custom text from someone. Otherwise it's just noise. + log_action(:create, warning) if warning.text.present? end def process_reports! - return if report_id.blank? + # If we're doing "mark as resolved" on a single report, + # then we want to keep other reports open in case they + # contain new actionable information. + # + # Otherwise, we will mark all unresolved reports about + # the account as resolved. - authorize(report, :update?) + reports.each { |report| authorize(report, :update?) } - if type == 'none' + reports.each do |report| log_action(:resolve, report) report.resolve!(current_account) - else - Report.where(target_account: target_account).unresolved.update_all(action_taken: true, action_taken_by_account_id: current_account.id) end end @@ -164,6 +168,20 @@ class Admin::AccountAction send_email_notification && target_account.local? end + def status_ids + @report.status_ids if @report && include_statuses + end + + def reports + @reports ||= begin + if type == 'none' && with_report? + [report] + else + Report.where(target_account: target_account).unresolved + end + end + end + def warning_preset @warning_preset ||= AccountWarningPreset.find(warning_preset_id) if warning_preset_id.present? end diff --git a/app/models/form/account_batch.rb b/app/models/form/account_batch.rb index 22aed7e34..725001436 100644 --- a/app/models/form/account_batch.rb +++ b/app/models/form/account_batch.rb @@ -67,6 +67,6 @@ class Form::AccountBatch records = accounts.includes(:user) records.each { |account| authorize(account.user, :reject?) } - .each { |account| SuspendAccountService.new.call(account, including_user: true, destroy: true, skip_distribution: true) } + .each { |account| SuspendAccountService.new.call(account, reserve_email: false, reserve_username: false) } end end diff --git a/app/models/form/status_batch.rb b/app/models/form/status_batch.rb index 91710a5d7..79394d0f8 100644 --- a/app/models/form/status_batch.rb +++ b/app/models/form/status_batch.rb @@ -34,7 +34,7 @@ class Form::StatusBatch def delete_statuses Status.where(id: status_ids).reorder(nil).find_each do |status| status.discard - RemovalWorker.perform_async(status.id, redraft: false) + RemovalWorker.perform_async(status.id, immediate: true) Tombstone.find_or_create_by(uri: status.uri, account: status.account, by_moderator: true) log_action :destroy, status end diff --git a/app/models/report.rb b/app/models/report.rb index 07389ef63..aaf5b5407 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -56,6 +56,7 @@ class Report < ApplicationRecord end def resolve!(acting_account) + RemovalWorker.push_bulk(Status.with_discarded.discarded.where(id: status_ids).pluck(:id)) { |status_id| [status_id, { immediate: true }] } update!(action_taken: true, action_taken_by_account_id: acting_account.id) end diff --git a/app/models/status.rb b/app/models/status.rb index 2d2b0aafe..4258fe39d 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -272,6 +272,10 @@ class Status < ApplicationRecord !sensitive? && with_media? end + def reported? + @reported ||= Report.where(target_account: account).unresolved.where('? = ANY(status_ids)', id).exists? + end + def emojis return @emojis if defined?(@emojis) diff --git a/app/models/user.rb b/app/models/user.rb index bd2c16a22..52d9a2add 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -258,6 +258,10 @@ class User < ApplicationRecord confirmed? && approved? && !disabled? && !account.suspended? end + def unconfirmed_or_pending? + !(confirmed? && approved?) + end + def inactive_message !approved? ? :pending : super end |