Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
7fa767fe
Commit
7fa767fe
authored
Feb 08, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dz-limit-nested-groups' into 'master'
Limit level of nesting for groups See merge request !9000
parents
4b4e07cf
f642a460
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
12 deletions
+36
-12
app/models/namespace.rb
app/models/namespace.rb
+14
-1
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+22
-11
No files found.
app/models/namespace.rb
View file @
7fa767fe
...
...
@@ -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
spec/models/namespace_spec.rb
View file @
7fa767fe
...
...
@@ -3,22 +3,33 @@ require 'spec_helper'
describe
Namespace
,
models:
true
do
let!
(
:namespace
)
{
create
(
:namespace
)
}
describe
'associations'
do
it
{
is_expected
.
to
have_many
:projects
}
it
{
is_expected
.
to
have_many
:project_statistics
}
it
{
is_expected
.
to
belong_to
:parent
}
it
{
is_expected
.
to
have_many
:children
}
end
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:name
).
scoped_to
(
:parent_id
)
}
it
{
is_expected
.
to
validate_length_of
(
:name
).
is_at_most
(
255
)
}
it
{
is_expected
.
to
validate_length_of
(
:description
).
is_at_most
(
255
)
}
it
{
is_expected
.
to
validate_presence_of
(
:path
)
}
it
{
is_expected
.
to
validate_length_of
(
:path
).
is_at_most
(
255
)
}
it
{
is_expected
.
to
validate_presence_of
(
:owner
)
}
it
'does not allow too deep nesting'
do
ancestors
=
(
1
..
21
).
to_a
nested
=
build
(
:namespace
,
parent:
namespace
)
allow
(
nested
).
to
receive
(
:ancestors
).
and_return
(
ancestors
)
expect
(
nested
).
not_to
be_valid
expect
(
nested
.
errors
[
:parent_id
].
first
).
to
eq
(
'has too deep level of nesting'
)
end
end
describe
"Respond to"
do
it
{
is_expected
.
to
respond_to
(
:human_name
)
}
it
{
is_expected
.
to
respond_to
(
:to_param
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment