Module: DefaultBranchProtection

Extended by:
ActiveSupport::Concern
Included in:
Admin::ApplicationSettingsController, Groups::Params
Defined in:
app/controllers/concerns/default_branch_protection.rb

Instance Method Summary collapse

Instance Method Details

#normalize_default_branch_params!(form_key) ⇒ Object



6
7
8
9
10
11
12
13
14
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/controllers/concerns/default_branch_protection.rb', line 6

def normalize_default_branch_params!(form_key)
  # The entity being configured will either be the instance or the group
  entity_settings_params = params[form_key]

  if Gitlab::Utils.to_boolean(entity_settings_params[:default_branch_protected]) == false
    entity_settings_params[:default_branch_protection_defaults] =
      ::Gitlab::Access::BranchProtection.protection_none

    return entity_settings_params
  end

  return entity_settings_params unless entity_settings_params.key?(:default_branch_protection_defaults)

  entity_settings_params.delete(:default_branch_protection_level)

  entity_settings_params[:default_branch_protection_defaults][:allowed_to_push].each do |entry|
    entry[:access_level] = entry[:access_level].to_i
  end

  entity_settings_params[:default_branch_protection_defaults][:allowed_to_merge].each do |entry|
    entry[:access_level] = entry[:access_level].to_i
  end

  [:allow_force_push, :code_owner_approval_required, :developer_can_initial_push].each do |key|
    next unless entity_settings_params[:default_branch_protection_defaults].key?(key)

    entity_settings_params[:default_branch_protection_defaults][key] =
      Gitlab::Utils.to_boolean(
        entity_settings_params[:default_branch_protection_defaults][key],
        default: ::Gitlab::Access::BranchProtection.protected_fully[key])
  end
end