diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index a3a2563be4d..ca5914b74ee 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1580,6 +1580,8 @@ en: email_polling_disabled: "You must enable either manual or POP3 polling before enabling reply by email." user_locale_not_enabled: "You must first enable 'allow user locale' before enabling this setting." invalid_regex: "Regex is invalid or not allowed." + email_editable_enabled: "You must disable 'email editable' before enabling this setting." + enable_sso_disabled: "You must first enable 'enable sso' before enabling this setting." search: within_post: "#%{post_number} by %{username}" diff --git a/config/site_settings.yml b/config/site_settings.yml index cb26851e779..fd487d97a6f 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -304,7 +304,9 @@ login: regex: '^https?:\/\/.+[^\/]$' sso_secret: '' sso_overrides_bio: false - sso_overrides_email: false + sso_overrides_email: + default: false + validator: "SsoOverridesEmailValidator" sso_overrides_username: false sso_overrides_name: false sso_overrides_avatar: diff --git a/lib/validators/sso_overrides_email_validator.rb b/lib/validators/sso_overrides_email_validator.rb new file mode 100644 index 00000000000..4af0149b5f6 --- /dev/null +++ b/lib/validators/sso_overrides_email_validator.rb @@ -0,0 +1,20 @@ +class SsoOverridesEmailValidator + def initialize(opts={}) + @opts = opts + end + + def valid_value?(val) + return true if val == 'f' + return false if !SiteSetting.enable_sso? + return false if SiteSetting.email_editable? + true + end + + def error_message + if !SiteSetting.enable_sso? + I18n.t('site_settings.errors.enable_sso_disabled') + elsif SiteSetting.email_editable? + I18n.t('site_settings.errors.email_editable_enabled') + end + end +end diff --git a/spec/components/validators/sso_overrides_email_validator_spec.rb b/spec/components/validators/sso_overrides_email_validator_spec.rb new file mode 100644 index 00000000000..4efd91a1008 --- /dev/null +++ b/spec/components/validators/sso_overrides_email_validator_spec.rb @@ -0,0 +1,71 @@ +require 'rails_helper' + +RSpec.describe SsoOverridesEmailValidator do + subject { described_class.new } + + describe '#valid_value?' do + describe "when 'email editable' is true" do + before do + SiteSetting.enable_sso = true + SiteSetting.email_editable = true + end + + describe 'when val is false' do + it 'should be valid' do + expect(subject.valid_value?('f')).to eq(true) + end + end + + describe 'when value is true' do + it 'should not be valid' do + expect(subject.valid_value?('t')).to eq(false) + + expect(subject.error_message).to eq(I18n.t( + 'site_settings.errors.email_editable_enabled' + )) + end + end + end + + describe "when 'email editable' is false" do + before do + SiteSetting.enable_sso = true + SiteSetting.email_editable = false + end + + describe 'when value is false' do + it 'should be valid' do + expect(subject.valid_value?('f')).to eq(true) + end + end + + describe 'when value is true' do + it 'should be valid' do + expect(subject.valid_value?('t')).to eq(true) + end + end + end + + describe "when 'enable sso' is false" do + before do + SiteSetting.enable_sso = false + end + + describe 'when value is false' do + it 'should be valid' do + expect(subject.valid_value?('f')).to eq(true) + end + end + + describe 'when value is true' do + it 'should not be valid' do + expect(subject.valid_value?('t')).to eq(false) + + expect(subject.error_message).to eq(I18n.t( + 'site_settings.errors.enable_sso_disabled' + )) + end + end + end + end +end