A platform for community discussion. Free, open, simple.
DEV: add site setting to disable watched word checking in user fields (#25411)
marstall5a00d1964fc6
diff --git a/app/models/user.rb b/app/models/user.rbindex 6f38448089f..0326df16c34 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -151,7 +151,10 @@ class User < ActiveRecord::Basevalidates :name, user_full_name: true, if: :will_save_change_to_name?, length: { maximum: 255 }validates :ip_address, allowed_ip_address: { on: :create }validates :primary_email, presence: true, unless: :skip_email_validation- validates :validatable_user_fields_values, watched_words: true, unless: :custom_fields_clean?+ validates :validatable_user_fields_values,+ watched_words: true,+ unless: :should_skip_user_fields_validation?+validates_associated :primary_email,message: ->(_, user_email) { user_email[:value]&.errors&.[](:email)&.first }@@ -180,7 +183,7 @@ class User < ActiveRecord::Basebefore_save :ensure_password_is_hashedbefore_save :match_primary_group_changesbefore_save :check_if_title_is_badged_granted- before_save :apply_watched_words, unless: :custom_fields_clean?+ before_save :apply_watched_words, unless: :should_skip_user_fields_validation?after_save :expire_tokens_if_password_changedafter_save :clear_global_notice_if_needed@@ -354,6 +357,10 @@ class User < ActiveRecord::Base)end+ def should_skip_user_fields_validation?+ custom_fields_clean? || SiteSetting.disable_watched_word_checking_in_user_fields+ end+def secured_sidebar_category_ids(user_guardian = nil)user_guardian ||= guardiandiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 800406f9c7f..e2a09c53cad 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2355,6 +2355,7 @@ en:code_formatting_style: "Code button in composer will default to this code formatting style"max_allowed_message_recipients: "Maximum recipients allowed in a message."+ disable_watched_word_checking_in_user_fields: "disable watched word checking in user fields"watched_words_regular_expressions: "Watched words are regular expressions."enable_diffhtml_preview: "Experimental feature which uses diffHTML to sync preview instead of full re-render"diff --git a/config/site_settings.yml b/config/site_settings.ymlindex c115ab839fb..a91412d285c 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -1122,6 +1122,9 @@ posting:max_allowed_message_recipients:default: 30min: 1+ disable_watched_word_checking_in_user_fields:+ hidden: true+ default: falsewatched_words_regular_expressions:client: truedefault: falsediff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex 5f051a5b568..354242c722c 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -281,6 +281,11 @@ RSpec.describe User docontext "when user field is private" dobefore { user_field.update(show_on_profile: false) }+ it { is_expected.to be_valid }+ end+ context "when SiteSetting.disable_watched_word_checking_in_user_fields is true" do+ before { SiteSetting.disable_watched_word_checking_in_user_fields = true }+it { is_expected.to be_valid }endend@@ -296,6 +301,15 @@ RSpec.describe User douser.save!expect(user_field_value).to eq "■■■■■■■■ word"end++ context "when SiteSetting.disable_watched_word_checking_in_user_fields is true" do+ before { SiteSetting.disable_watched_word_checking_in_user_fields = true }++ it "does not censor the words upon saving" do+ user.save!+ expect(user_field_value).to eq "censored word"+ end+ endendcontext "when user field is private" do@@ -324,6 +338,14 @@ RSpec.describe User douser.save!expect(user_field_value).to eq "word replaced"end+ context "when SiteSetting.disable_watched_word_checking_in_user_fields is true" do+ before { SiteSetting.disable_watched_word_checking_in_user_fields = true }++ it "does not replace anything" do+ user.save!+ expect(user_field_value).to eq "word to replace"+ end+ endendcontext "when user field is private" do