Module: ApplicationSettingImplementation

Extended by:
ActiveSupport::Concern
Includes:
Gitlab::Utils::StrongMemoize
Included in:
ApplicationSetting, Gitlab::FakeApplicationSettings
Defined in:
app/models/application_setting_implementation.rb

Constant Summary collapse

STRING_LIST_SEPARATOR =
%r{\s*[,;]\s*     # comma or semicolon, optionally surrounded by whitespace
  |               # or
  \s              # any whitespace character
  |               # or
  [\r\n]          # any number of newline characters
}x.freeze
FORBIDDEN_KEY_VALUE =

Setting a key restriction to `-1` means that all keys of this type are forbidden.

KeyRestrictionValidator::FORBIDDEN
SUPPORTED_KEY_TYPES =
%i[rsa dsa ecdsa ed25519].freeze
DEFAULT_PROTECTED_PATHS =
[
  '/users/password',
  '/users/sign_in',
  '/api/v3/session.json',
  '/api/v3/session',
  '/api/v4/session.json',
  '/api/v4/session',
  '/users',
  '/users/confirmation',
  '/unsubscribes/',
  '/import/github/personal_access_token',
  '/admin/session'
].freeze
DEFAULT_MINIMUM_PASSWORD_LENGTH =
8

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Instance Method Details

#add_to_outbound_local_requests_whitelist(values_array) ⇒ Object


230
231
232
233
234
235
236
237
# File 'app/models/application_setting_implementation.rb', line 230

def add_to_outbound_local_requests_whitelist(values_array)
  clear_memoization(:outbound_local_requests_whitelist_arrays)

  self.outbound_local_requests_whitelist ||= []
  self.outbound_local_requests_whitelist += values_array

  self.outbound_local_requests_whitelist.uniq!
end

#allow_signup?Boolean

Returns:

  • (Boolean)

352
353
354
# File 'app/models/application_setting_implementation.rb', line 352

def allow_signup?
   && password_authentication_enabled_for_web?
end

#allowed_key_typesObject


340
341
342
343
344
# File 'app/models/application_setting_implementation.rb', line 340

def allowed_key_types
  SUPPORTED_KEY_TYPES.select do |type|
    key_restriction_for(type) != FORBIDDEN_KEY_VALUE
  end
end

#archive_builds_older_thanObject


378
379
380
# File 'app/models/application_setting_implementation.rb', line 378

def archive_builds_older_than
  archive_builds_in_seconds.seconds.ago if archive_builds_in_seconds
end

#asset_proxy_whitelist=(values) ⇒ Object


261
262
263
264
265
266
267
268
# File 'app/models/application_setting_implementation.rb', line 261

def asset_proxy_whitelist=(values)
  values = strings_to_array(values) if values.is_a?(String)

  # make sure we always whitelist the running host
  values << Gitlab.config.gitlab.host unless values.include?(Gitlab.config.gitlab.host)

  self[:asset_proxy_whitelist] = values
end

#commit_email_hostnameObject


278
279
280
# File 'app/models/application_setting_implementation.rb', line 278

def commit_email_hostname
  super.presence || self.class.default_commit_email_hostname
end

#default_group_visibility=(level) ⇒ Object


290
291
292
# File 'app/models/application_setting_implementation.rb', line 290

def default_group_visibility=(level)
  super(Gitlab::VisibilityLevel.level_value(level))
end

#default_project_visibility=(level) ⇒ Object


282
283
284
# File 'app/models/application_setting_implementation.rb', line 282

def default_project_visibility=(level)
  super(Gitlab::VisibilityLevel.level_value(level))
end

#default_snippet_visibility=(level) ⇒ Object


286
287
288
# File 'app/models/application_setting_implementation.rb', line 286

def default_snippet_visibility=(level)
  super(Gitlab::VisibilityLevel.level_value(level))
end

#disabled_oauth_sign_in_sources=(sources) ⇒ Object


195
196
197
198
# File 'app/models/application_setting_implementation.rb', line 195

def (sources)
  sources = (sources || []).map(&:to_s) & Devise.omniauth_providers.map(&:to_s)
  super(sources)
end

#domain_blacklist_file=(file) ⇒ Object


216
217
218
# File 'app/models/application_setting_implementation.rb', line 216

def domain_blacklist_file=(file)
  self.domain_blacklist_raw = file.read
end

#domain_blacklist_rawObject


204
205
206
# File 'app/models/application_setting_implementation.rb', line 204

def domain_blacklist_raw
  array_to_string(self.domain_blacklist)
end

#domain_blacklist_raw=(values) ⇒ Object


212
213
214
# File 'app/models/application_setting_implementation.rb', line 212

def domain_blacklist_raw=(values)
  self.domain_blacklist = strings_to_array(values)
end

#domain_whitelist_rawObject


200
201
202
# File 'app/models/application_setting_implementation.rb', line 200

def domain_whitelist_raw
  array_to_string(self.domain_whitelist)
end

#domain_whitelist_raw=(values) ⇒ Object


208
209
210
# File 'app/models/application_setting_implementation.rb', line 208

def domain_whitelist_raw=(values)
  self.domain_whitelist = strings_to_array(values)
end

#health_check_access_tokenObject


328
329
330
# File 'app/models/application_setting_implementation.rb', line 328

def health_check_access_token
  ensure_health_check_access_token!
end

#help_page_support_url_column_exists?Boolean

Returns:

  • (Boolean)

191
192
193
# File 'app/models/application_setting_implementation.rb', line 191

def help_page_support_url_column_exists?
  ::Gitlab::Database.cached_column_exists?(:application_settings, :help_page_support_url)
end

#home_page_url_column_exists?Boolean

Returns:

  • (Boolean)

187
188
189
# File 'app/models/application_setting_implementation.rb', line 187

def home_page_url_column_exists?
  ::Gitlab::Database.cached_column_exists?(:application_settings, :home_page_url)
end

#key_restriction_for(type) ⇒ Object


346
347
348
349
350
# File 'app/models/application_setting_implementation.rb', line 346

def key_restriction_for(type)
  attr_name = "#{type}_key_restriction"

  has_attribute?(attr_name) ? public_send(attr_name) : FORBIDDEN_KEY_VALUE # rubocop:disable GitlabSecurity/PublicSend
end

#latest_termsObject


369
370
371
# File 'app/models/application_setting_implementation.rb', line 369

def latest_terms
  @latest_terms ||= ApplicationSetting::Term.latest
end

#normalized_repository_storage_weightsObject


307
308
309
310
311
312
313
314
315
316
317
# File 'app/models/application_setting_implementation.rb', line 307

def normalized_repository_storage_weights
  strong_memoize(:normalized_repository_storage_weights) do
    weights_total = repository_storages_weighted.values.reduce(:+)

    repository_storages_weighted.transform_values do |w|
      next w if weights_total == 0

      w.to_f / weights_total
    end
  end
end

#outbound_local_requests_whitelist_arraysObject

This method separates out the strings stored in the application_setting.outbound_local_requests_whitelist array into 2 arrays; an array of IPAddr objects (`[IPAddr.new('127.0.0.1')]`), and an array of domain strings (`['www.example.com']`).


243
244
245
246
247
248
249
250
251
# File 'app/models/application_setting_implementation.rb', line 243

def outbound_local_requests_whitelist_arrays
  strong_memoize(:outbound_local_requests_whitelist_arrays) do
    next [[], []] unless self.outbound_local_requests_whitelist

    ip_whitelist, domain_whitelist = separate_whitelists(self.outbound_local_requests_whitelist)

    [ip_whitelist, domain_whitelist]
  end
end

#outbound_local_requests_whitelist_rawObject


220
221
222
# File 'app/models/application_setting_implementation.rb', line 220

def outbound_local_requests_whitelist_raw
  array_to_string(self.outbound_local_requests_whitelist)
end

#outbound_local_requests_whitelist_raw=(values) ⇒ Object


224
225
226
227
228
# File 'app/models/application_setting_implementation.rb', line 224

def outbound_local_requests_whitelist_raw=(values)
  clear_memoization(:outbound_local_requests_whitelist_arrays)

  self.outbound_local_requests_whitelist = strings_to_array(values)
end

#password_authentication_enabled?Boolean

Returns:

  • (Boolean)

356
357
358
# File 'app/models/application_setting_implementation.rb', line 356

def password_authentication_enabled?
  password_authentication_enabled_for_web? || password_authentication_enabled_for_git?
end

#performance_bar_allowed_groupObject


298
299
300
# File 'app/models/application_setting_implementation.rb', line 298

def performance_bar_allowed_group
  Group.find_by_id(performance_bar_allowed_group_id)
end

#performance_bar_enabledObject

Return true if the Performance Bar is enabled for a given group


303
304
305
# File 'app/models/application_setting_implementation.rb', line 303

def performance_bar_enabled
  performance_bar_allowed_group_id.present?
end

#pick_repository_storageObject

Choose one of the available repository storage options based on a normalized weighted probability.


320
321
322
# File 'app/models/application_setting_implementation.rb', line 320

def pick_repository_storage
  normalized_repository_storage_weights.max_by { |_, weight| rand**(1.0 / weight) }.first
end

#protected_paths_rawObject


253
254
255
# File 'app/models/application_setting_implementation.rb', line 253

def protected_paths_raw
  array_to_string(self.protected_paths)
end

#protected_paths_raw=(values) ⇒ Object


257
258
259
# File 'app/models/application_setting_implementation.rb', line 257

def protected_paths_raw=(values)
  self.protected_paths = strings_to_array(values)
end

#repository_storagesObject


270
271
272
# File 'app/models/application_setting_implementation.rb', line 270

def repository_storages
  Array(read_attribute(:repository_storages))
end

#repository_storages_weightedObject


274
275
276
# File 'app/models/application_setting_implementation.rb', line 274

def repository_storages_weighted
  read_attribute(:repository_storages_weighted)
end

#reset_memoized_termsObject


373
374
375
376
# File 'app/models/application_setting_implementation.rb', line 373

def reset_memoized_terms
  @latest_terms = nil # rubocop:disable Gitlab/ModuleWithInstanceVariables
  latest_terms
end

#restricted_visibility_levels=(levels) ⇒ Object


294
295
296
# File 'app/models/application_setting_implementation.rb', line 294

def restricted_visibility_levels=(levels)
  super(levels&.map { |level| Gitlab::VisibilityLevel.level_value(level) })
end

#runners_registration_tokenObject


324
325
326
# File 'app/models/application_setting_implementation.rb', line 324

def runners_registration_token
  ensure_runners_registration_token!
end

#static_objects_external_storage_enabled?Boolean

Returns:

  • (Boolean)

382
383
384
# File 'app/models/application_setting_implementation.rb', line 382

def static_objects_external_storage_enabled?
  static_objects_external_storage_url.present?
end

#usage_ping_can_be_configured?Boolean

Returns:

  • (Boolean)

332
333
334
# File 'app/models/application_setting_implementation.rb', line 332

def usage_ping_can_be_configured?
  Settings.gitlab.usage_ping_enabled
end

#usage_ping_enabledObject


336
337
338
# File 'app/models/application_setting_implementation.rb', line 336

def usage_ping_enabled
  usage_ping_can_be_configured? && super
end

#user_default_internal_regex_enabled?Boolean

Returns:

  • (Boolean)

360
361
362
# File 'app/models/application_setting_implementation.rb', line 360

def user_default_internal_regex_enabled?
  user_default_external? && user_default_internal_regex.present?
end

#user_default_internal_regex_instanceObject


364
365
366
# File 'app/models/application_setting_implementation.rb', line 364

def user_default_internal_regex_instance
  Regexp.new(user_default_internal_regex, Regexp::IGNORECASE)
end

#web_ide_clientside_preview_bundler_urlObject

This will eventually be configurable gitlab.com/gitlab-org/gitlab/issues/208161


388
389
390
# File 'app/models/application_setting_implementation.rb', line 388

def web_ide_clientside_preview_bundler_url
  'https://sandbox-prod.gitlab-static.net'
end