Class: FeatureFlags::UpdateService

Inherits:
BaseService show all
Defined in:
app/services/feature_flags/update_service.rb

Constant Summary collapse

AUDITABLE_STRATEGY_ATTRIBUTES_HUMAN_NAMES =
{
  'scopes' => 'environment scopes',
  'parameters' => 'parameters'
}.freeze

Constants inherited from BaseService

BaseService::AUDITABLE_ATTRIBUTES

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#execute(feature_flag) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/feature_flags/update_service.rb', line 15

def execute(feature_flag)
  return error('Access Denied', 403) unless can_update?(feature_flag)
  return error('Not Found', 404) unless valid_user_list_ids?(feature_flag, user_list_ids(params))

  ApplicationRecord.transaction do
    feature_flag.assign_attributes(params)

    feature_flag.strategies.each do |strategy|
      if strategy.name_changed? && strategy.name_was == ::Operations::FeatureFlags::Strategy::STRATEGY_GITLABUSERLIST
        strategy.user_list = nil
      end
    end

    # 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_context: saved_audit_context)
    else
      error(feature_flag.errors.full_messages, :bad_request)
    end
  end
end

#success(**args) ⇒ Object



10
11
12
13
# File 'app/services/feature_flags/update_service.rb', line 10

def success(**args)
  execute_hooks_after_commit(args[:feature_flag])
  super
end