1_settings.rb 5.09 KB
Newer Older
1 2
class Settings < Settingslogic
  source "#{Rails.root}/config/gitlab.yml"
3
  namespace Rails.env
4 5

  class << self
6 7 8 9 10 11
    def gitlab_on_non_standard_port?
      ![443, 80].include?(gitlab.port.to_i)
    end

    private

12 13 14
    def build_gitlab_shell_ssh_path_prefix
      if gitlab_shell.ssh_port != 22
        "ssh://#{gitlab_shell.ssh_user}@#{gitlab_shell.ssh_host}:#{gitlab_shell.ssh_port}/"
15
      else
16
        "#{gitlab_shell.ssh_user}@#{gitlab_shell.ssh_host}:"
17 18 19 20 21 22 23 24 25 26 27 28
      end
    end

    def build_gitlab_url
      if gitlab_on_non_standard_port?
        custom_port = ":#{gitlab.port}"
      else
        custom_port = nil
      end
      [ gitlab.protocol,
        "://",
        gitlab.host,
29 30
        custom_port,
        gitlab.relative_url_root
31 32
      ].join('')
    end
33 34
  end
end
35 36 37 38


# Default settings
Settings['ldap'] ||= Settingslogic.new({})
39
Settings.ldap['enabled'] = false if Settings.ldap['enabled'].nil?
40 41
Settings.ldap['allow_username_or_email_login'] = false if Settings.ldap['allow_username_or_email_login'].nil?

42 43

Settings['omniauth'] ||= Settingslogic.new({})
44
Settings.omniauth['enabled']      = false if Settings.omniauth['enabled'].nil?
45 46
Settings.omniauth['providers']  ||= []

47 48
Settings['issues_tracker']  ||= {}

49 50 51
#
# GitLab
#
52
Settings['gitlab'] ||= Settingslogic.new({})
53 54
Settings.gitlab['default_projects_limit'] ||= 10
Settings.gitlab['default_can_create_group'] = true if Settings.gitlab['default_can_create_group'].nil?
55
Settings.gitlab['host']       ||= 'localhost'
56
Settings.gitlab['https']        = false if Settings.gitlab['https'].nil?
57
Settings.gitlab['port']       ||= Settings.gitlab.https ? 443 : 80
58
Settings.gitlab['relative_url_root'] ||= ENV['RAILS_RELATIVE_URL_ROOT'] || ''
59
Settings.gitlab['protocol']   ||= Settings.gitlab.https ? "https" : "http"
60
Settings.gitlab['email_from'] ||= "gitlab@#{Settings.gitlab.host}"
61
Settings.gitlab['support_email']  ||= Settings.gitlab.email_from
62
Settings.gitlab['url']        ||= Settings.send(:build_gitlab_url)
63
Settings.gitlab['user']       ||= 'git'
64 65 66 67 68
Settings.gitlab['user_home']  ||= begin
  Etc.getpwnam(Settings.gitlab['user']).dir
rescue ArgumentError # no user configured
  '/home/' + Settings.gitlab['user']
end
Marin Jankovski's avatar
Marin Jankovski committed
69
Settings.gitlab['signup_enabled'] ||= false
70
Settings.gitlab['username_changing_enabled'] = true if Settings.gitlab['username_changing_enabled'].nil?
71
Settings.gitlab['issue_closing_pattern'] = '^([Cc]loses|[Ff]ixes) #(\d+)' if Settings.gitlab['issue_closing_pattern'].nil?
72 73 74 75
Settings.gitlab['default_projects_features'] ||= {}
Settings.gitlab.default_projects_features['issues']         = true if Settings.gitlab.default_projects_features['issues'].nil?
Settings.gitlab.default_projects_features['merge_requests'] = true if Settings.gitlab.default_projects_features['merge_requests'].nil?
Settings.gitlab.default_projects_features['wiki']           = true if Settings.gitlab.default_projects_features['wiki'].nil?
76 77
Settings.gitlab.default_projects_features['wall']           = false if Settings.gitlab.default_projects_features['wall'].nil?
Settings.gitlab.default_projects_features['snippets']       = false if Settings.gitlab.default_projects_features['snippets'].nil?
78
Settings.gitlab.default_projects_features['public']         = false if Settings.gitlab.default_projects_features['public'].nil?
79

80 81 82
#
# Gravatar
#
83
Settings['gravatar'] ||= Settingslogic.new({})
84
Settings.gravatar['enabled']      = true if Settings.gravatar['enabled'].nil?
85 86
Settings.gravatar['plain_url']  ||= 'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=mm'
Settings.gravatar['ssl_url']    ||= 'https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm'
87

88 89 90 91
#
# GitLab Shell
#
Settings['gitlab_shell'] ||= Settingslogic.new({})
92
Settings.gitlab_shell['hooks_path']   ||= Settings.gitlab['user_home'] + '/gitlab-shell/hooks/'
93 94
Settings.gitlab_shell['receive_pack']   = true if Settings.gitlab_shell['receive_pack'].nil?
Settings.gitlab_shell['upload_pack']    = true if Settings.gitlab_shell['upload_pack'].nil?
95
Settings.gitlab_shell['repos_path']   ||= Settings.gitlab['user_home'] + '/repositories/'
96 97 98 99 100
Settings.gitlab_shell['ssh_host']     ||= (Settings.gitlab.host || 'localhost')
Settings.gitlab_shell['ssh_port']     ||= 22
Settings.gitlab_shell['ssh_user']     ||= Settings.gitlab.user
Settings.gitlab_shell['owner_group']  ||= Settings.gitlab.user
Settings.gitlab_shell['ssh_path_prefix'] ||= Settings.send(:build_gitlab_shell_ssh_path_prefix)
101

102 103 104
#
# Backup
#
105
Settings['backup'] ||= Settingslogic.new({})
106 107
Settings.backup['keep_time']  ||= 0
Settings.backup['path']         = File.expand_path(Settings.backup['path'] || "tmp/backups/", Rails.root)
108

109 110 111
#
# Git
#
112
Settings['git'] ||= Settingslogic.new({})
113 114
Settings.git['max_size']  ||= 5242880 # 5.megabytes
Settings.git['bin_path']  ||= '/usr/bin/git'
115
Settings.git['timeout']   ||= 10
116

117
Settings['satellites'] ||= Settingslogic.new({})
Riyad Preukschas's avatar
Riyad Preukschas committed
118
Settings.satellites['path'] = File.expand_path(Settings.satellites['path'] || "tmp/repo_satellites/", Rails.root)
119 120 121 122 123

#
# Extra customization
#
Settings['extra'] ||= Settingslogic.new({})
124 125 126 127 128 129 130 131 132

#
# Testing settings
#
if Rails.env.test?
  Settings.gitlab['default_projects_limit']   = 42
  Settings.gitlab['default_can_create_group'] = false
  Settings.gitlab['default_can_create_team']  = false
end