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
This commit is contained in:
Eugen Rochko 2022-03-01 22:20:29 +01:00 committed by GitHub
parent 14919fe11e
commit 25d3dc4373
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 16 deletions

View file

@ -7,7 +7,7 @@ class Admin::Reports::ActionsController < Admin::BaseController
authorize @report, :show?
case action_from_button
when 'delete'
when 'delete', 'mark_as_sensitive'
status_batch_action = Admin::StatusBatchAction.new(
type: action_from_button,
status_ids: @report.status_ids,
@ -41,6 +41,8 @@ class Admin::Reports::ActionsController < Admin::BaseController
def action_from_button
if params[:delete]
'delete'
elsif params[:mark_as_sensitive]
'mark_as_sensitive'
elsif params[:silence]
'silence'
elsif params[:suspend]

View file

@ -1504,6 +1504,8 @@ a.sparkline {
word-wrap: break-word;
font-weight: 400;
color: $primary-text-color;
box-sizing: border-box;
min-height: 100%;
p {
margin-bottom: 20px;

View file

@ -17,12 +17,13 @@
class AccountWarning < ApplicationRecord
enum action: {
none: 0,
disable: 1_000,
delete_statuses: 1_500,
sensitive: 2_000,
silence: 3_000,
suspend: 4_000,
none: 0,
disable: 1_000,
mark_statuses_as_sensitive: 1_250,
delete_statuses: 1_500,
sensitive: 2_000,
silence: 3_000,
suspend: 4_000,
}, _suffix: :action
belongs_to :account, inverse_of: :account_warnings

View file

@ -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

View file

@ -231,6 +231,10 @@ class Status < ApplicationRecord
media_attachments.any?
end
def with_preview_card?
preview_cards.any?
end
def non_sensitive_with_media?
!sensitive? && with_media?
end

View file

@ -27,6 +27,8 @@ class ApproveAppealService < BaseService
undo_disable!
when 'delete_statuses'
undo_delete_statuses!
when 'mark_statuses_as_sensitive'
undo_mark_statuses_as_sensitive!
when 'sensitive'
undo_sensitive!
when 'silence'
@ -49,6 +51,12 @@ class ApproveAppealService < BaseService
# Cannot be undone
end
def undo_mark_statuses_as_sensitive!
@strike.statuses.includes(:media_attachments).each do |status|
UpdateStatusService.new.call(status, @current_account.id, sensitive: false) if status.with_media?
end
end
def undo_sensitive!
target_account.unsensitize!
end

View file

@ -22,8 +22,8 @@ class UpdateStatusService < BaseService
Status.transaction do
create_previous_edit!
update_media_attachments!
update_poll!
update_media_attachments! if @options.key?(:media_ids)
update_poll! if @options.key?(:poll)
update_immediate_attributes!
create_edit!
end
@ -91,9 +91,9 @@ class UpdateStatusService < BaseService
end
def update_immediate_attributes!
@status.text = @options[:text].presence || @options.delete(:spoiler_text) || ''
@status.spoiler_text = @options[:spoiler_text] || ''
@status.sensitive = @options[:sensitive] || @options[:spoiler_text].present?
@status.text = @options[:text].presence || @options.delete(:spoiler_text) || '' if @options.key?(:text)
@status.spoiler_text = @options[:spoiler_text] || '' if @options.key?(:spoiler_text)
@status.sensitive = @options[:sensitive] || @options[:spoiler_text].present? if @options.key?(:sensitive) || @options.key?(:spoiler_text)
@status.language = valid_locale_or_nil(@options[:language] || @status.language || @status.account.user&.preferred_posting_language || I18n.default_locale)
@status.edited_at = Time.now.utc

View file

@ -5,6 +5,12 @@
= link_to t('admin.reports.mark_as_resolved'), resolve_admin_report_path(@report), method: :post, class: 'button'
.report-actions__item__description
= t('admin.reports.actions.resolve_description_html')
- if @statuses.any? { |status| status.with_media? || status.with_preview_card? }
.report-actions__item
.report-actions__item__button
= button_tag t('admin.reports.mark_as_sensitive'), name: :mark_as_sensitive, class: 'button'
.report-actions__item__description
= t('admin.reports.actions.mark_as_sensitive_description_html')
.report-actions__item
.report-actions__item__button
= button_tag t('admin.reports.delete_and_resolve'), name: :delete, class: 'button button--destructive'