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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
f100790b
Commit
f100790b
authored
Sep 25, 2020
by
Eugenia Grieff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename finder param to include_parent_descendants
- Add tests for new finder param include_parent_descendants
parent
1fda2307
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
11 deletions
+66
-11
app/finders/groups_finder.rb
app/finders/groups_finder.rb
+8
-9
lib/api/groups.rb
lib/api/groups.rb
+2
-2
spec/finders/groups_finder_spec.rb
spec/finders/groups_finder_spec.rb
+56
-0
No files found.
app/finders/groups_finder.rb
View file @
f100790b
...
...
@@ -12,7 +12,7 @@
# all_available: boolean (defaults to true)
# min_access_level: integer
# exclude_group_ids: array of integers
# include_descendants: boolean (defaults to false)
# include_
parent_
descendants: boolean (defaults to false)
#
# Users with full private access can see all groups. The `owned` and `parent`
# params can be used to restrict the groups that are returned.
...
...
@@ -85,8 +85,9 @@ class GroupsFinder < UnionFinder
def
by_parent
(
groups
)
return
groups
unless
params
[
:parent
]
if
params
[
:include_descendants
]
groups
.
id_in
(
hierarchy_for_parent
(
params
[
:parent
]).
descendants
.
pluck
(
:id
))
if
include_parent_descendants?
descendants
=
Gitlab
::
ObjectHierarchy
.
new
(
Group
.
where
(
id:
params
[
:parent
])).
descendants
groups
.
id_in
(
descendants
.
pluck
(
:id
))
else
groups
.
where
(
parent:
params
[
:parent
])
end
...
...
@@ -105,13 +106,11 @@ class GroupsFinder < UnionFinder
params
.
fetch
(
:all_available
,
true
)
end
def
min_access_level
?
current_user
&&
params
[
:min_access_level
].
present?
def
include_parent_descendants
?
params
.
fetch
(
:include_parent_descendants
,
false
)
end
# rubocop: disable CodeReuse/ActiveRecord
def
hierarchy_for_parent
(
parent_group_id
)
@hierarchy
||=
Gitlab
::
ObjectHierarchy
.
new
(
Group
.
where
(
id:
parent_group_id
))
def
min_access_level?
current_user
&&
params
[
:min_access_level
].
present?
end
# rubocop: enable CodeReuse/ActiveRecord
end
lib/api/groups.rb
View file @
f100790b
...
...
@@ -33,7 +33,7 @@ module API
:all_available
,
:custom_attributes
,
:owned
,
:min_access_level
,
:include_descendants
:include_
parent_
descendants
)
find_params
[
:parent
]
=
if
params
[
:top_level_only
]
...
...
@@ -322,7 +322,7 @@ module API
use
:with_custom_attributes
end
get
":id/descendant_groups"
do
finder_params
=
declared_params
(
include_missing:
false
).
merge
(
include_descendants:
true
)
finder_params
=
declared_params
(
include_missing:
false
).
merge
(
include_
parent_
descendants:
true
)
groups
=
find_groups
(
finder_params
,
params
[
:id
])
present_groups
params
,
groups
end
...
...
spec/finders/groups_finder_spec.rb
View file @
f100790b
...
...
@@ -161,5 +161,61 @@ RSpec.describe GroupsFinder do
end
end
end
context
'with include parent group descendants'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:parent_group
)
{
create
(
:group
,
:public
)
}
let_it_be
(
:public_subgroup
)
{
create
(
:group
,
:public
,
parent:
parent_group
)
}
let_it_be
(
:internal_sub_subgroup
)
{
create
(
:group
,
:internal
,
parent:
public_subgroup
)
}
let_it_be
(
:private_sub_subgroup
)
{
create
(
:group
,
:private
,
parent:
public_subgroup
)
}
let_it_be
(
:public_sub_subgroup
)
{
create
(
:group
,
:public
,
parent:
public_subgroup
)
}
let
(
:params
)
{
{
include_parent_descendants:
true
,
parent:
parent_group
}
}
context
'with nil parent'
do
it
'returns all accessible groups'
do
params
[
:parent
]
=
nil
expect
(
described_class
.
new
(
user
,
params
).
execute
).
to
contain_exactly
(
parent_group
,
public_subgroup
,
internal_sub_subgroup
,
public_sub_subgroup
)
end
end
context
'without a user'
do
it
'only returns the group public descendants'
do
expect
(
described_class
.
new
(
nil
,
params
).
execute
).
to
contain_exactly
(
public_subgroup
,
public_sub_subgroup
)
end
end
context
'when a user is present'
do
it
'returns the group public and internal descendants'
do
expect
(
described_class
.
new
(
user
,
params
).
execute
).
to
contain_exactly
(
public_subgroup
,
public_sub_subgroup
,
internal_sub_subgroup
)
end
end
context
'when a parent group member is present'
do
before
do
parent_group
.
add_developer
(
user
)
end
it
'returns all group descendants'
do
expect
(
described_class
.
new
(
user
,
params
).
execute
).
to
contain_exactly
(
public_subgroup
,
public_sub_subgroup
,
internal_sub_subgroup
,
private_sub_subgroup
)
end
end
end
end
end
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