Fix: 投稿にNGワードが含まれる場合、投稿のモデレーションができなくなる場合がある問題 (#685)
This commit is contained in:
parent
de9ab9042f
commit
aef6d96d55
5 changed files with 23 additions and 8 deletions
|
@ -34,7 +34,8 @@ module Admin
|
|||
UpdateStatusService.new.call(
|
||||
@status,
|
||||
edit_status_account_id,
|
||||
no_history: true
|
||||
no_history: true,
|
||||
bypass_validation: true
|
||||
)
|
||||
log_action(:remove_history, @status)
|
||||
redirect_to admin_account_status_path
|
||||
|
@ -46,7 +47,8 @@ module Admin
|
|||
@status,
|
||||
edit_status_account_id,
|
||||
media_ids: [],
|
||||
media_attributes: []
|
||||
media_attributes: [],
|
||||
bypass_validation: true
|
||||
)
|
||||
log_action(:remove_media, @status)
|
||||
redirect_to admin_account_status_path
|
||||
|
@ -57,7 +59,8 @@ module Admin
|
|||
UpdateStatusService.new.call(
|
||||
@status,
|
||||
edit_status_account_id,
|
||||
sensitive: true
|
||||
sensitive: true,
|
||||
bypass_validation: true
|
||||
)
|
||||
log_action(:force_sensitive, @status)
|
||||
redirect_to admin_account_status_path
|
||||
|
@ -68,7 +71,8 @@ module Admin
|
|||
UpdateStatusService.new.call(
|
||||
@status,
|
||||
edit_status_account_id,
|
||||
spoiler_text: 'CW'
|
||||
spoiler_text: 'CW',
|
||||
bypass_validation: true
|
||||
)
|
||||
log_action(:force_cw, @status)
|
||||
redirect_to admin_account_status_path
|
||||
|
|
|
@ -83,7 +83,7 @@ class Admin::StatusBatchAction
|
|||
authorize([:admin, status], :update?)
|
||||
|
||||
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
|
||||
status.update(sensitive: true)
|
||||
end
|
||||
|
@ -119,7 +119,7 @@ class Admin::StatusBatchAction
|
|||
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)
|
||||
UpdateStatusService.new.call(status, representative_account.id, spoiler_text: 'CW', text: status_text, bypass_validation: true)
|
||||
else
|
||||
status.update(spoiler_text: 'CW', text: status_text)
|
||||
end
|
||||
|
|
|
@ -56,14 +56,14 @@ class ApproveAppealService < BaseService
|
|||
def undo_mark_statuses_as_sensitive!
|
||||
representative_account = Account.representative
|
||||
@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
|
||||
|
||||
def undo_force_cw!
|
||||
representative_account = Account.representative
|
||||
@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
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ class UpdateStatusService < BaseService
|
|||
end
|
||||
|
||||
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.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] || '')
|
||||
|
@ -91,10 +92,13 @@ class UpdateStatusService < BaseService
|
|||
end
|
||||
|
||||
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]}")
|
||||
end
|
||||
|
||||
def validate_status_ng_rules!
|
||||
return if @options[:bypass_validation]
|
||||
|
||||
result = check_invalid_status_for_ng_rule! @status.account,
|
||||
reaction_type: 'edit',
|
||||
spoiler_text: @options.key?(:spoiler_text) ? (@options[:spoiler_text] || '') : @status.spoiler_text,
|
||||
|
|
|
@ -277,6 +277,13 @@ RSpec.describe UpdateStatusService, type: :service do
|
|||
expect { subject.call(status, status.account_id, text: text) }.to raise_error(Mastodon::ValidationError)
|
||||
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
|
||||
text = 'ng word aiueo'
|
||||
Form::AdminSettings.new(ng_words: 'test').save
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue