From 79ae596c2d032300ed0bb60405248f3a7f7cd2de Mon Sep 17 00:00:00 2001 From: KMY Date: Mon, 1 Apr 2024 08:24:24 +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=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= 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 5fdea8c52f56f6..64b516d81561fa 100644 --- a/app/controllers/admin/statuses_controller.rb +++ b/app/controllers/admin/statuses_controller.rb @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/app/models/admin/status_batch_action.rb b/app/models/admin/status_batch_action.rb index 99274c85b29f8e..d295b01e288ed1 100644 --- a/app/models/admin/status_batch_action.rb +++ b/app/models/admin/status_batch_action.rb @@ -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 @@ -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 diff --git a/app/services/approve_appeal_service.rb b/app/services/approve_appeal_service.rb index 6de051edc457f4..40bb76b8a488b2 100644 --- a/app/services/approve_appeal_service.rb +++ b/app/services/approve_appeal_service.rb @@ -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 diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index 2a3bf5f179d599..342c320e82fe55 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -84,6 +84,7 @@ 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] || '') @@ -91,10 +92,13 @@ def validate_status! 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 211e80e65b7990..30661189579b4d 100644 --- a/spec/services/update_status_service_spec.rb +++ b/spec/services/update_status_service_spec.rb @@ -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)