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
fb91e449
Commit
fb91e449
authored
Jan 27, 2022
by
Francisco Javier López
Committed by
Alper Akgun
Jan 27, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce linear ancestors upto in GroupDescendantsFinder
parent
9df0ef28
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
39 deletions
+64
-39
app/finders/group_descendants_finder.rb
app/finders/group_descendants_finder.rb
+7
-2
config/feature_flags/development/linear_group_descendants_finder_upto.yml
...lags/development/linear_group_descendants_finder_upto.yml
+8
-0
spec/finders/group_descendants_finder_spec.rb
spec/finders/group_descendants_finder_spec.rb
+49
-37
No files found.
app/finders/group_descendants_finder.rb
View file @
fb91e449
...
...
@@ -110,8 +110,13 @@ class GroupDescendantsFinder
# rubocop: disable CodeReuse/ActiveRecord
def
ancestors_of_groups
(
base_for_ancestors
)
group_ids
=
base_for_ancestors
.
except
(
:select
,
:sort
).
select
(
:id
)
Gitlab
::
ObjectHierarchy
.
new
(
Group
.
where
(
id:
group_ids
))
.
base_and_ancestors
(
upto:
parent_group
.
id
)
groups
=
Group
.
where
(
id:
group_ids
)
if
Feature
.
enabled?
(
:linear_group_descendants_finder_upto
,
current_user
,
default_enabled: :yaml
)
groups
.
self_and_ancestors
(
upto:
parent_group
.
id
)
else
Gitlab
::
ObjectHierarchy
.
new
(
groups
).
base_and_ancestors
(
upto:
parent_group
.
id
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
config/feature_flags/development/linear_group_descendants_finder_upto.yml
0 → 100644
View file @
fb91e449
---
name
:
linear_group_descendants_finder_upto
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/78991
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/350972
milestone
:
'
14.8'
type
:
development
group
:
group::authentication and authorization
default_enabled
:
false
spec/finders/group_descendants_finder_spec.rb
View file @
fb91e449
...
...
@@ -165,8 +165,8 @@ RSpec.describe GroupDescendantsFinder do
end
context
'with nested groups'
do
let
!
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
let
!
(
:subgroup
)
{
create
(
:group
,
:private
,
parent:
group
)
}
let
_it_be
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
let
_it_be_with_reload
(
:subgroup
)
{
create
(
:group
,
:private
,
parent:
group
)
}
describe
'#execute'
do
it
'contains projects and subgroups'
do
...
...
@@ -208,57 +208,69 @@ RSpec.describe GroupDescendantsFinder do
context
'with a filter'
do
let
(
:params
)
{
{
filter:
'test'
}
}
it
'contains only matching projects and subgroups'
do
matching_project
=
create
(
:project
,
namespace:
group
,
name:
'Testproject'
)
matching_subgroup
=
create
(
:group
,
name:
'testgroup'
,
parent:
group
)
shared_examples
'filter examples'
do
it
'contains only matching projects and subgroups'
do
matching_project
=
create
(
:project
,
namespace:
group
,
name:
'Testproject'
)
matching_subgroup
=
create
(
:group
,
name:
'testgroup'
,
parent:
group
)
expect
(
finder
.
execute
).
to
contain_exactly
(
matching_subgroup
,
matching_project
)
end
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
)
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
)
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
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
,
:private
,
name:
'testgroup'
,
parent:
subgroup
)
context
'with matching children'
do
it
'includes a group that has a subgroup matching the query and its parent'
do
matching_subgroup
=
create
(
:group
,
:private
,
name:
'testgroup'
,
parent:
subgroup
)
expect
(
finder
.
execute
).
to
contain_exactly
(
subgroup
,
matching_subgroup
)
end
expect
(
finder
.
execute
).
to
contain_exactly
(
subgroup
,
matching_subgroup
)
end
it
'includes the parent of a matching project'
do
matching_project
=
create
(
:project
,
namespace:
subgroup
,
name:
'Testproject'
)
it
'includes the parent of a matching project'
do
matching_project
=
create
(
:project
,
namespace:
subgroup
,
name:
'Testproject'
)
expect
(
finder
.
execute
).
to
contain_exactly
(
subgroup
,
matching_project
)
end
expect
(
finder
.
execute
).
to
contain_exactly
(
subgroup
,
matching_project
)
end
context
'with a small page size'
do
let
(
:params
)
{
{
filter:
'test'
,
per_page:
1
}
}
it
'contains all the ancestors of a matching subgroup regardless the page size'
do
subgroup
=
create
(
:group
,
:private
,
parent:
group
)
matching
=
create
(
:group
,
:private
,
name:
'testgroup'
,
parent:
subgroup
)
context
'with a small page size'
do
let
(
:params
)
{
{
filter:
'test'
,
per_page:
1
}
}
expect
(
finder
.
execute
).
to
contain_exactly
(
subgroup
,
matching
)
end
end
it
'contains all the ancestors of a matching subgroup regardless the page size'
do
subgroup
=
create
(
:group
,
:private
,
parent:
group
)
matching
=
create
(
:group
,
:private
,
name:
'testgroup'
,
parent:
subgroup
)
it
'does not include the parent itself'
do
group
.
update!
(
name:
'test'
)
expect
(
finder
.
execute
).
to
contain_exactly
(
subgroup
,
matching
)
expect
(
finder
.
execute
).
not_to
include
(
group
)
end
end
end
it
'does not include the parent itself'
do
group
.
update!
(
name:
'test'
)
it_behaves_like
'filter examples'
expect
(
finder
.
execute
).
not_to
include
(
group
)
context
'when feature flag :linear_group_descendants_finder_upto is disabled'
do
before
do
stub_feature_flags
(
linear_group_descendants_finder_upto:
false
)
end
it_behaves_like
'filter examples'
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