2020-07-16 11:09:38 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class NamespaceSetting < ApplicationRecord
|
2021-04-07 14:09:45 -04:00
|
|
|
include CascadingNamespaceSettingAttribute
|
|
|
|
|
|
|
|
cascading_attr :delayed_project_removal
|
|
|
|
|
2020-07-16 11:09:38 -04:00
|
|
|
belongs_to :namespace, inverse_of: :namespace_settings
|
|
|
|
|
2020-10-08 20:08:41 -04:00
|
|
|
validate :default_branch_name_content
|
2020-10-13 11:08:53 -04:00
|
|
|
validate :allow_mfa_for_group
|
2021-04-05 23:09:02 -04:00
|
|
|
validate :allow_resource_access_token_creation_for_group
|
2020-10-08 20:08:41 -04:00
|
|
|
|
2020-11-04 10:08:41 -05:00
|
|
|
before_validation :normalize_default_branch_name
|
|
|
|
|
2021-04-07 14:09:45 -04:00
|
|
|
NAMESPACE_SETTINGS_PARAMS = [:default_branch_name, :delayed_project_removal,
|
|
|
|
:lock_delayed_project_removal, :resource_access_token_creation_allowed].freeze
|
2020-10-08 20:08:41 -04:00
|
|
|
|
2020-07-16 11:09:38 -04:00
|
|
|
self.primary_key = :namespace_id
|
2020-10-08 20:08:41 -04:00
|
|
|
|
2020-11-04 10:08:41 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def normalize_default_branch_name
|
|
|
|
self.default_branch_name = nil if default_branch_name.blank?
|
|
|
|
end
|
|
|
|
|
2020-10-08 20:08:41 -04: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 11:08:53 -04: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-05 23:09:02 -04: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 11:09:38 -04:00
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
NamespaceSetting.prepend_mod_with('NamespaceSetting')
|