2020-07-16 15:09:38 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class NamespaceSetting < ApplicationRecord
|
2021-04-07 18:09:45 +00:00
|
|
|
include CascadingNamespaceSettingAttribute
|
2021-09-08 09:09:10 +00:00
|
|
|
include Sanitizable
|
2022-01-19 12:17:41 +00:00
|
|
|
include ChronicDurationAttribute
|
2022-08-19 21:11:26 +00:00
|
|
|
include IgnorableColumns
|
|
|
|
|
|
|
|
ignore_columns %i[exclude_from_free_user_cap include_for_free_user_cap_preview],
|
|
|
|
remove_with: '15.5',
|
|
|
|
remove_after: '2022-09-23'
|
2021-04-07 18:09:45 +00:00
|
|
|
|
|
|
|
cascading_attr :delayed_project_removal
|
|
|
|
|
2020-07-16 15:09:38 +00:00
|
|
|
belongs_to :namespace, inverse_of: :namespace_settings
|
|
|
|
|
2022-06-16 15:09:00 +00:00
|
|
|
enum jobs_to_be_done: { basics: 0, move_repository: 1, code_storage: 2, exploring: 3, ci: 4, other: 5 }, _suffix: true
|
|
|
|
enum enabled_git_access_protocol: { all: 0, ssh: 1, http: 2 }, _suffix: true
|
|
|
|
|
|
|
|
validates :enabled_git_access_protocol, inclusion: { in: enabled_git_access_protocols.keys }
|
|
|
|
|
2020-10-09 00:08:41 +00:00
|
|
|
validate :default_branch_name_content
|
2020-10-13 15:08:53 +00:00
|
|
|
validate :allow_mfa_for_group
|
2021-04-06 03:09:02 +00:00
|
|
|
validate :allow_resource_access_token_creation_for_group
|
2020-10-09 00:08:41 +00:00
|
|
|
|
2020-11-04 15:08:41 +00:00
|
|
|
before_validation :normalize_default_branch_name
|
|
|
|
|
2022-01-19 12:17:41 +00:00
|
|
|
chronic_duration_attr :runner_token_expiration_interval_human_readable, :runner_token_expiration_interval
|
|
|
|
chronic_duration_attr :subgroup_runner_token_expiration_interval_human_readable, :subgroup_runner_token_expiration_interval
|
|
|
|
chronic_duration_attr :project_runner_token_expiration_interval_human_readable, :project_runner_token_expiration_interval
|
|
|
|
|
2022-07-04 18:09:30 +00:00
|
|
|
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
|
|
|
|
].freeze
|
2020-10-09 00:08:41 +00:00
|
|
|
|
2020-07-16 15:09:38 +00:00
|
|
|
self.primary_key = :namespace_id
|
2020-10-09 00:08:41 +00:00
|
|
|
|
2022-07-04 18:09:30 +00:00
|
|
|
def self.allowed_namespace_settings_params
|
|
|
|
NAMESPACE_SETTINGS_PARAMS
|
|
|
|
end
|
|
|
|
|
2021-09-08 09:09:10 +00:00
|
|
|
sanitizes! :default_branch_name
|
|
|
|
|
2021-08-10 12:11:00 +00:00
|
|
|
def prevent_sharing_groups_outside_hierarchy
|
|
|
|
return super if namespace.root?
|
|
|
|
|
|
|
|
namespace.root_ancestor.prevent_sharing_groups_outside_hierarchy
|
|
|
|
end
|
|
|
|
|
2022-09-06 18:10:28 +00:00
|
|
|
def show_diff_preview_in_email?
|
|
|
|
return show_diff_preview_in_email unless namespace.has_parent?
|
|
|
|
|
|
|
|
all_ancestors_allow_diff_preview_in_email?
|
|
|
|
end
|
|
|
|
|
2020-11-04 15:08:41 +00:00
|
|
|
private
|
|
|
|
|
2022-09-06 18:10:28 +00:00
|
|
|
def all_ancestors_allow_diff_preview_in_email?
|
|
|
|
!self.class.where(namespace_id: namespace.self_and_ancestors, show_diff_preview_in_email: false).exists?
|
|
|
|
end
|
|
|
|
|
2020-11-04 15:08:41 +00:00
|
|
|
def normalize_default_branch_name
|
2021-09-08 09:09:10 +00:00
|
|
|
self.default_branch_name = default_branch_name.presence
|
2020-11-04 15:08:41 +00:00
|
|
|
end
|
|
|
|
|
2020-10-09 00:08:41 +00:00
|
|
|
def default_branch_name_content
|
|
|
|
return if default_branch_name.nil?
|
|
|
|
|
|
|
|
if default_branch_name.blank?
|
|
|
|
errors.add(:default_branch_name, "can not be an empty string")
|
|
|
|
end
|
|
|
|
end
|
2020-10-13 15:08:53 +00:00
|
|
|
|
|
|
|
def allow_mfa_for_group
|
|
|
|
if namespace&.subgroup? && allow_mfa_for_subgroups == false
|
|
|
|
errors.add(:allow_mfa_for_subgroups, _('is not allowed since the group is not top-level group.'))
|
|
|
|
end
|
|
|
|
end
|
2021-04-06 03:09:02 +00:00
|
|
|
|
|
|
|
def allow_resource_access_token_creation_for_group
|
|
|
|
if namespace&.subgroup? && !resource_access_token_creation_allowed
|
|
|
|
errors.add(:resource_access_token_creation_allowed, _('is not allowed since the group is not top-level group.'))
|
|
|
|
end
|
|
|
|
end
|
2020-07-16 15:09:38 +00:00
|
|
|
end
|
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
NamespaceSetting.prepend_mod_with('NamespaceSetting')
|