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 included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

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
# 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 event before the feature flag is saved as #changed_strategies_messages depends on the strategies' states before save
    audit_event = audit_event(feature_flag)

    if feature_flag.save
      success(feature_flag: feature_flag, audit_event: audit_event)
    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