summaryrefslogtreecommitdiff
path: root/app/services/feature_flags
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-09-02 06:09:10 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-02 06:09:10 +0000
commit951a32fcf3fc8766eae1430a389b77049410c371 (patch)
tree284b8298b4de14dc2f31b9ef2cdfe3d90ace7296 /app/services/feature_flags
parentceb0c326ae57bac76fe40ca3471b0ee5d152f58e (diff)
downloadgitlab-ce-951a32fcf3fc8766eae1430a389b77049410c371.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/feature_flags')
-rw-r--r--app/services/feature_flags/base_service.rb10
-rw-r--r--app/services/feature_flags/create_service.rb4
-rw-r--r--app/services/feature_flags/update_service.rb38
3 files changed, 27 insertions, 25 deletions
diff --git a/app/services/feature_flags/base_service.rb b/app/services/feature_flags/base_service.rb
index d041703803b..f1d19ff469d 100644
--- a/app/services/feature_flags/base_service.rb
+++ b/app/services/feature_flags/base_service.rb
@@ -48,10 +48,12 @@ module FeatureFlags
end
end
- def created_scope_message(scope)
- "Created rule #{scope.environment_scope} "\
- "and set it as #{scope.active ? "active" : "inactive"} "\
- "with strategies #{scope.strategies}."
+ def created_strategy_message(strategy)
+ scopes = strategy.scopes
+ .map { |scope| %Q("#{scope.environment_scope}") }
+ .join(', ')
+ %Q(Created strategy \"#{strategy.name}\" )\
+ "with scopes #{scopes}."
end
def feature_flag_by_name
diff --git a/app/services/feature_flags/create_service.rb b/app/services/feature_flags/create_service.rb
index 5111f914447..65f8f8e33f6 100644
--- a/app/services/feature_flags/create_service.rb
+++ b/app/services/feature_flags/create_service.rb
@@ -24,8 +24,8 @@ module FeatureFlags
def audit_message(feature_flag)
message_parts = ["Created feature flag #{feature_flag.name} with description \"#{feature_flag.description}\"."]
- message_parts += feature_flag.scopes.map do |scope|
- created_scope_message(scope)
+ message_parts += feature_flag.strategies.map do |strategy|
+ created_strategy_message(strategy)
end
message_parts.join(" ")
diff --git a/app/services/feature_flags/update_service.rb b/app/services/feature_flags/update_service.rb
index 01e4f661d75..ccfd1b57d44 100644
--- a/app/services/feature_flags/update_service.rb
+++ b/app/services/feature_flags/update_service.rb
@@ -2,10 +2,9 @@
module FeatureFlags
class UpdateService < FeatureFlags::BaseService
- AUDITABLE_SCOPE_ATTRIBUTES_HUMAN_NAMES = {
- 'active' => 'active state',
- 'environment_scope' => 'environment scope',
- 'strategies' => 'strategies'
+ AUDITABLE_STRATEGY_ATTRIBUTES_HUMAN_NAMES = {
+ 'scopes' => 'environment scopes',
+ 'parameters' => 'parameters'
}.freeze
def execute(feature_flag)
@@ -41,7 +40,7 @@ module FeatureFlags
def audit_message(feature_flag)
changes = changed_attributes_messages(feature_flag)
- changes += changed_scopes_messages(feature_flag)
+ changes += changed_strategies_messages(feature_flag)
return if changes.empty?
@@ -56,29 +55,30 @@ module FeatureFlags
end
end
- def changed_scopes_messages(feature_flag)
- feature_flag.scopes.map do |scope|
- if scope.new_record?
- created_scope_message(scope)
- elsif scope.marked_for_destruction?
- deleted_scope_message(scope)
+ def changed_strategies_messages(feature_flag)
+ feature_flag.strategies.map do |strategy|
+ if strategy.new_record?
+ created_strategy_message(strategy)
+ elsif strategy.marked_for_destruction?
+ deleted_strategy_message(strategy)
else
- updated_scope_message(scope)
+ updated_strategy_message(strategy)
end
- end.compact # updated_scope_message can return nil if nothing has been changed
+ end.compact # updated_strategy_message can return nil if nothing has been changed
end
- def deleted_scope_message(scope)
- "Deleted rule #{scope.environment_scope}."
+ def deleted_strategy_message(strategy)
+ scopes = strategy.scopes.map { |scope| scope.environment_scope }.join(', ')
+ "Deleted strategy #{strategy.name} with environment scopes #{scopes}."
end
- def updated_scope_message(scope)
- changes = scope.changes.slice(*AUDITABLE_SCOPE_ATTRIBUTES_HUMAN_NAMES.keys)
+ def updated_strategy_message(strategy)
+ changes = strategy.changes.slice(*AUDITABLE_STRATEGY_ATTRIBUTES_HUMAN_NAMES.keys)
return if changes.empty?
- message = "Updated rule #{scope.environment_scope} "
+ message = "Updated strategy #{strategy.name} "
message += changes.map do |attribute_name, change|
- name = AUDITABLE_SCOPE_ATTRIBUTES_HUMAN_NAMES[attribute_name]
+ name = AUDITABLE_STRATEGY_ATTRIBUTES_HUMAN_NAMES[attribute_name]
"#{name} from #{change.first} to #{change.second}"
end.join(' ')