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

View File

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

View File

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

View File

@ -30,6 +30,8 @@ class Admin::StatusBatchAction
case type case type
when 'delete' when 'delete'
handle_delete! handle_delete!
when 'mark_as_sensitive'
handle_mark_as_sensitive!
when 'report' when 'report'
handle_report! handle_report!
when 'remove_from_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? }] } RemovalWorker.push_bulk(status_ids) { |status_id| [status_id, { 'preserve' => target_account.local?, 'immediate' => !target_account.local? }] }
end 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! def handle_report!
@report = Report.new(report_params) unless with_report? @report = Report.new(report_params) unless with_report?
@report.status_ids = (@report.status_ids + status_ids.map(&:to_i)).uniq @report.status_ids = (@report.status_ids + status_ids.map(&:to_i)).uniq

View File

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

View File

@ -27,6 +27,8 @@ class ApproveAppealService < BaseService
undo_disable! undo_disable!
when 'delete_statuses' when 'delete_statuses'
undo_delete_statuses! undo_delete_statuses!
when 'mark_statuses_as_sensitive'
undo_mark_statuses_as_sensitive!
when 'sensitive' when 'sensitive'
undo_sensitive! undo_sensitive!
when 'silence' when 'silence'
@ -49,6 +51,12 @@ class ApproveAppealService < BaseService
# Cannot be undone # Cannot be undone
end 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! def undo_sensitive!
target_account.unsensitize! target_account.unsensitize!
end end

View File

@ -22,8 +22,8 @@ class UpdateStatusService < BaseService
Status.transaction do Status.transaction do
create_previous_edit! create_previous_edit!
update_media_attachments! update_media_attachments! if @options.key?(:media_ids)
update_poll! update_poll! if @options.key?(:poll)
update_immediate_attributes! update_immediate_attributes!
create_edit! create_edit!
end end
@ -91,9 +91,9 @@ class UpdateStatusService < BaseService
end end
def update_immediate_attributes! def update_immediate_attributes!
@status.text = @options[:text].presence || @options.delete(:spoiler_text) || '' @status.text = @options[:text].presence || @options.delete(:spoiler_text) || '' if @options.key?(:text)
@status.spoiler_text = @options[:spoiler_text] || '' @status.spoiler_text = @options[:spoiler_text] || '' if @options.key?(:spoiler_text)
@status.sensitive = @options[:sensitive] || @options[:spoiler_text].present? @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.language = valid_locale_or_nil(@options[:language] || @status.language || @status.account.user&.preferred_posting_language || I18n.default_locale)
@status.edited_at = Time.now.utc @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' = link_to t('admin.reports.mark_as_resolved'), resolve_admin_report_path(@report), method: :post, class: 'button'
.report-actions__item__description .report-actions__item__description
= t('admin.reports.actions.resolve_description_html') = 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
.report-actions__item__button .report-actions__item__button
= button_tag t('admin.reports.delete_and_resolve'), name: :delete, class: 'button button--destructive' = button_tag t('admin.reports.delete_and_resolve'), name: :delete, class: 'button button--destructive'

View File

@ -586,6 +586,7 @@ en:
action_taken_by: Action taken by action_taken_by: Action taken by
actions: actions:
delete_description_html: The reported posts will be deleted and a strike will be recorded to help you escalate on future infractions by the same account. delete_description_html: The reported posts will be deleted and a strike will be recorded to help you escalate on future infractions by the same account.
mark_as_sensitive_description_html: The media in the reported posts will be marked as sensitive and a strike will be recorded to help you escalate on future refractions by the same account.
other_description_html: See more options for controlling the account's behaviour and customize communication to the reported account. other_description_html: See more options for controlling the account's behaviour and customize communication to the reported account.
resolve_description_html: No action will be taken against the reported account, no strike recorded, and the report will be closed. resolve_description_html: No action will be taken against the reported account, no strike recorded, and the report will be closed.
silence_description_html: The profile will be visible only to those who already follow it or manually look it up, severely limiting its reach. Can always be reverted. silence_description_html: The profile will be visible only to those who already follow it or manually look it up, severely limiting its reach. Can always be reverted.
@ -606,6 +607,7 @@ en:
forwarded: Forwarded forwarded: Forwarded
forwarded_to: Forwarded to %{domain} forwarded_to: Forwarded to %{domain}
mark_as_resolved: Mark as resolved mark_as_resolved: Mark as resolved
mark_as_sensitive: Mark as sensitive
mark_as_unresolved: Mark as unresolved mark_as_unresolved: Mark as unresolved
no_one_assigned: No one no_one_assigned: No one
notes: notes:
@ -749,6 +751,7 @@ en:
actions: actions:
delete_statuses: "%{name} deleted %{target}'s posts" delete_statuses: "%{name} deleted %{target}'s posts"
disable: "%{name} froze %{target}'s account" disable: "%{name} froze %{target}'s account"
mark_statuses_as_sensitive: "%{name} marked %{target}'s posts as sensitive"
none: "%{name} sent a warning to %{target}" none: "%{name} sent a warning to %{target}"
sensitive: "%{name} marked %{target}'s account as sensitive" sensitive: "%{name} marked %{target}'s account as sensitive"
silence: "%{name} limited %{target}'s account" silence: "%{name} limited %{target}'s account"
@ -831,6 +834,7 @@ en:
actions: actions:
delete_statuses: to delete their posts delete_statuses: to delete their posts
disable: to freeze their account disable: to freeze their account
mark_statuses_as_sensitive: to mark their posts as sensitive
none: a warning none: a warning
sensitive: to mark their account as sensitive sensitive: to mark their account as sensitive
silence: to limit their account silence: to limit their account
@ -1020,8 +1024,9 @@ en:
title_actions: title_actions:
delete_statuses: Post removal delete_statuses: Post removal
disable: Freezing of account disable: Freezing of account
mark_statuses_as_sensitive: Marking of posts as sensitive
none: Warning none: Warning
sensitive: Marking as sensitive of account sensitive: Marking of account as sensitive
silence: Limitation of account silence: Limitation of account
suspend: Suspension of account suspend: Suspension of account
your_appeal_approved: Your appeal has been approved your_appeal_approved: Your appeal has been approved
@ -1623,24 +1628,27 @@ en:
explanation: explanation:
delete_statuses: Some of your posts have been found to violate one or more community guidelines and have been subsequently removed by the moderators of %{instance}. Future violations may result in harsher punitive actions against your account. delete_statuses: Some of your posts have been found to violate one or more community guidelines and have been subsequently removed by the moderators of %{instance}. Future violations may result in harsher punitive actions against your account.
disable: You can no longer use your account, but your profile and other data remains intact. You can request a backup of your data, change account settings or delete your account. disable: You can no longer use your account, but your profile and other data remains intact. You can request a backup of your data, change account settings or delete your account.
mark_statuses_as_sensitive: Some of your posts have been marked as sensitive by the moderators of %{instance}. This means that people will need to tap the media in the posts before a preview is displayed. You can mark media as sensitive yourself when posting in the future.
sensitive: From now on, all your uploaded media files will be marked as sensitive and hidden behind a click-through warning. sensitive: From now on, all your uploaded media files will be marked as sensitive and hidden behind a click-through warning.
silence: You can still use your account but only people who are already following you will see your posts on this server, and you may be excluded from various discovery features. However, others may still manually follow you. silence: You can still use your account but only people who are already following you will see your posts on this server, and you may be excluded from various discovery features. However, others may still manually follow you.
suspend: You can no longer use your account, and your profile and other data are no longer accessible. You can still login to request a backup of your data until the data is fully removed in about 30 days, but we will retain some basic data to prevent you from evading the suspension. suspend: You can no longer use your account, and your profile and other data are no longer accessible. You can still login to request a backup of your data until the data is fully removed in about 30 days, but we will retain some basic data to prevent you from evading the suspension.
get_in_touch: If you believe this is an error, you can reply to this e-mail to get in touch with the staff of %{instance}. get_in_touch: If you believe this is an error, you can reply to this e-mail to get in touch with the staff of %{instance}.
reason: 'Reason:' reason: 'Reason:'
statuses: 'Posts that have been found in violation:' statuses: 'Posts cited:'
subject: subject:
delete_statuses: Your posts on %{acct} have been removed delete_statuses: Your posts on %{acct} have been removed
disable: Your account %{acct} has been frozen disable: Your account %{acct} has been frozen
mark_statuses_as_sensitive: Your posts on %{acct} have been marked as sensitive
none: Warning for %{acct} none: Warning for %{acct}
sensitive: Your media files on %{acct} will be marked as sensitive from now on sensitive: Your posts on %{acct} will be marked as sensitive from now on
silence: Your account %{acct} has been limited silence: Your account %{acct} has been limited
suspend: Your account %{acct} has been suspended suspend: Your account %{acct} has been suspended
title: title:
delete_statuses: Posts removed delete_statuses: Posts removed
disable: Account frozen disable: Account frozen
mark_statuses_as_sensitive: Posts marked as sensitive
none: Warning none: Warning
sensitive: Media hidden sensitive: Account marked as sensitive
silence: Account limited silence: Account limited
suspend: Account suspended suspend: Account suspended
welcome: welcome: