diff --git a/app/controllers/admin/statuses_controller.rb b/app/controllers/admin/statuses_controller.rb index b80cd20f56..00c4a792c3 100644 --- a/app/controllers/admin/statuses_controller.rb +++ b/app/controllers/admin/statuses_controller.rb @@ -4,7 +4,7 @@ module Admin class StatusesController < BaseController before_action :set_account before_action :set_statuses, except: :show - before_action :set_status, only: :show + before_action :set_status, only: [:show, :remove_history, :remove_media, :force_sensitive, :force_cw, :remove_status] PER_PAGE = 20 @@ -29,6 +29,56 @@ module Admin redirect_to after_create_redirect_path end + def remove_history + authorize [:admin, @status], :show? + UpdateStatusService.new.call( + @status, + @account.id, + no_history: true + ) + redirect_to admin_account_status_path + end + + def remove_media + authorize [:admin, @status], :show? + UpdateStatusService.new.call( + @status, + @account.id, + media_ids: [], + media_attributes: [] + ) + redirect_to admin_account_status_path + end + + def force_sensitive + authorize [:admin, @status], :show? + UpdateStatusService.new.call( + @status, + @account.id, + sensitive: true + ) + redirect_to admin_account_status_path + end + + def force_cw + authorize [:admin, @status], :show? + UpdateStatusService.new.call( + @status, + @account.id, + spoiler_text: 'CW' + ) + redirect_to admin_account_status_path + end + + def remove_status + authorize [:admin, @status], :show? + @status.discard_with_reblogs + StatusPin.find_by(status: @status)&.destroy + @status.account.statuses_count = @status.account.statuses_count - 1 + RemovalWorker.perform_async(@status.id, { 'redraft' => false }) + redirect_to admin_account_path + end + private def admin_status_batch_action_params diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index f75fdf55d9..2022d73932 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -23,12 +23,14 @@ class UpdateStatusService < BaseService @media_attachments_changed = false @poll_changed = false + clear_histories! if @options[:no_history] + Status.transaction do - create_previous_edit! + create_previous_edit! unless @options[:no_history] update_media_attachments! if @options.key?(:media_ids) update_poll! if @options.key?(:poll) update_immediate_attributes! - create_edit! + create_edit! unless @options[:no_history] end queue_poll_notifications! @@ -166,4 +168,10 @@ class UpdateStatusService < BaseService def significant_changes? @status.changed? || @poll_changed || @media_attachments_changed end + + def clear_histories! + @status.edits.destroy_all + @status.edited_at = nil + @status.save! + end end diff --git a/app/views/admin/statuses/show.html.haml b/app/views/admin/statuses/show.html.haml index 62b49de8c8..1ed99cfa3d 100644 --- a/app/views/admin/statuses/show.html.haml +++ b/app/views/admin/statuses/show.html.haml @@ -45,6 +45,19 @@ %th= t('admin.statuses.favourites') %td= friendly_number_to_human @status.favourites_count +%div.action-buttons + %div + - if @account.local? + = link_to t('admin.statuses.remove_history'), remove_history_admin_account_status_path(@account.id), method: :post, class: 'button' if can?(:warn, @account) + - if @account.local? && @status.with_media? + = link_to t('admin.statuses.remove_media'), remove_media_admin_account_status_path(@account.id), method: :post, class: 'button' if can?(:warn, @account) + - if @account.local? && !@status.sensitive && @status.with_media? + = link_to t('admin.statuses.force_nsfw'), force_sensitive_admin_account_status_path(@account.id), method: :post, class: 'button' if can?(:warn, @account) + - if @account.local? && !@status.spoiler_text.present? + = link_to t('admin.statuses.force_cw'), force_cw_admin_account_status_path(@account.id), method: :post, class: 'button' if can?(:warn, @account) + - if @account.local? + = link_to t('admin.statuses.remove'), remove_status_admin_account_status_path(@account.id), method: :post, class: 'button' if can?(:warn, @account) + %hr.spacer/ %h3= t('admin.statuses.history') diff --git a/config/locales/en.yml b/config/locales/en.yml index 99f8f42e76..956072c5be 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -774,6 +774,8 @@ en: report: Report deleted: Deleted favourites: Favourites + force_cw: Force CW + force_nsfw: Force NSFW history: Version history in_reply_to: Replying to language: Language @@ -784,6 +786,9 @@ en: open: Open post original_status: Original post reblogs: Reblogs + remove: Remove post + remove_media: Remove medias + remove_history: Remove edit history status_changed: Post changed title: Account posts trending: Trending diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 73c02f6b5b..19e8312c28 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -760,6 +760,8 @@ ja: report: 通報 deleted: 削除済み favourites: お気に入り + force_cw: 強制CW + force_nsfw: 強制NSFW history: 更新履歴 in_reply_to: 返信先 language: 言語 @@ -770,6 +772,9 @@ ja: open: 投稿を開く original_status: オリジナルの投稿 reblogs: ブースト + remove: 投稿を削除 + remove_media: メディアを削除 + remove_history: 編集履歴を削除 status_changed: 投稿を変更しました title: 投稿一覧 trending: トレンド diff --git a/config/routes.rb b/config/routes.rb index 3ee7a8069d..a72918a527 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -355,6 +355,14 @@ Rails.application.routes.draw do resource :action, only: [:new, :create], controller: 'account_actions' resources :statuses, only: [:index, :show] do + member do + post :remove_history + post :remove_media + post :force_sensitive + post :force_cw + post :remove_status + end + collection do post :batch end