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
80780018
Commit
80780018
authored
Sep 05, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update `children` route to handle projects and groups
parent
648c082a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
31 deletions
+77
-31
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+6
-2
config/routes/group.rb
config/routes/group.rb
+3
-0
lib/gitlab/path_regex.rb
lib/gitlab/path_regex.rb
+0
-1
spec/controllers/groups_controller_spec.rb
spec/controllers/groups_controller_spec.rb
+61
-21
spec/lib/gitlab/path_regex_spec.rb
spec/lib/gitlab/path_regex_spec.rb
+7
-7
No files found.
app/controllers/groups_controller.rb
View file @
80780018
...
...
@@ -61,7 +61,11 @@ class GroupsController < Groups::ApplicationController
end
def
children
parent
=
Group
.
find_by
(
parent_id:
params
[
:parent_id
])
||
@group
parent
=
if
params
[
:parent_id
].
present?
Group
.
find
(
params
[
:parent_id
])
else
@group
end
if
parent
.
nil?
||
!
can?
(
current_user
,
:read_group
,
parent
)
render_404
end
...
...
@@ -70,7 +74,7 @@ class GroupsController < Groups::ApplicationController
respond_to
do
|
format
|
format
.
json
do
render
json:
GroupChild
ren
Serializer
render
json:
GroupChildSerializer
.
new
(
current_user:
current_user
)
.
with_pagination
(
request
,
response
)
.
represent
(
@children
)
...
...
config/routes/group.rb
View file @
80780018
...
...
@@ -41,6 +41,9 @@ scope(path: 'groups/*id',
get
:merge_requests
,
as: :merge_requests_group
get
:projects
,
as: :projects_group
get
:activity
,
as: :activity_group
scope
(
path:
'-'
)
do
get
:children
,
as: :group_children
end
get
'/'
,
action: :show
,
as: :group_canonical
end
...
...
lib/gitlab/path_regex.rb
View file @
80780018
...
...
@@ -129,7 +129,6 @@ module Gitlab
notification_setting
pipeline_quota
projects
subgroups
]
.
freeze
ILLEGAL_PROJECT_PATH_WORDS
=
PROJECT_WILDCARD_ROUTES
...
...
spec/controllers/groups_controller_spec.rb
View file @
80780018
...
...
@@ -150,39 +150,79 @@ describe GroupsController do
end
end
describe
'GET #subgroups'
,
:nested_groups
do
let!
(
:public_subgroup
)
{
create
(
:group
,
:public
,
parent:
group
)
}
let!
(
:private_subgroup
)
{
create
(
:group
,
:private
,
parent:
group
)
}
describe
'GET #children'
do
context
'for projects'
do
let!
(
:public_project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let!
(
:private_project
)
{
create
(
:project
,
:private
,
namespace:
group
)
}
context
'as a user'
do
before
do
sign_in
(
user
)
pending
(
'spec the children path instead'
)
context
'as a user'
do
before
do
sign_in
(
user
)
end
it
'shows all children'
do
get
:children
,
id:
group
.
to_param
,
format: :json
expect
(
assigns
(
:children
)).
to
contain_exactly
(
public_project
,
private_project
)
end
context
'being member of private subgroup'
do
it
'shows public and private children the user is member of'
do
group_member
.
destroy!
private_project
.
add_guest
(
user
)
get
:children
,
id:
group
.
to_param
,
format: :json
expect
(
assigns
(
:children
)).
to
contain_exactly
(
public_project
,
private_project
)
end
end
end
it
'shows all subgroups'
do
get
:subgroups
,
id:
group
.
to_param
context
'as a guest'
do
it
'shows the public children'
do
get
:children
,
id:
group
.
to_param
,
format: :json
expect
(
assigns
(
:nested_groups
)).
to
contain_exactly
(
public_subgroup
,
private_subgroup
)
expect
(
assigns
(
:children
)).
to
contain_exactly
(
public_project
)
end
end
end
context
'being member of private subgroup'
do
it
'shows public and private subgroups the user is member of'
do
group_member
.
destroy!
private_subgroup
.
add_guest
(
user
)
context
'for subgroups'
,
:nested_groups
do
let!
(
:public_subgroup
)
{
create
(
:group
,
:public
,
parent:
group
)
}
let!
(
:private_subgroup
)
{
create
(
:group
,
:private
,
parent:
group
)
}
let!
(
:public_project
)
{
create
(
:project
,
:public
,
namespace:
group
)
}
let!
(
:private_project
)
{
create
(
:project
,
:private
,
namespace:
group
)
}
get
:subgroups
,
id:
group
.
to_param
context
'as a user'
do
before
do
sign_in
(
user
)
end
expect
(
assigns
(
:nested_groups
)).
to
contain_exactly
(
public_subgroup
,
private_subgroup
)
it
'shows all children'
do
get
:children
,
id:
group
.
to_param
,
format: :json
expect
(
assigns
(
:children
)).
to
contain_exactly
(
public_subgroup
,
private_subgroup
,
public_project
,
private_project
)
end
context
'being member of private subgroup'
do
it
'shows public and private children the user is member of'
do
group_member
.
destroy!
private_subgroup
.
add_guest
(
user
)
private_project
.
add_guest
(
user
)
get
:children
,
id:
group
.
to_param
,
format: :json
expect
(
assigns
(
:children
)).
to
contain_exactly
(
public_subgroup
,
private_subgroup
,
public_project
,
private_project
)
end
end
end
end
context
'as a guest'
do
it
'shows the public subgroups
'
do
get
:subgroups
,
id:
group
.
to_param
context
'as a guest'
do
it
'shows the public children
'
do
get
:children
,
id:
group
.
to_param
,
format: :json
expect
(
assigns
(
:nested_groups
)).
to
contain_exactly
(
public_subgroup
)
expect
(
assigns
(
:children
)).
to
contain_exactly
(
public_subgroup
,
public_project
)
end
end
end
end
...
...
spec/lib/gitlab/path_regex_spec.rb
View file @
80780018
...
...
@@ -213,7 +213,7 @@ describe Gitlab::PathRegex do
it
'accepts group routes'
do
expect
(
subject
).
to
match
(
'activity/'
)
expect
(
subject
).
to
match
(
'group_members/'
)
expect
(
subject
).
to
match
(
'
subgroup
s/'
)
expect
(
subject
).
to
match
(
'
label
s/'
)
end
it
'is not case sensitive'
do
...
...
@@ -246,7 +246,7 @@ describe Gitlab::PathRegex do
it
'accepts group routes'
do
expect
(
subject
).
to
match
(
'activity/'
)
expect
(
subject
).
to
match
(
'group_members/'
)
expect
(
subject
).
to
match
(
'
subgroup
s/'
)
expect
(
subject
).
to
match
(
'
label
s/'
)
end
end
...
...
@@ -268,7 +268,7 @@ describe Gitlab::PathRegex do
it
'accepts group routes'
do
expect
(
subject
).
to
match
(
'activity/more/'
)
expect
(
subject
).
to
match
(
'group_members/more/'
)
expect
(
subject
).
to
match
(
'
subgroup
s/more/'
)
expect
(
subject
).
to
match
(
'
label
s/more/'
)
end
end
end
...
...
@@ -292,7 +292,7 @@ describe Gitlab::PathRegex do
it
'rejects group routes'
do
expect
(
subject
).
not_to
match
(
'root/activity/'
)
expect
(
subject
).
not_to
match
(
'root/group_members/'
)
expect
(
subject
).
not_to
match
(
'root/
subgroup
s/'
)
expect
(
subject
).
not_to
match
(
'root/
label
s/'
)
end
end
...
...
@@ -314,7 +314,7 @@ describe Gitlab::PathRegex do
it
'rejects group routes'
do
expect
(
subject
).
not_to
match
(
'root/activity/more/'
)
expect
(
subject
).
not_to
match
(
'root/group_members/more/'
)
expect
(
subject
).
not_to
match
(
'root/
subgroup
s/more/'
)
expect
(
subject
).
not_to
match
(
'root/
label
s/more/'
)
end
end
end
...
...
@@ -349,7 +349,7 @@ describe Gitlab::PathRegex do
it
'accepts group routes'
do
expect
(
subject
).
to
match
(
'activity/'
)
expect
(
subject
).
to
match
(
'group_members/'
)
expect
(
subject
).
to
match
(
'
subgroup
s/'
)
expect
(
subject
).
to
match
(
'
label
s/'
)
end
it
'is not case sensitive'
do
...
...
@@ -382,7 +382,7 @@ describe Gitlab::PathRegex do
it
'accepts group routes'
do
expect
(
subject
).
to
match
(
'root/activity/'
)
expect
(
subject
).
to
match
(
'root/group_members/'
)
expect
(
subject
).
to
match
(
'root/
subgroup
s/'
)
expect
(
subject
).
to
match
(
'root/
label
s/'
)
end
it
'is not case sensitive'
do
...
...
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