Fix: 投稿にNGワードが含まれる場合、投稿のモデレーションができなくなる場合がある問題 (#685)
This commit is contained in:
parent
4a9f549dd2
commit
e7aececf5e
5 changed files with 23 additions and 8 deletions
|
@ -34,7 +34,8 @@ module Admin
|
||||||
UpdateStatusService.new.call(
|
UpdateStatusService.new.call(
|
||||||
@status,
|
@status,
|
||||||
edit_status_account_id,
|
edit_status_account_id,
|
||||||
no_history: true
|
no_history: true,
|
||||||
|
bypass_validation: true
|
||||||
)
|
)
|
||||||
log_action(:remove_history, @status)
|
log_action(:remove_history, @status)
|
||||||
redirect_to admin_account_status_path
|
redirect_to admin_account_status_path
|
||||||
|
@ -46,7 +47,8 @@ module Admin
|
||||||
@status,
|
@status,
|
||||||
edit_status_account_id,
|
edit_status_account_id,
|
||||||
media_ids: [],
|
media_ids: [],
|
||||||
media_attributes: []
|
media_attributes: [],
|
||||||
|
bypass_validation: true
|
||||||
)
|
)
|
||||||
log_action(:remove_media, @status)
|
log_action(:remove_media, @status)
|
||||||
redirect_to admin_account_status_path
|
redirect_to admin_account_status_path
|
||||||
|
@ -57,7 +59,8 @@ module Admin
|
||||||
UpdateStatusService.new.call(
|
UpdateStatusService.new.call(
|
||||||
@status,
|
@status,
|
||||||
edit_status_account_id,
|
edit_status_account_id,
|
||||||
sensitive: true
|
sensitive: true,
|
||||||
|
bypass_validation: true
|
||||||
)
|
)
|
||||||
log_action(:force_sensitive, @status)
|
log_action(:force_sensitive, @status)
|
||||||
redirect_to admin_account_status_path
|
redirect_to admin_account_status_path
|
||||||
|
@ -68,7 +71,8 @@ module Admin
|
||||||
UpdateStatusService.new.call(
|
UpdateStatusService.new.call(
|
||||||
@status,
|
@status,
|
||||||
edit_status_account_id,
|
edit_status_account_id,
|
||||||
spoiler_text: 'CW'
|
spoiler_text: 'CW',
|
||||||
|
bypass_validation: true
|
||||||
)
|
)
|
||||||
log_action(:force_cw, @status)
|
log_action(:force_cw, @status)
|
||||||
redirect_to admin_account_status_path
|
redirect_to admin_account_status_path
|
||||||
|
|
|
@ -83,7 +83,7 @@ class Admin::StatusBatchAction
|
||||||
authorize([:admin, status], :update?)
|
authorize([:admin, status], :update?)
|
||||||
|
|
||||||
if target_account.local?
|
if target_account.local?
|
||||||
UpdateStatusService.new.call(status, representative_account.id, sensitive: true)
|
UpdateStatusService.new.call(status, representative_account.id, sensitive: true, bypass_validation: true)
|
||||||
else
|
else
|
||||||
status.update(sensitive: true)
|
status.update(sensitive: true)
|
||||||
end
|
end
|
||||||
|
@ -119,7 +119,7 @@ class Admin::StatusBatchAction
|
||||||
status_text = "#{status.spoiler_text}\n\n#{status_text}" if status.spoiler_text
|
status_text = "#{status.spoiler_text}\n\n#{status_text}" if status.spoiler_text
|
||||||
|
|
||||||
if target_account.local?
|
if target_account.local?
|
||||||
UpdateStatusService.new.call(status, representative_account.id, spoiler_text: 'CW', text: status_text)
|
UpdateStatusService.new.call(status, representative_account.id, spoiler_text: 'CW', text: status_text, bypass_validation: true)
|
||||||
else
|
else
|
||||||
status.update(spoiler_text: 'CW', text: status_text)
|
status.update(spoiler_text: 'CW', text: status_text)
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,14 +56,14 @@ class ApproveAppealService < BaseService
|
||||||
def undo_mark_statuses_as_sensitive!
|
def undo_mark_statuses_as_sensitive!
|
||||||
representative_account = Account.representative
|
representative_account = Account.representative
|
||||||
@strike.statuses.includes(:media_attachments).find_each do |status|
|
@strike.statuses.includes(:media_attachments).find_each do |status|
|
||||||
UpdateStatusService.new.call(status, representative_account.id, sensitive: false) if status.with_media?
|
UpdateStatusService.new.call(status, representative_account.id, sensitive: false, bypass_validation: true) if status.with_media?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def undo_force_cw!
|
def undo_force_cw!
|
||||||
representative_account = Account.representative
|
representative_account = Account.representative
|
||||||
@strike.statuses.includes(:media_attachments).find_each do |status|
|
@strike.statuses.includes(:media_attachments).find_each do |status|
|
||||||
UpdateStatusService.new.call(status, representative_account.id, spoiler_text: '')
|
UpdateStatusService.new.call(status, representative_account.id, spoiler_text: '', bypass_validation: true) if status.spoiler_text.present?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,7 @@ class UpdateStatusService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_status!
|
def validate_status!
|
||||||
|
return if @options[:bypass_validation]
|
||||||
raise Mastodon::ValidationError, I18n.t('statuses.contains_ng_words') if Admin::NgWord.reject?("#{@options[:spoiler_text]}\n#{@options[:text]}")
|
raise Mastodon::ValidationError, I18n.t('statuses.contains_ng_words') if Admin::NgWord.reject?("#{@options[:spoiler_text]}\n#{@options[:text]}")
|
||||||
raise Mastodon::ValidationError, I18n.t('statuses.too_many_hashtags') if Admin::NgWord.hashtag_reject_with_extractor?(@options[:text] || '')
|
raise Mastodon::ValidationError, I18n.t('statuses.too_many_hashtags') if Admin::NgWord.hashtag_reject_with_extractor?(@options[:text] || '')
|
||||||
raise Mastodon::ValidationError, I18n.t('statuses.too_many_mentions') if Admin::NgWord.mention_reject_with_extractor?(@options[:text] || '')
|
raise Mastodon::ValidationError, I18n.t('statuses.too_many_mentions') if Admin::NgWord.mention_reject_with_extractor?(@options[:text] || '')
|
||||||
|
@ -91,10 +92,13 @@ class UpdateStatusService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_status_mentions!
|
def validate_status_mentions!
|
||||||
|
return if @options[:bypass_validation]
|
||||||
raise Mastodon::ValidationError, I18n.t('statuses.contains_ng_words') if (mention_to_stranger? || reference_to_stranger?) && Setting.stranger_mention_from_local_ng && Admin::NgWord.stranger_mention_reject?("#{@options[:spoiler_text]}\n#{@options[:text]}")
|
raise Mastodon::ValidationError, I18n.t('statuses.contains_ng_words') if (mention_to_stranger? || reference_to_stranger?) && Setting.stranger_mention_from_local_ng && Admin::NgWord.stranger_mention_reject?("#{@options[:spoiler_text]}\n#{@options[:text]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_status_ng_rules!
|
def validate_status_ng_rules!
|
||||||
|
return if @options[:bypass_validation]
|
||||||
|
|
||||||
result = check_invalid_status_for_ng_rule! @status.account,
|
result = check_invalid_status_for_ng_rule! @status.account,
|
||||||
reaction_type: 'edit',
|
reaction_type: 'edit',
|
||||||
spoiler_text: @options.key?(:spoiler_text) ? (@options[:spoiler_text] || '') : @status.spoiler_text,
|
spoiler_text: @options.key?(:spoiler_text) ? (@options[:spoiler_text] || '') : @status.spoiler_text,
|
||||||
|
|
|
@ -277,6 +277,13 @@ RSpec.describe UpdateStatusService do
|
||||||
expect { subject.call(status, status.account_id, text: text) }.to raise_error(Mastodon::ValidationError)
|
expect { subject.call(status, status.account_id, text: text) }.to raise_error(Mastodon::ValidationError)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'bypass ng words' do
|
||||||
|
text = 'ng word test'
|
||||||
|
Fabricate(:ng_word, keyword: 'test', stranger: false)
|
||||||
|
|
||||||
|
expect { subject.call(status, status.account_id, text: text, bypass_validation: true) }.to_not raise_error
|
||||||
|
end
|
||||||
|
|
||||||
it 'not hit ng words' do
|
it 'not hit ng words' do
|
||||||
text = 'ng word aiueo'
|
text = 'ng word aiueo'
|
||||||
Fabricate(:ng_word, keyword: 'test', stranger: false)
|
Fabricate(:ng_word, keyword: 'test', stranger: false)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue