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
Léo-Paul Géneau
gitlab-ce
Commits
7a3ba8e9
Commit
7a3ba8e9
authored
Sep 26, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure the user only sees groups he's allowed to see
parent
b92e7103
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
2 deletions
+40
-2
app/finders/group_descendants_finder.rb
app/finders/group_descendants_finder.rb
+12
-2
spec/finders/group_descendants_finder_spec.rb
spec/finders/group_descendants_finder_spec.rb
+28
-0
No files found.
app/finders/group_descendants_finder.rb
View file @
7a3ba8e9
...
...
@@ -73,13 +73,23 @@ class GroupDescendantsFinder
all_available:
true
).
execute
end
def
all_descendant_groups
def
all_visible_descendant_groups
groups_table
=
Group
.
arel_table
visible_for_user
=
if
current_user
groups_table
[
:id
].
in
(
Arel
::
Nodes
::
SqlLiteral
.
new
(
GroupsFinder
.
new
(
current_user
,
all_available:
true
).
execute
.
select
(
:id
).
to_sql
)
)
else
groups_table
[
:visibility_level
].
eq
(
Gitlab
::
VisibilityLevel
::
PUBLIC
)
end
Gitlab
::
GroupHierarchy
.
new
(
Group
.
where
(
id:
parent_group
))
.
base_and_descendants
.
where
(
visible_for_user
)
end
def
subgroups_matching_filter
all_descendant_groups
all_
visible_
descendant_groups
.
where
.
not
(
id:
parent_group
)
.
search
(
params
[
:filter
])
end
...
...
spec/finders/group_descendants_finder_spec.rb
View file @
7a3ba8e9
...
...
@@ -58,6 +58,19 @@ describe GroupDescendantsFinder do
expect
(
found_group
.
preloaded_member_count
).
to
eq
(
1
)
end
it
'does not include subgroups the user does not have access to'
do
subgroup
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
public_subgroup
=
create
(
:group
,
:public
,
parent:
group
,
path:
'public-group'
)
other_subgroup
=
create
(
:group
,
:private
,
parent:
group
,
path:
'visible-private-group'
)
other_user
=
create
(
:user
)
other_subgroup
.
add_developer
(
other_user
)
finder
=
described_class
.
new
(
current_user:
other_user
,
parent_group:
group
)
expect
(
finder
.
execute
).
to
contain_exactly
(
public_subgroup
,
other_subgroup
)
end
context
'with a filter'
do
let
(
:params
)
{
{
filter:
'test'
}
}
...
...
@@ -68,6 +81,21 @@ describe GroupDescendantsFinder do
expect
(
finder
.
execute
).
to
contain_exactly
(
matching_subgroup
,
matching_project
)
end
it
'does not include subgroups the user does not have access to'
do
_invisible_subgroup
=
create
(
:group
,
:private
,
parent:
group
,
name:
'test1'
)
other_subgroup
=
create
(
:group
,
:private
,
parent:
group
,
name:
'test2'
)
public_subgroup
=
create
(
:group
,
:public
,
parent:
group
,
name:
'test3'
)
other_subsubgroup
=
create
(
:group
,
:private
,
parent:
other_subgroup
,
name:
'test4'
)
other_user
=
create
(
:user
)
other_subgroup
.
add_developer
(
other_user
)
finder
=
described_class
.
new
(
current_user:
other_user
,
parent_group:
group
,
params:
params
)
expect
(
finder
.
execute
).
to
contain_exactly
(
other_subgroup
,
public_subgroup
,
other_subsubgroup
)
end
context
'with matching children'
do
it
'includes a group that has a subgroup matching the query and its parent'
do
matching_subgroup
=
create
(
:group
,
name:
'testgroup'
,
parent:
subgroup
)
...
...
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