about summary refs log tree commit diff
path: root/app/models/admin
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-03-01 22:20:29 +0100
committerGitHub <noreply@github.com>2022-03-01 22:20:29 +0100
commit25d3dc4373531071f444d8e44e44cd21970cb373 (patch)
treec58f2e336ebdc3e15de07395bde6dd3ed80a4e24 /app/models/admin
parent14919fe11e9a1dd5cbf12969a2957d0d05bb0534 (diff)
Add ability to mark statuses as sensitive from reports in admin UI (#17668)
* Add ability to mark statuses as sensitive from reports in admin UI

* Allow mark as sensitive action on statuses with preview cards
Diffstat (limited to 'app/models/admin')
-rw-r--r--app/models/admin/status_batch_action.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/models/admin/status_batch_action.rb b/app/models/admin/status_batch_action.rb
index 40f60f379..4d91b9805 100644
--- a/app/models/admin/status_batch_action.rb
+++ b/app/models/admin/status_batch_action.rb
@@ -30,6 +30,8 @@ class Admin::StatusBatchAction
     case type
     when 'delete'
       handle_delete!
+    when 'mark_as_sensitive'
+      handle_mark_as_sensitive!
     when 'report'
       handle_report!
     when 'remove_from_report'
@@ -65,6 +67,38 @@ class Admin::StatusBatchAction
     RemovalWorker.push_bulk(status_ids) { |status_id| [status_id, { 'preserve' => target_account.local?, 'immediate' => !target_account.local? }] }
   end
 
+  def handle_mark_as_sensitive!
+    # Can't use a transaction here because UpdateStatusService queues
+    # Sidekiq jobs
+    statuses.includes(:media_attachments, :preview_cards).find_each do |status|
+      next unless status.with_media? || status.with_preview_card?
+
+      authorize(status, :update?)
+
+      if target_account.local?
+        UpdateStatusService.new.call(status, current_account.id, sensitive: true)
+      else
+        status.update(sensitive: true)
+      end
+
+      log_action(:update, status)
+
+      if with_report?
+        report.resolve!(current_account)
+        log_action(:resolve, report)
+      end
+
+      @warning = target_account.strikes.create!(
+        action: :mark_statuses_as_sensitive,
+        account: current_account,
+        report: report,
+        status_ids: status_ids
+      )
+    end
+
+    UserMailer.warning(target_account.user, @warning).deliver_later! if warnable?
+  end
+
   def handle_report!
     @report = Report.new(report_params) unless with_report?
     @report.status_ids = (@report.status_ids + status_ids.map(&:to_i)).uniq