From aef6d96d55a6dee35ece4b7d47cbe021f272cd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KMY=EF=BC=88=E9=9B=AA=E3=81=82=E3=81=99=E3=81=8B=EF=BC=89?= Date: Mon, 1 Apr 2024 08:54:16 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=E6=8A=95=E7=A8=BF=E3=81=ABNG=E3=83=AF?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=81=8C=E5=90=AB=E3=81=BE=E3=82=8C=E3=82=8B?= =?UTF-8?q?=E5=A0=B4=E5=90=88=E3=80=81=E6=8A=95=E7=A8=BF=E3=81=AE=E3=83=A2?= =?UTF-8?q?=E3=83=87=E3=83=AC=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=8C?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=8F=E3=81=AA=E3=82=8B=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=8C=E3=81=82=E3=82=8B=E5=95=8F=E9=A1=8C=20(#685)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin/statuses_controller.rb | 12 ++++++++---- app/models/admin/status_batch_action.rb | 4 ++-- app/services/approve_appeal_service.rb | 4 ++-- app/services/update_status_service.rb | 4 ++++ spec/services/update_status_service_spec.rb | 7 +++++++ 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/statuses_controller.rb b/app/controllers/admin/statuses_controller.rb index 5fdea8c52f..64b516d815 100644 --- a/app/controllers/admin/statuses_controller.rb +++ b/app/controllers/admin/statuses_controller.rb @@ -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 diff --git a/app/models/admin/status_batch_action.rb b/app/models/admin/status_batch_action.rb index 99274c85b2..d295b01e28 100644 --- a/app/models/admin/status_batch_action.rb +++ b/app/models/admin/status_batch_action.rb @@ -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 diff --git a/app/services/approve_appeal_service.rb b/app/services/approve_appeal_service.rb index 6de051edc4..40bb76b8a4 100644 --- a/app/services/approve_appeal_service.rb +++ b/app/services/approve_appeal_service.rb @@ -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 diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index 2a3bf5f179..342c320e82 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -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, diff --git a/spec/services/update_status_service_spec.rb b/spec/services/update_status_service_spec.rb index 89184a4f4c..22bbc4d5b8 100644 --- a/spec/services/update_status_service_spec.rb +++ b/spec/services/update_status_service_spec.rb @@ -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