Add admin status edit commands

This commit is contained in:
KMY 2023-03-16 23:27:51 +09:00
parent 7910ab0333
commit ad102071bc
6 changed files with 92 additions and 3 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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: トレンド

View file

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