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