Class: NamespaceSetting

Inherits:
ApplicationRecord show all
Includes:
CascadingNamespaceSettingAttribute, ChronicDurationAttribute, Sanitizable
Defined in:
app/models/namespace_setting.rb

Constant Summary collapse

NAMESPACE_SETTINGS_PARAMS =
%i[
  default_branch_name
  delayed_project_removal
  lock_delayed_project_removal
  resource_access_token_creation_allowed
  prevent_sharing_groups_outside_hierarchy
  new_user_signups_cap
  setup_for_company
  jobs_to_be_done
  runner_token_expiration_interval
  enabled_git_access_protocol
  subgroup_runner_token_expiration_interval
  project_runner_token_expiration_interval
  default_branch_protection_defaults
].freeze
DEFAULT_BRANCH_PROTECTIONS_DEFAULT_MAX_SIZE =

matches the size set in the database constraint

1.kilobyte

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ChronicDurationAttribute

#chronic_duration_attributes, #output_chronic_duration_attribute

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.allowed_namespace_settings_paramsObject



56
57
58
# File 'app/models/namespace_setting.rb', line 56

def self.allowed_namespace_settings_params
  NAMESPACE_SETTINGS_PARAMS
end

Instance Method Details

#all_ancestors_have_runner_registration_enabled?Boolean

Returns:

  • (Boolean)


76
77
78
79
80
81
82
# File 'app/models/namespace_setting.rb', line 76

def all_ancestors_have_runner_registration_enabled?
  return false unless Gitlab::CurrentSettings.valid_runner_registrars.include?('group')

  return true unless namespace.has_parent?

  !self.class.where(namespace_id: namespace.ancestors, runner_registration_enabled: false).exists?
end

#allow_runner_registration_token?Boolean

Returns:

  • (Boolean)


84
85
86
87
88
# File 'app/models/namespace_setting.rb', line 84

def allow_runner_registration_token?
  settings = Gitlab::CurrentSettings.current_application_settings

  settings.allow_runner_registration_token && namespace.root_ancestor.allow_runner_registration_token
end

#prevent_sharing_groups_outside_hierarchyObject



60
61
62
63
64
# File 'app/models/namespace_setting.rb', line 60

def prevent_sharing_groups_outside_hierarchy
  return super if namespace.root?

  namespace.root_ancestor.prevent_sharing_groups_outside_hierarchy
end

#runner_registration_enabled?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/namespace_setting.rb', line 72

def runner_registration_enabled?
  runner_registration_enabled && all_ancestors_have_runner_registration_enabled?
end

#show_diff_preview_in_email?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
# File 'app/models/namespace_setting.rb', line 66

def show_diff_preview_in_email?
  return show_diff_preview_in_email unless namespace.has_parent?

  all_ancestors_allow_diff_preview_in_email?
end