BigW Consortium Gitlab

application_settings_helper.rb 3.06 KB
Newer Older
1
module ApplicationSettingsHelper
Douwe Maan committed
2 3 4 5 6 7
  delegate  :gravatar_enabled?,
            :signup_enabled?,
            :signin_enabled?,
            :akismet_enabled?,
            :koding_enabled?,
            to: :current_application_settings
8

9 10 11 12
  def user_oauth_applications?
    current_application_settings.user_oauth_applications
  end

13
  def allowed_protocols_present?
14
    current_application_settings.enabled_git_access_protocol.present?
15 16 17
  end

  def enabled_protocol
18
    case current_application_settings.enabled_git_access_protocol
19 20 21 22 23 24 25
    when 'http'
      gitlab_config.protocol
    when 'ssh'
      'ssh'
    end
  end

26
  def enabled_project_button(project, protocol)
27 28
    case protocol
    when 'ssh'
29
      ssh_clone_button(project, 'bottom', append_link: false)
30
    else
31
      http_clone_button(project, 'bottom', append_link: false)
32 33 34
    end
  end

35 36 37 38 39
  # Return a group of checkboxes that use Bootstrap's button plugin for a
  # toggle button effect.
  def restricted_level_checkboxes(help_block_id)
    Gitlab::VisibilityLevel.options.map do |name, level|
      checked = restricted_visibility_levels(true).include?(level)
40 41
      css_class = checked ? 'active' : ''
      checkbox_name = "application_setting[restricted_visibility_levels][]"
42

43
      label_tag(name, class: css_class) do
44 45
        check_box_tag(checkbox_name, level, checked,
                      autocomplete: 'off',
46 47
                      'aria-describedby' => help_block_id,
                      id: name) + visibility_level_icon(level) + name
48 49 50
      end
    end
  end
51 52 53 54 55 56

  # Return a group of checkboxes that use Bootstrap's button plugin for a
  # toggle button effect.
  def import_sources_checkboxes(help_block_id)
    Gitlab::ImportSources.options.map do |name, source|
      checked = current_application_settings.import_sources.include?(source)
57
      css_class = checked ? 'active' : ''
58 59
      checkbox_name = 'application_setting[import_sources][]'

60
      label_tag(name, class: css_class) do
61 62
        check_box_tag(checkbox_name, source, checked,
                      autocomplete: 'off',
63 64
                      'aria-describedby' => help_block_id,
                      id: name.tr(' ', '_')) + name
65 66 67
      end
    end
  end
68

69
  def oauth_providers_checkboxes
70
    button_based_providers.map do |source|
71
      disabled = current_application_settings.disabled_oauth_sign_in_sources.include?(source.to_s)
72
      css_class = 'btn'
Andrei Gliga committed
73
      css_class << ' active' unless disabled
74
      checkbox_name = 'application_setting[enabled_oauth_sign_in_sources][]'
75 76

      label_tag(checkbox_name, class: css_class) do
77
        check_box_tag(checkbox_name, source, !disabled,
78
                      autocomplete: 'off') + Gitlab::OAuth::Provider.label_for(source)
79 80 81
      end
    end
  end
82

83
  def repository_storages_options_for_select
84 85
    options = Gitlab.config.repositories.storages.map do |name, storage|
      ["#{name} - #{storage['path']}", name]
86 87
    end

88
    options_for_select(options, @application_setting.repository_storages)
89
  end
90 91 92 93

  def sidekiq_queue_options_for_select
    options_for_select(Sidekiq::Queue.all.map(&:name), @application_setting.sidekiq_throttling_queues)
  end
94
end