2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class NamespaceSetting < ApplicationRecord
|
2021-04-29 21:17:54 +05:30
|
|
|
include CascadingNamespaceSettingAttribute
|
2021-11-11 11:23:49 +05:30
|
|
|
include Sanitizable
|
2022-03-02 08:16:31 +05:30
|
|
|
include ChronicDurationAttribute
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
cascading_attr :delayed_project_removal
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
belongs_to :namespace, inverse_of: :namespace_settings
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
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 }
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
validate :default_branch_name_content
|
|
|
|
validate :allow_mfa_for_group
|
2021-04-29 21:17:54 +05:30
|
|
|
validate :allow_resource_access_token_creation_for_group
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
before_validation :normalize_default_branch_name
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
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
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
NAMESPACE_SETTINGS_PARAMS = [:default_branch_name, :delayed_project_removal,
|
2021-09-04 01:27:46 +05:30
|
|
|
:lock_delayed_project_removal, :resource_access_token_creation_allowed,
|
2021-11-11 11:23:49 +05:30
|
|
|
:prevent_sharing_groups_outside_hierarchy, :new_user_signups_cap,
|
2022-07-23 23:45:48 +05:30
|
|
|
:setup_for_company, :jobs_to_be_done, :runner_token_expiration_interval, :enabled_git_access_protocol,
|
2022-03-02 08:16:31 +05:30
|
|
|
:subgroup_runner_token_expiration_interval, :project_runner_token_expiration_interval].freeze
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
self.primary_key = :namespace_id
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
sanitizes! :default_branch_name
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
def prevent_sharing_groups_outside_hierarchy
|
|
|
|
return super if namespace.root?
|
|
|
|
|
|
|
|
namespace.root_ancestor.prevent_sharing_groups_outside_hierarchy
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def normalize_default_branch_name
|
2021-11-11 11:23:49 +05:30
|
|
|
self.default_branch_name = default_branch_name.presence
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
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-29 21:17:54 +05:30
|
|
|
|
|
|
|
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-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
NamespaceSetting.prepend_mod_with('NamespaceSetting')
|