UX: Add validator for `SiteSetting#sso_overrides_email`.

This commit is contained in:
Guo Xiang Tan 2017-07-10 10:08:55 +09:00
parent f1a6449e4b
commit 2255724637
4 changed files with 96 additions and 1 deletions

View File

@ -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}"

View File

@ -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:

View File

@ -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

View File

@ -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