Commit c3896451 authored by Etienne Baqué's avatar Etienne Baqué

Refactored code in Audit::Details and added a test

parent 6c0f34bf
...@@ -27,15 +27,15 @@ module Audit ...@@ -27,15 +27,15 @@ module Audit
case action.keys.first case action.keys.first
when :add when :add
"Added #{target_type_value}#{@details[:as] ? " as #{@details[:as]}" : ''}" "Added #{target_detail_value}#{@details[:as] ? " as #{@details[:as]}" : ''}"
when :remove when :remove
"Removed #{target_type_value}" "Removed #{target_detail_value}"
when :failed_login when :failed_login
"Failed to login with #{Gitlab::Auth::OAuth::Provider.label_for(target_type_value).upcase} authentication" "Failed to login with #{oath_label} authentication"
when :custom_message when :custom_message
target_type_value detail_value
else else
text_for_change(target_type_value) text_for_change(target_detail_value)
end end
end end
...@@ -48,10 +48,16 @@ module Audit ...@@ -48,10 +48,16 @@ module Audit
changed.join(' ') changed.join(' ')
end end
def target_type_value def target_detail_value
target_type = @details[:target_type] @details[:target_type] == 'Operations::FeatureFlag' ? detail_value : detail_value.tr('_', ' ')
val = @details.values.first end
target_type == 'Operations::FeatureFlag' ? val : val.tr('_', ' ')
def detail_value
@details.values.first
end
def oath_label
Gitlab::Auth::OAuth::Provider.label_for(detail_value).upcase
end end
end end
end end
...@@ -83,6 +83,22 @@ describe Audit::Details do ...@@ -83,6 +83,22 @@ describe Audit::Details do
expect(string).to eq(custom_message) expect(string).to eq(custom_message)
end end
context 'failed_login' do
let(:feature_flag) do
{
failed_login: 'google_oauth2',
target_type: 'Operations::FeatureFlag'
}
end
let(:message) { 'Failed to login with GOOGLE authentication' }
it 'shows the correct failed login meessage' do
string = described_class.humanize(feature_flag)
expect(string).to eq message
end
end
end end
context 'deploy key' do context 'deploy key' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment