-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…vements [TAN-2794] Added the ability to hide verification methods from the front end (for Oslo)
- Loading branch information
Showing
8 changed files
with
133 additions
and
14 deletions.
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
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
27 changes: 27 additions & 0 deletions
27
back/engines/commercial/verification/app/services/verification/patches/settings_service.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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Verification | ||
module Patches | ||
module SettingsService | ||
def format_for_front_end(settings, schema) | ||
settings = disable_verification_if_no_methods_enabled(settings) | ||
super | ||
end | ||
|
||
private | ||
|
||
# Ensures the FE does not show verification if: | ||
# a) There are no verification methods | ||
# b) All verification methods are flagged as 'hide_from_profile' | ||
def disable_verification_if_no_methods_enabled(settings) | ||
return settings if !settings['verification'] || settings['verification']['enabled'] == false | ||
|
||
enabled = settings['verification']['verification_methods'].present? | ||
enabled = false if settings['verification']['verification_methods']&.pluck('hide_from_profile')&.all?(true) | ||
|
||
settings['verification']['enabled'] = enabled | ||
settings | ||
end | ||
end | ||
end | ||
end |
64 changes: 64 additions & 0 deletions
64
back/engines/commercial/verification/spec/services/settings_service_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,64 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe SettingsService do | ||
let(:ss) { described_class.new } | ||
|
||
describe 'disable_verification_if_no_methods_enabled' do | ||
it 'disables verification if there are no methods enabled' do | ||
settings = { | ||
'verification' => { | ||
'allowed' => true, | ||
'enabled' => true | ||
} | ||
} | ||
|
||
updated_settings = ss.send(:disable_verification_if_no_methods_enabled, settings) | ||
expect(updated_settings['verification']['enabled']).to be false | ||
end | ||
|
||
it 'disables verification if all methods are hidden from the profile' do | ||
settings = { | ||
'verification' => { | ||
'allowed' => true, | ||
'enabled' => true, | ||
'verification_methods' => [ | ||
{ | ||
'name' => 'nemlog_in', | ||
'hide_from_profile' => true | ||
}, | ||
{ | ||
'name' => 'keycloak', | ||
'hide_from_profile' => true | ||
} | ||
] | ||
} | ||
} | ||
|
||
updated_settings = ss.send(:disable_verification_if_no_methods_enabled, settings) | ||
expect(updated_settings['verification']['enabled']).to be false | ||
end | ||
|
||
it 'does not disable verification if at least one method is NOT hidden from the profile' do | ||
settings = { | ||
'verification' => { | ||
'allowed' => true, | ||
'enabled' => true, | ||
'verification_methods' => [ | ||
{ | ||
'name' => 'nemlog_in' | ||
}, | ||
{ | ||
'name' => 'keycloak', | ||
'hide_in_profile' => true | ||
} | ||
] | ||
} | ||
} | ||
|
||
updated_settings = ss.send(:disable_verification_if_no_methods_enabled, settings) | ||
expect(updated_settings['verification']['enabled']).to be true | ||
end | ||
end | ||
end |
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