diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-02-08 15:04:31 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-02-08 15:04:31 +0000 |
commit | 7fa767fe35e7e7f023ee972bc6034fbdccf84ee7 (patch) | |
tree | 73aaebc95bc57dc9cae5078c835b041f45b36629 /app/models/namespace.rb | |
parent | 4b4e07cf47f82390255808fa4afdfe6c7fd96b5f (diff) | |
parent | f642a4608d99b1344d862134900c2e078eda9cfc (diff) | |
download | gitlab-ce-7fa767fe35e7e7f023ee972bc6034fbdccf84ee7.tar.gz |
Merge branch 'dz-limit-nested-groups' into 'master'
Limit level of nesting for groups
See merge request !9000
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r-- | app/models/namespace.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb index c5713fb7818..8352565da1c 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -7,6 +7,11 @@ class Namespace < ActiveRecord::Base include Gitlab::CurrentSettings include Routable + # Prevent users from creating unreasonably deep level of nesting. + # The number 20 was taken based on maximum nesting level of + # Android repo (15) + some extra backup. + NUMBER_OF_ANCESTORS_ALLOWED = 20 + cache_markdown_field :description, pipeline: :description has_many :projects, dependent: :destroy @@ -29,6 +34,8 @@ class Namespace < ActiveRecord::Base length: { maximum: 255 }, namespace: true + validate :nesting_level_allowed + delegate :name, to: :owner, allow_nil: true, prefix: true after_update :move_dir, if: :path_changed? @@ -194,7 +201,7 @@ class Namespace < ActiveRecord::Base # Scopes the model on ancestors of the record def ancestors if parent_id - path = route.path + path = route ? route.path : full_path paths = [] until path.blank? @@ -274,4 +281,10 @@ class Namespace < ActiveRecord::Base path_was end end + + def nesting_level_allowed + if ancestors.count > Group::NUMBER_OF_ANCESTORS_ALLOWED + errors.add(:parent_id, "has too deep level of nesting") + end + end end |