diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-14 06:08:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-14 06:08:22 +0300 |
commit | 32380631045bf0c30c6ae6952a4a62e3e5436b82 (patch) | |
tree | 2096d5db0d3f77a12469f38f5ba33861c1973ddc /app/services/feature_flags | |
parent | 6031d32432ca35a9adca80698139982f3ef66cc6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/feature_flags')
-rw-r--r-- | app/services/feature_flags/base_service.rb | 34 | ||||
-rw-r--r-- | app/services/feature_flags/create_service.rb | 10 | ||||
-rw-r--r-- | app/services/feature_flags/destroy_service.rb | 10 | ||||
-rw-r--r-- | app/services/feature_flags/update_service.rb | 16 |
4 files changed, 41 insertions, 29 deletions
diff --git a/app/services/feature_flags/base_service.rb b/app/services/feature_flags/base_service.rb index 59db1a5f12f..028906a0b43 100644 --- a/app/services/feature_flags/base_service.rb +++ b/app/services/feature_flags/base_service.rb @@ -7,42 +7,24 @@ module FeatureFlags AUDITABLE_ATTRIBUTES = %w(name description active).freeze def success(**args) - audit_event = args.fetch(:audit_event) { audit_event(args[:feature_flag]) } - save_audit_event(audit_event) sync_to_jira(args[:feature_flag]) + + audit_event(args[:feature_flag], args[:audit_context]) super end protected - def update_last_feature_flag_updated_at! - Operations::FeatureFlagsClient.update_last_feature_flag_updated_at!(project) - end - - def audit_event(feature_flag) - message = audit_message(feature_flag) + def audit_event(feature_flag, context = nil) + context ||= audit_context(feature_flag) - return if message.blank? + return if context[:message].blank? - details = - { - custom_message: message, - target_id: feature_flag.id, - target_type: feature_flag.class.name, - target_details: feature_flag.name - } - - ::AuditEventService.new( - current_user, - feature_flag.project, - details - ) + ::Gitlab::Audit::Auditor.audit(context) end - def save_audit_event(audit_event) - return unless audit_event - - audit_event.security_event + def update_last_feature_flag_updated_at! + Operations::FeatureFlagsClient.update_last_feature_flag_updated_at!(project) end def sync_to_jira(feature_flag) diff --git a/app/services/feature_flags/create_service.rb b/app/services/feature_flags/create_service.rb index 6ea40345191..2a3153e6a54 100644 --- a/app/services/feature_flags/create_service.rb +++ b/app/services/feature_flags/create_service.rb @@ -21,6 +21,16 @@ module FeatureFlags private + def audit_context(feature_flag) + { + name: 'feature_flag_created', + message: audit_message(feature_flag), + author: current_user, + scope: feature_flag.project, + target: feature_flag + } + end + def audit_message(feature_flag) message_parts = ["Created feature flag #{feature_flag.name} with description \"#{feature_flag.description}\"."] diff --git a/app/services/feature_flags/destroy_service.rb b/app/services/feature_flags/destroy_service.rb index 0fdc890b8a3..fdcbb802b16 100644 --- a/app/services/feature_flags/destroy_service.rb +++ b/app/services/feature_flags/destroy_service.rb @@ -22,6 +22,16 @@ module FeatureFlags end end + def audit_context(feature_flag) + { + name: 'feature_flag_deleted', + message: audit_message(feature_flag), + author: current_user, + scope: feature_flag.project, + target: feature_flag + } + end + def audit_message(feature_flag) "Deleted feature flag #{feature_flag.name}." end diff --git a/app/services/feature_flags/update_service.rb b/app/services/feature_flags/update_service.rb index a465ca1dd5f..555b5a93d23 100644 --- a/app/services/feature_flags/update_service.rb +++ b/app/services/feature_flags/update_service.rb @@ -25,13 +25,13 @@ module FeatureFlags end end - # We generate the audit event before the feature flag is saved as #changed_strategies_messages depends on the strategies' states before save - audit_event = audit_event(feature_flag) + # We generate the audit context before the feature flag is saved as #changed_strategies_messages depends on the strategies' states before save + saved_audit_context = audit_context feature_flag if feature_flag.save update_last_feature_flag_updated_at! - success(feature_flag: feature_flag, audit_event: audit_event) + success(feature_flag: feature_flag, audit_context: saved_audit_context) else error(feature_flag.errors.full_messages, :bad_request) end @@ -50,6 +50,16 @@ module FeatureFlags end end + def audit_context(feature_flag) + { + name: 'feature_flag_updated', + message: audit_message(feature_flag), + author: current_user, + scope: feature_flag.project, + target: feature_flag + } + end + def audit_message(feature_flag) changes = changed_attributes_messages(feature_flag) changes += changed_strategies_messages(feature_flag) |