Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 投稿にNGワードが含まれる場合、投稿のモデレーションができなくなる場合がある問題 #685

Merged
merged 1 commit into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/controllers/admin/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def remove_history
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
Expand All @@ -46,7 +47,8 @@ def remove_media
@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
Expand All @@ -57,7 +59,8 @@ def force_sensitive
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
Expand All @@ -68,7 +71,8 @@ def force_cw
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
Expand Down
4 changes: 2 additions & 2 deletions app/models/admin/status_batch_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def handle_mark_as_sensitive!
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
Expand Down Expand Up @@ -119,7 +119,7 @@ def handle_force_cw!
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
Expand Down
4 changes: 2 additions & 2 deletions app/services/approve_appeal_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def undo_delete_statuses!
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

Expand Down
4 changes: 4 additions & 0 deletions app/services/update_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,21 @@ def update_media_attachments!
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] || '')
raise Mastodon::ValidationError, I18n.t('statuses.too_many_mentions') if (mention_to_stranger? || reference_to_stranger?) && Admin::NgWord.stranger_mention_reject_with_extractor?(@options[:text] || '')
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,
Expand Down
7 changes: 7 additions & 0 deletions spec/services/update_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ def match_update_request(req, type)
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'
Fabricate(:ng_word, keyword: 'test', stranger: false)
Expand Down
Loading