Add custom NamespaceNameValidator
This commit is contained in:
parent
9321d382bd
commit
175f482c3c
2 changed files with 13 additions and 3 deletions
|
@ -23,10 +23,10 @@ class Namespace < ActiveRecord::Base
|
|||
|
||||
validates :owner, presence: true, unless: ->(n) { n.type == "Group" }
|
||||
validates :name,
|
||||
presence: true, uniqueness: true,
|
||||
length: { within: 0..255 },
|
||||
format: { with: Gitlab::Regex.namespace_name_regex,
|
||||
message: Gitlab::Regex.namespace_name_regex_message }
|
||||
namespace_name: true,
|
||||
presence: true,
|
||||
uniqueness: true
|
||||
|
||||
validates :description, length: { within: 0..255 }
|
||||
validates :path,
|
||||
|
|
10
app/validators/namespace_name_validator.rb
Normal file
10
app/validators/namespace_name_validator.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
# NamespaceNameValidator
|
||||
#
|
||||
# Custom validator for GitLab namespace name strings.
|
||||
class NamespaceNameValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
unless value =~ Gitlab::Regex.namespace_name_regex
|
||||
record.errors.add(attribute, Gitlab::Regex.namespace_name_regex_message)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue