Commit d58c9932 authored by Jason Goodman's avatar Jason Goodman Committed by Bob Van Landuyt

Create an audit event for feature flag scope strategy changes

Create a simple audit message with the raw strategy json
parent 93281427
...@@ -34,7 +34,8 @@ module FeatureFlags ...@@ -34,7 +34,8 @@ module FeatureFlags
def created_scope_message(scope) def created_scope_message(scope)
"Created rule <strong>#{scope.environment_scope}</strong> "\ "Created rule <strong>#{scope.environment_scope}</strong> "\
"and set it as <strong>#{scope.active ? "active" : "inactive"}</strong>." "and set it as <strong>#{scope.active ? "active" : "inactive"}</strong> "\
"with strategies <strong>#{scope.strategies}</strong>."
end end
end end
end end
...@@ -4,7 +4,8 @@ module FeatureFlags ...@@ -4,7 +4,8 @@ module FeatureFlags
class UpdateService < FeatureFlags::BaseService class UpdateService < FeatureFlags::BaseService
AUDITABLE_SCOPE_ATTRIBUTES_HUMAN_NAMES = { AUDITABLE_SCOPE_ATTRIBUTES_HUMAN_NAMES = {
'active' => 'active state', 'active' => 'active state',
'environment_scope' => 'environment scope' 'environment_scope' => 'environment scope',
'strategies' => 'strategies'
}.freeze }.freeze
def execute(feature_flag) def execute(feature_flag)
......
---
title: Audit strategies for feature flag scopes
merge_request: 14652
author:
type: added
...@@ -47,10 +47,12 @@ describe FeatureFlags::CreateService do ...@@ -47,10 +47,12 @@ describe FeatureFlags::CreateService do
end end
it 'creates audit event' do it 'creates audit event' do
expected_message = "Created feature flag <strong>feature_flag</strong> "\ expected_message = 'Created feature flag <strong>feature_flag</strong> '\
"with description <strong>\"description\"</strong>. "\ 'with description <strong>"description"</strong>. '\
"Created rule <strong>*</strong> and set it as <strong>active</strong>. "\ 'Created rule <strong>*</strong> and set it as <strong>active</strong> '\
"Created rule <strong>production</strong> and set it as <strong>inactive</strong>." 'with strategies <strong>[{"name"=>"default", "parameters"=>{}}]</strong>. '\
'Created rule <strong>production</strong> and set it as <strong>inactive</strong> '\
'with strategies <strong>[{"name"=>"default", "parameters"=>{}}]</strong>.'
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)
......
...@@ -159,10 +159,12 @@ describe FeatureFlags::UpdateService do ...@@ -159,10 +159,12 @@ describe FeatureFlags::UpdateService do
end end
it 'creates audit event with new scope' do it 'creates audit event with new scope' do
expected = 'Created rule <strong>review</strong> and set it as <strong>active</strong> '\
'with strategies <strong>[{"name"=>"default", "parameters"=>{}}]</strong>.'
subject subject
expect(audit_event_message).to(
include("Created rule <strong>review</strong> and set it as <strong>active</strong>.") expect(audit_event_message).to include(expected)
)
end end
context 'when scope can not be created' do context 'when scope can not be created' do
...@@ -181,5 +183,37 @@ describe FeatureFlags::UpdateService do ...@@ -181,5 +183,37 @@ describe FeatureFlags::UpdateService do
end end
end end
end end
context 'when the strategy is changed' do
let(:scope) do
create(:operations_feature_flag_scope,
feature_flag: feature_flag,
environment_scope: 'sandbox',
strategies: [{ name: "default", parameters: {} }])
end
let(:params) do
{
scopes_attributes: [{
id: scope.id,
environment_scope: 'sandbox',
strategies: [{
name: 'gradualRolloutUserId',
parameters: {
groupId: 'mygroup',
percentage: "40"
}
}]
}]
}
end
it 'creates an audit event' do
expected = %r{Updated rule <strong>sandbox</strong> strategies from <strong>.*</strong> to <strong>.*</strong>.}
expect { subject }.to change { AuditEvent.count }.by(1)
expect(audit_event_message).to match(expected)
end
end
end end
end end
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