debian-mirror-gitlab/app/models/namespace_setting.rb

37 lines
933 B
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
class NamespaceSetting < ApplicationRecord
belongs_to :namespace, inverse_of: :namespace_settings
2021-01-03 14:25:43 +05:30
validate :default_branch_name_content
validate :allow_mfa_for_group
2021-01-29 00:20:46 +05:30
before_validation :normalize_default_branch_name
2021-01-03 14:25:43 +05:30
NAMESPACE_SETTINGS_PARAMS = [:default_branch_name].freeze
2020-07-28 23:09:34 +05:30
self.primary_key = :namespace_id
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
private
def normalize_default_branch_name
self.default_branch_name = nil if default_branch_name.blank?
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
2020-07-28 23:09:34 +05:30
end
NamespaceSetting.prepend_if_ee('EE::NamespaceSetting')