Welcome to mirror list, hosted at ThFree Co, Russian Federation.

namespace_validator.rb « validators « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4ab1706abda7277c25d33df42acab0d77d78c3b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# NamespaceValidator
#
# Custom validator for GitLab namespace values.
#
# Values are checked for formatting and exclusion from `Gitlab::Blacklist.path`.
class NamespaceValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    unless value =~ Gitlab::Regex.namespace_regex
      record.errors.add(attribute, Gitlab::Regex.namespace_regex_message)
    end

    if blacklisted?(value)
      record.errors.add(attribute, "#{value} is a reserved name")
    end
  end

  private

  def blacklisted?(value)
    Gitlab::Blacklist.path.include?(value)
  end
end