forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UX: Add validator for
SiteSetting#sso_overrides_email
.
- Loading branch information
Showing
4 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
71 changes: 71 additions & 0 deletions
71
spec/components/validators/sso_overrides_email_validator_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |