2021-01-03 14:25:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module FeatureFlags
|
|
|
|
class BaseService < ::BaseService
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
AUDITABLE_ATTRIBUTES = %w(name description active).freeze
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
def success(**args)
|
|
|
|
sync_to_jira(args[:feature_flag])
|
2023-05-27 22:25:52 +05:30
|
|
|
|
|
|
|
audit_event(args[:feature_flag], args[:audit_context])
|
2021-03-08 18:12:59 +05:30
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
protected
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def audit_event(feature_flag, context = nil)
|
|
|
|
context ||= audit_context(feature_flag)
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
return if context[:message].blank?
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
::Gitlab::Audit::Auditor.audit(context)
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def update_last_feature_flag_updated_at!
|
|
|
|
Operations::FeatureFlagsClient.update_last_feature_flag_updated_at!(project)
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
def sync_to_jira(feature_flag)
|
|
|
|
return unless feature_flag.present?
|
2022-01-26 12:08:38 +05:30
|
|
|
return unless project.jira_subscription_exists?
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
seq_id = ::Atlassian::JiraConnect::Client.generate_update_sequence_id
|
|
|
|
feature_flag.run_after_commit do
|
|
|
|
::JiraConnect::SyncFeatureFlagsWorker.perform_async(feature_flag.id, seq_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
def created_strategy_message(strategy)
|
|
|
|
scopes = strategy.scopes
|
|
|
|
.map { |scope| %Q("#{scope.environment_scope}") }
|
|
|
|
.join(', ')
|
|
|
|
%Q(Created strategy "#{strategy.name}" with scopes #{scopes}.)
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def feature_flag_by_name
|
|
|
|
strong_memoize(:feature_flag_by_name) do
|
|
|
|
project.operations_feature_flags.find_by_name(params[:name])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def feature_flag_scope_by_environment_scope
|
|
|
|
strong_memoize(:feature_flag_scope_by_environment_scope) do
|
|
|
|
feature_flag_by_name.scopes.find_by_environment_scope(params[:environment_scope])
|
|
|
|
end
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def audit_message(feature_flag)
|
|
|
|
raise NotImplementedError, "This method should be overriden by subclasses"
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|