DEV: add site setting to disable watched word checking in user fields (#25411)
adding a hidden sitesetting, `disable_watched_word_checking_in_user_fields` - false by default. if set to true, you can use any word at all in user profile fields. meta: https://meta.discourse.org/t/watched-words-scope/282699/20
This commit is contained in:
parent
2457553d0a
commit
5a00d1964f
|
@ -151,7 +151,10 @@ class User < ActiveRecord::Base
|
|||
validates :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::Base
|
|||
before_save :ensure_password_is_hashed
|
||||
before_save :match_primary_group_changes
|
||||
before_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_changed
|
||||
after_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 ||= guardian
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -1122,6 +1122,9 @@ posting:
|
|||
max_allowed_message_recipients:
|
||||
default: 30
|
||||
min: 1
|
||||
disable_watched_word_checking_in_user_fields:
|
||||
hidden: true
|
||||
default: false
|
||||
watched_words_regular_expressions:
|
||||
client: true
|
||||
default: false
|
||||
|
|
|
@ -281,6 +281,11 @@ RSpec.describe User do
|
|||
context "when user field is private" do
|
||||
before { 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 }
|
||||
end
|
||||
end
|
||||
|
@ -296,6 +301,15 @@ RSpec.describe User do
|
|||
user.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
|
||||
end
|
||||
end
|
||||
|
||||
context "when user field is private" do
|
||||
|
@ -324,6 +338,14 @@ RSpec.describe User do
|
|||
user.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
|
||||
end
|
||||
end
|
||||
|
||||
context "when user field is private" do
|
||||
|
|
Loading…
Reference in New Issue