From a6a68a548f8a3b5cac8031ec0fb50482b2795827 Mon Sep 17 00:00:00 2001 From: KMY Date: Thu, 6 Jul 2023 21:12:53 +0900 Subject: [PATCH] Add force CW action button on moderatoring statuses --- .../admin/reports/actions_controller.rb | 4 +- app/lib/activitypub/activity/create.rb | 4 +- app/models/account_warning.rb | 1 + app/models/admin/status_batch_action.rb | 38 +++++++++++++++++++ app/services/approve_appeal_service.rb | 9 +++++ app/views/admin/reports/_actions.html.haml | 5 +++ config/locales/en.yml | 3 ++ config/locales/ja.yml | 3 ++ 8 files changed, 64 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/reports/actions_controller.rb b/app/controllers/admin/reports/actions_controller.rb index 554f7906f8..5572108d59 100644 --- a/app/controllers/admin/reports/actions_controller.rb +++ b/app/controllers/admin/reports/actions_controller.rb @@ -12,7 +12,7 @@ class Admin::Reports::ActionsController < Admin::BaseController authorize @report, :show? case action_from_button - when 'delete', 'mark_as_sensitive' + when 'delete', 'mark_as_sensitive', 'force_cw' status_batch_action = Admin::StatusBatchAction.new( type: action_from_button, status_ids: @report.status_ids, @@ -52,6 +52,8 @@ class Admin::Reports::ActionsController < Admin::BaseController 'delete' elsif params[:mark_as_sensitive] 'mark_as_sensitive' + elsif params[:force_cw] + 'force_cw' elsif params[:silence] 'silence' elsif params[:suspend] diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 12e05b9796..b7ca0927c8 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -473,8 +473,8 @@ class ActivityPub::Activity::Create < ActivityPub::Activity end def process_references! - ActivityPub::FetchReferencesService(@json['references']) unless @json['references'].nil? - ProcessReferencesWorker.perform_async(@status.id, [], []) + references = @json['references'].nil? ? [] : ActivityPub::FetchReferencesService(@json['references']) + ProcessReferencesWorker.perform_async(@status.id, [], references) end def join_group! diff --git a/app/models/account_warning.rb b/app/models/account_warning.rb index 4f8cc53200..1b2ffccae6 100644 --- a/app/models/account_warning.rb +++ b/app/models/account_warning.rb @@ -20,6 +20,7 @@ class AccountWarning < ApplicationRecord enum action: { none: 0, disable: 1_000, + force_cw: 1_200, mark_statuses_as_sensitive: 1_250, delete_statuses: 1_500, sensitive: 2_000, diff --git a/app/models/admin/status_batch_action.rb b/app/models/admin/status_batch_action.rb index b8bdec7223..b5178c672e 100644 --- a/app/models/admin/status_batch_action.rb +++ b/app/models/admin/status_batch_action.rb @@ -33,6 +33,8 @@ class Admin::StatusBatchAction handle_delete! when 'mark_as_sensitive' handle_mark_as_sensitive! + when 'force_cw' + handle_force_cw! when 'report' handle_report! when 'remove_from_report' @@ -104,6 +106,42 @@ class Admin::StatusBatchAction UserMailer.warning(target_account.user, @warning).deliver_later! if warnable? end + def handle_force_cw! + representative_account = Account.representative + + # Can't use a transaction here because UpdateStatusService queues + # Sidekiq jobs + statuses.find_each do |status| + authorize([:admin, status], :update?) + + status_text = status.text + status_text = "#{status.spoiler_text}\n\n#{status_text}" if status.spoiler_text + + if target_account.local? + UpdateStatusService.new.call(status, representative_account.id, spoiler_text: 'CW', text: status_text) + else + status.update(spoiler_text: 'CW', text: status_text) + end + + log_action(:update, status) + + if with_report? + report.resolve!(current_account) + log_action(:resolve, report) + end + end + + @warning = target_account.strikes.create!( + action: :force_cw, + account: current_account, + report: report, + status_ids: status_ids, + text: text + ) + + 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 + allowed_status_ids).uniq diff --git a/app/services/approve_appeal_service.rb b/app/services/approve_appeal_service.rb index 96aaaa7d07..bae70fc1cd 100644 --- a/app/services/approve_appeal_service.rb +++ b/app/services/approve_appeal_service.rb @@ -29,6 +29,8 @@ class ApproveAppealService < BaseService undo_delete_statuses! when 'mark_statuses_as_sensitive' undo_mark_statuses_as_sensitive! + when 'force_cw' + undo_force_cw! when 'sensitive' undo_sensitive! when 'silence' @@ -58,6 +60,13 @@ class ApproveAppealService < BaseService end end + def undo_force_cw! + representative_account = Account.representative + @strike.statuses.includes(:media_attachments).each do |status| + UpdateStatusService.new.call(status, representative_account.id, spoiler_text: '') + end + end + def undo_sensitive! target_account.unsensitize! end diff --git a/app/views/admin/reports/_actions.html.haml b/app/views/admin/reports/_actions.html.haml index aad4416257..0fe558dafe 100644 --- a/app/views/admin/reports/_actions.html.haml +++ b/app/views/admin/reports/_actions.html.haml @@ -11,6 +11,11 @@ = 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.force_cw'), name: :force_cw, class: 'button' + .report-actions__item__description + = t('admin.reports.actions.force_cw_description_html') .report-actions__item .report-actions__item__button = button_tag t('admin.reports.delete_and_resolve'), name: :delete, class: 'button button--destructive' diff --git a/config/locales/en.yml b/config/locales/en.yml index db2712cd8a..cb7b616c1a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1835,6 +1835,7 @@ en: 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}. 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. + force_cw: Some of your posts have been added warning (CW) by the moderators of %{instance}. This means that people will need to tap the text in the posts before a preview is displayed. You can add posts warning yourself when posting in the future. 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. 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. @@ -1844,6 +1845,7 @@ en: subject: delete_statuses: Your posts on %{acct} have been removed disable: Your account %{acct} has been frozen + force_cw: Your posts on %{acct} have been added warning mark_statuses_as_sensitive: Your posts on %{acct} have been marked as sensitive none: Warning for %{acct} sensitive: Your posts on %{acct} will be marked as sensitive from now on @@ -1852,6 +1854,7 @@ en: title: delete_statuses: Posts removed disable: Account frozen + force_cw: Posts added warning mark_statuses_as_sensitive: Posts marked as sensitive none: Warning sensitive: Account marked as sensitive diff --git a/config/locales/ja.yml b/config/locales/ja.yml index c39c64d4ad..7052d023e3 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1769,6 +1769,7 @@ ja: explanation: delete_statuses: あなたの投稿のいくつかは、1つ以上のコミュニティガイドラインに違反していることが判明し、%{instance}のモデレータによって削除されました。 disable: アカウントは使用できませんが、プロフィールやその他のデータはそのまま残ります。 データのバックアップをリクエストしたり、アカウント設定を変更したり、アカウントを削除したりできます。 + force_cw: あなたのいくつかの投稿は、%{instance}のモデレータによって閲覧注意としてマークされています。これは、投稿本文が表示される前にユーザが投稿内のボタンをタップする必要があることを意味します。あなたは将来投稿する際に自分自身で文章に警告を記述することができます。 mark_statuses_as_sensitive: あなたのいくつかの投稿は、%{instance}のモデレータによって閲覧注意としてマークされています。これは、プレビューが表示される前にユーザが投稿内のメディアをタップする必要があることを意味します。あなたは将来投稿する際に自分自身でメディアを閲覧注意としてマークすることができます。 sensitive: 今後、アップロードされたすべてのメディアファイルは閲覧注意としてマークされ、クリック解除式の警告で覆われるようになります。 silence: アカウントが制限されています。このサーバーでは既にフォローしている人だけがあなたの投稿を見ることができます。 様々な発見機能から除外されるかもしれません。他の人があなたを手動でフォローすることは可能です。 @@ -1778,6 +1779,7 @@ ja: subject: delete_statuses: "%{acct}さんの投稿が削除されました" disable: あなたのアカウント %{acct}は凍結されました + force_cw: あなたの%{acct}の投稿はCWとして警告文が追加されました mark_statuses_as_sensitive: あなたの%{acct}の投稿は閲覧注意としてマークされました none: "%{acct}に対する警告" sensitive: あなたの%{acct}の投稿はこれから閲覧注意としてマークされます @@ -1786,6 +1788,7 @@ ja: title: delete_statuses: 投稿が削除されました disable: アカウントが凍結されました + force_cw: 閲覧注意として警告が追加された投稿 mark_statuses_as_sensitive: 閲覧注意としてマークされた投稿 none: 警告 sensitive: 閲覧注意としてマークされたアカウント