Commit a898b0a7 authored by Robert Speicher's avatar Robert Speicher

Merge branch '10321-remove-feature_flag_audit-feature-flag' into 'master'

Remove `feature_flag_audit` feature flag

Closes #10321

See merge request gitlab-org/gitlab-ee!9949
parents 90b9f50a 3c6492ea
...@@ -6,13 +6,7 @@ module FeatureFlags ...@@ -6,13 +6,7 @@ module FeatureFlags
protected protected
def audit_enabled?
Feature.enabled?(:feature_flag_audit, project, default_enabled: true)
end
def audit_event(feature_flag) def audit_event(feature_flag)
return unless audit_enabled?
message = audit_message(feature_flag) message = audit_message(feature_flag)
return if message.blank? return if message.blank?
...@@ -33,7 +27,7 @@ module FeatureFlags ...@@ -33,7 +27,7 @@ module FeatureFlags
end end
def save_audit_event(audit_event) def save_audit_event(audit_event)
return unless audit_event # feature_flag_audit is disabled or audit_message is blank return unless audit_event
audit_event.security_event audit_event.security_event
end end
......
...@@ -15,182 +15,120 @@ describe 'User creates feature flag', :js do ...@@ -15,182 +15,120 @@ describe 'User creates feature flag', :js do
end end
context 'when creates without changing scopes' do context 'when creates without changing scopes' do
shared_examples 'succesfully creates feature flag' do before do
before do visit(new_project_feature_flag_path(project))
visit(new_project_feature_flag_path(project)) set_feature_flag_info('ci_live_trace', 'For live trace')
set_feature_flag_info('ci_live_trace', 'For live trace') click_button 'Create feature flag'
click_button 'Create feature flag' expect(page).to have_current_path(project_feature_flags_path(project))
expect(page).to have_current_path(project_feature_flags_path(project)) end
end
it 'shows the created feature flag' do it 'shows the created feature flag' do
within_feature_flag_row(1) do within_feature_flag_row(1) do
expect(page.find('.feature-flag-name')).to have_content('ci_live_trace') expect(page.find('.feature-flag-name')).to have_content('ci_live_trace')
expect(page).to have_css('.js-feature-flag-status .badge-success') expect(page).to have_css('.js-feature-flag-status .badge-success')
within_feature_flag_scopes do within_feature_flag_scopes do
expect(page.find('.badge:nth-child(1)')).to have_content('*') expect(page.find('.badge:nth-child(1)')).to have_content('*')
expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active') expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active')
end
end end
end end
end end
context 'when feature flag audit enabled' do it 'records audit event' do
include_examples 'succesfully creates feature flag' visit(project_audit_events_path(project))
it 'records audit event' do
visit(project_audit_events_path(project))
expect(page).to have_text("Created feature flag ci live trace with description \"For live trace\".") expect(page).to have_text("Created feature flag ci live trace with description \"For live trace\".")
end
end
context 'when feature flag audit is disabled' do
before do
stub_feature_flags(feature_flag_audit: false)
end
include_examples 'succesfully creates feature flag'
it 'does not record audit event' do
visit(project_audit_events_path(project))
expect(page).to have_no_text("Created feature flag")
end
end end
end end
context 'when creates with disabling the default scope' do context 'when creates with disabling the default scope' do
shared_examples 'succesfully creates feature flag' do before do
before do visit(new_project_feature_flag_path(project))
visit(new_project_feature_flag_path(project)) set_feature_flag_info('ci_live_trace', 'For live trace')
set_feature_flag_info('ci_live_trace', 'For live trace')
within_scope_row(1) do
within_status { find('.project-feature-toggle').click }
end
click_button 'Create feature flag' within_scope_row(1) do
within_status { find('.project-feature-toggle').click }
end end
it 'shows the created feature flag' do click_button 'Create feature flag'
within_feature_flag_row(1) do
expect(page.find('.feature-flag-name')).to have_content('ci_live_trace')
expect(page).to have_css('.js-feature-flag-status .badge-danger')
within_feature_flag_scopes do
expect(page.find('.badge:nth-child(1)')).to have_content('*')
expect(page.find('.badge:nth-child(1)')['class']).to include('badge-inactive')
end
end
end
end end
context 'when feature flag audit enabled' do it 'shows the created feature flag' do
include_examples 'succesfully creates feature flag' within_feature_flag_row(1) do
end expect(page.find('.feature-flag-name')).to have_content('ci_live_trace')
expect(page).to have_css('.js-feature-flag-status .badge-danger')
context 'when feature flag audit is disabled' do within_feature_flag_scopes do
before do expect(page.find('.badge:nth-child(1)')).to have_content('*')
stub_feature_flags(feature_flag_audit: false) expect(page.find('.badge:nth-child(1)')['class']).to include('badge-inactive')
end
end end
include_examples 'succesfully creates feature flag'
end end
end end
context 'when creates with an additional scope' do context 'when creates with an additional scope' do
shared_examples 'succesfully creates feature flag' do before do
before do visit(new_project_feature_flag_path(project))
visit(new_project_feature_flag_path(project)) set_feature_flag_info('mr_train', '')
set_feature_flag_info('mr_train', '')
within_scope_row(2) do
within_scope_row(2) do within_environment_spec do
within_environment_spec do find('.js-env-input').set("review/*")
find('.js-env-input').set("review/*") find('.js-create-button').click
find('.js-create-button').click
end
end
within_scope_row(2) do
within_status { find('.project-feature-toggle').click }
end end
click_button 'Create feature flag'
end end
it 'shows the created feature flag' do within_scope_row(2) do
within_feature_flag_row(1) do within_status { find('.project-feature-toggle').click }
expect(page.find('.feature-flag-name')).to have_content('mr_train')
expect(page).to have_css('.js-feature-flag-status .badge-success')
within_feature_flag_scopes do
expect(page.find('.badge:nth-child(1)')).to have_content('*')
expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active')
expect(page.find('.badge:nth-child(2)')).to have_content('review/*')
expect(page.find('.badge:nth-child(2)')['class']).to include('badge-active')
end
end
end end
end
context 'when feature flag audit enabled' do click_button 'Create feature flag'
include_examples 'succesfully creates feature flag'
end end
context 'when feature flag audit is disabled' do it 'shows the created feature flag' do
before do within_feature_flag_row(1) do
stub_feature_flags(feature_flag_audit: false) expect(page.find('.feature-flag-name')).to have_content('mr_train')
end expect(page).to have_css('.js-feature-flag-status .badge-success')
include_examples 'succesfully creates feature flag' within_feature_flag_scopes do
expect(page.find('.badge:nth-child(1)')).to have_content('*')
expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active')
expect(page.find('.badge:nth-child(2)')).to have_content('review/*')
expect(page.find('.badge:nth-child(2)')['class']).to include('badge-active')
end
end
end end
end end
context 'when searches an environment name for scope creation' do context 'when searches an environment name for scope creation' do
let!(:environment) { create(:environment, name: 'production', project: project) } let!(:environment) { create(:environment, name: 'production', project: project) }
shared_examples 'succesfully creates feature flag' do before do
before do visit(new_project_feature_flag_path(project))
visit(new_project_feature_flag_path(project)) set_feature_flag_info('mr_train', '')
set_feature_flag_info('mr_train', '')
within_scope_row(2) do within_scope_row(2) do
within_environment_spec do within_environment_spec do
find('.js-env-input').set('prod') find('.js-env-input').set('prod')
click_button 'production' click_button 'production'
end
end end
click_button 'Create feature flag'
end end
it 'shows the created feature flag' do click_button 'Create feature flag'
within_feature_flag_row(1) do
expect(page.find('.feature-flag-name')).to have_content('mr_train')
expect(page).to have_css('.js-feature-flag-status .badge-success')
within_feature_flag_scopes do
expect(page.find('.badge:nth-child(1)')).to have_content('*')
expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active')
expect(page.find('.badge:nth-child(2)')).to have_content('production')
expect(page.find('.badge:nth-child(2)')['class']).to include('badge-inactive')
end
end
end
end end
context 'when feature flag audit enabled' do it 'shows the created feature flag' do
include_examples 'succesfully creates feature flag' within_feature_flag_row(1) do
end expect(page.find('.feature-flag-name')).to have_content('mr_train')
expect(page).to have_css('.js-feature-flag-status .badge-success')
context 'when feature flag audit is disabled' do within_feature_flag_scopes do
before do expect(page.find('.badge:nth-child(1)')).to have_content('*')
stub_feature_flags(feature_flag_audit: false) expect(page.find('.badge:nth-child(1)')['class']).to include('badge-active')
expect(page.find('.badge:nth-child(2)')).to have_content('production')
expect(page.find('.badge:nth-child(2)')['class']).to include('badge-inactive')
end
end end
include_examples 'succesfully creates feature flag'
end end
end end
......
...@@ -37,154 +37,94 @@ describe 'User updates feature flag', :js do ...@@ -37,154 +37,94 @@ describe 'User updates feature flag', :js do
end end
context 'when user updates a status of a scope' do context 'when user updates a status of a scope' do
shared_examples 'succesfully updates feature flag' do before do
before do within_scope_row(2) do
within_scope_row(2) do within_status { find('.project-feature-toggle').click }
within_status { find('.project-feature-toggle').click }
end
click_button 'Save changes'
expect(page).to have_current_path(project_feature_flags_path(project))
end end
it 'shows the updated feature flag' do click_button 'Save changes'
within_feature_flag_row(1) do expect(page).to have_current_path(project_feature_flags_path(project))
expect(page.find('.feature-flag-name')).to have_content('ci_live_trace')
expect(page).to have_css('.js-feature-flag-status .badge-danger')
within_feature_flag_scopes do
expect(page.find('.badge:nth-child(1)')).to have_content('*')
expect(page.find('.badge:nth-child(1)')['class']).to include('badge-inactive')
expect(page.find('.badge:nth-child(2)')).to have_content('review/*')
expect(page.find('.badge:nth-child(2)')['class']).to include('badge-inactive')
end
end
end
end end
context 'when feature flag audit enabled' do it 'shows the updated feature flag' do
include_examples 'succesfully updates feature flag' within_feature_flag_row(1) do
expect(page.find('.feature-flag-name')).to have_content('ci_live_trace')
expect(page).to have_css('.js-feature-flag-status .badge-danger')
it 'records audit event' do within_feature_flag_scopes do
visit(project_audit_events_path(project)) expect(page.find('.badge:nth-child(1)')).to have_content('*')
expect(page.find('.badge:nth-child(1)')['class']).to include('badge-inactive')
expect(page).to( expect(page.find('.badge:nth-child(2)')).to have_content('review/*')
have_text("Updated feature flag ci live trace. Updated rule review/* active state from true to false.") expect(page.find('.badge:nth-child(2)')['class']).to include('badge-inactive')
) end
end end
end end
context 'when feature flag audit is disabled' do it 'records audit event' do
before do visit(project_audit_events_path(project))
stub_feature_flags(feature_flag_audit: false)
end
include_examples 'succesfully updates feature flag'
it 'does not record audit event' do expect(page).to(
visit(project_audit_events_path(project)) have_text("Updated feature flag ci live trace. Updated rule review/* active state from true to false.")
)
expect(page).to have_no_text("Updated feature flag")
end
end end
end end
context 'when user adds a new scope' do context 'when user adds a new scope' do
shared_examples 'succesfully updates feature flag' do before do
before do within_scope_row(3) do
within_scope_row(3) do within_environment_spec do
within_environment_spec do find('.js-env-input').set('production')
find('.js-env-input').set('production') find('.js-create-button').click
find('.js-create-button').click
end
end end
click_button 'Save changes'
expect(page).to have_current_path(project_feature_flags_path(project))
end end
it 'shows the newly created scope' do click_button 'Save changes'
within_feature_flag_row(1) do expect(page).to have_current_path(project_feature_flags_path(project))
within_feature_flag_scopes do
expect(page.find('.badge:nth-child(3)')).to have_content('production')
expect(page.find('.badge:nth-child(3)')['class']).to include('badge-inactive')
end
end
end
end end
context 'when feature flag audit enabled' do it 'shows the newly created scope' do
include_examples 'succesfully updates feature flag' within_feature_flag_row(1) do
within_feature_flag_scopes do
it 'records audit event' do expect(page.find('.badge:nth-child(3)')).to have_content('production')
visit(project_audit_events_path(project)) expect(page.find('.badge:nth-child(3)')['class']).to include('badge-inactive')
end
expect(page).to(
have_text("Updated feature flag ci live trace")
)
end end
end end
context 'when feature flag audit is disabled' do it 'records audit event' do
before do visit(project_audit_events_path(project))
stub_feature_flags(feature_flag_audit: false)
end
include_examples 'succesfully updates feature flag'
it 'does not record audit event' do expect(page).to(
visit(project_audit_events_path(project)) have_text("Updated feature flag ci live trace")
)
expect(page).to have_no_text("Updated feature flag")
end
end end
end end
context 'when user deletes a scope' do context 'when user deletes a scope' do
shared_examples 'succesfully updates feature flag' do before do
before do within_scope_row(2) do
within_scope_row(2) do within_delete { find('.js-delete-scope').click }
within_delete { find('.js-delete-scope').click }
end
click_button 'Save changes'
expect(page).to have_current_path(project_feature_flags_path(project))
end end
it 'shows the updated feature flag' do click_button 'Save changes'
within_feature_flag_row(1) do expect(page).to have_current_path(project_feature_flags_path(project))
within_feature_flag_scopes do
expect(page).to have_css('.badge:nth-child(1)')
expect(page).not_to have_css('.badge:nth-child(2)')
end
end
end
end end
context 'when feature flag audit enabled' do it 'shows the updated feature flag' do
include_examples 'succesfully updates feature flag' within_feature_flag_row(1) do
within_feature_flag_scopes do
it 'records audit event' do expect(page).to have_css('.badge:nth-child(1)')
visit(project_audit_events_path(project)) expect(page).not_to have_css('.badge:nth-child(2)')
end
expect(page).to(
have_text("Updated feature flag ci live trace")
)
end end
end end
context 'when feature flag audit is disabled' do it 'records audit event' do
before do visit(project_audit_events_path(project))
stub_feature_flags(feature_flag_audit: false)
end
include_examples 'succesfully updates feature flag' expect(page).to(
have_text("Updated feature flag ci live trace")
it 'does not record audit event' do )
visit(project_audit_events_path(project))
expect(page).to have_no_text("Updated feature flag")
end
end end
end end
end end
...@@ -55,22 +55,6 @@ describe FeatureFlags::CreateService do ...@@ -55,22 +55,6 @@ describe FeatureFlags::CreateService do
expect { subject }.to change { AuditEvent.count }.by(1) expect { subject }.to change { AuditEvent.count }.by(1)
expect(AuditEvent.last.present.action).to eq(expected_message) expect(AuditEvent.last.present.action).to eq(expected_message)
end end
context 'when feature flag audit is disabled' do
before do
stub_feature_flags(feature_flag_audit: false)
end
it { expect(subject[:status]).to eq(:success) }
it 'creates feature flag' do
expect { subject }.to change { Operations::FeatureFlag.count }.by(1)
end
it 'does not create audit log' do
expect { subject }.not_to change { AuditEvent.count }
end
end
end end
end end
end end
...@@ -24,20 +24,6 @@ describe FeatureFlags::DestroyService do ...@@ -24,20 +24,6 @@ describe FeatureFlags::DestroyService do
expect(audit_event_message).to eq("Deleted feature flag <strong>#{feature_flag.name.tr('_', ' ')}</strong>.") expect(audit_event_message).to eq("Deleted feature flag <strong>#{feature_flag.name.tr('_', ' ')}</strong>.")
end end
context 'when feature flag audit is disabled' do
before do
stub_feature_flags(feature_flag_audit: false)
end
it 'works successfully' do
expect(subject[:status]).to eq(:success)
end
it 'does not create audit event' do
expect { subject }.not_to change { AuditEvent.count }
end
end
context 'when feature flag can not be destroyed' do context 'when feature flag can not be destroyed' do
before do before do
allow(feature_flag).to receive(:destroy).and_return(false) allow(feature_flag).to receive(:destroy).and_return(false)
......
...@@ -29,24 +29,6 @@ describe FeatureFlags::UpdateService do ...@@ -29,24 +29,6 @@ describe FeatureFlags::UpdateService do
) )
end end
shared_examples 'disabled feature flag audit' do
context 'when feature flag audit is disabled' do
before do
stub_feature_flags(feature_flag_audit: false)
end
it 'returns success status' do
expect(subject[:status]).to eq(:success)
end
it 'does not create audit event' do
expect { subject }.not_to change { AuditEvent.count }
end
end
end
include_examples 'disabled feature flag audit'
context 'with invalid params' do context 'with invalid params' do
let(:params) { { name: nil } } let(:params) { { name: nil } }
...@@ -85,8 +67,6 @@ describe FeatureFlags::UpdateService do ...@@ -85,8 +67,6 @@ describe FeatureFlags::UpdateService do
" to <strong>\"new description\"</strong>.") " to <strong>\"new description\"</strong>.")
) )
end end
include_examples 'disabled feature flag audit'
end end
context 'when active state is changed' do context 'when active state is changed' do
...@@ -103,8 +83,6 @@ describe FeatureFlags::UpdateService do ...@@ -103,8 +83,6 @@ describe FeatureFlags::UpdateService do
"from <strong>true</strong> to <strong>false</strong>.") "from <strong>true</strong> to <strong>false</strong>.")
) )
end end
include_examples 'disabled feature flag audit'
end end
context 'when scope is renamed' do context 'when scope is renamed' do
...@@ -123,8 +101,6 @@ describe FeatureFlags::UpdateService do ...@@ -123,8 +101,6 @@ describe FeatureFlags::UpdateService do
) )
end end
include_examples 'disabled feature flag audit'
context 'when scope can not be updated' do context 'when scope can not be updated' do
let(:params) do let(:params) do
{ {
...@@ -159,8 +135,6 @@ describe FeatureFlags::UpdateService do ...@@ -159,8 +135,6 @@ describe FeatureFlags::UpdateService do
expect(audit_event_message).to include("Deleted rule <strong>review</strong>.") expect(audit_event_message).to include("Deleted rule <strong>review</strong>.")
end end
include_examples 'disabled feature flag audit'
context 'when scope can not be deleted' do context 'when scope can not be deleted' do
RSpec::Matchers.define_negated_matcher :not_change, :change RSpec::Matchers.define_negated_matcher :not_change, :change
...@@ -191,8 +165,6 @@ describe FeatureFlags::UpdateService do ...@@ -191,8 +165,6 @@ describe FeatureFlags::UpdateService do
) )
end end
include_examples 'disabled feature flag audit'
context 'when scope can not be created' do context 'when scope can not be created' do
let(:new_environment_scope) { '' } let(:new_environment_scope) { '' }
......
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