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
Boxiang Sun
gitlab-ce
Commits
22fe2fb4
Commit
22fe2fb4
authored
Apr 02, 2019
by
Peter Marko
Committed by
James Lopez
Apr 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix group transfer selection possibilities
parent
ba23d637
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
2 deletions
+49
-2
app/finders/groups_finder.rb
app/finders/groups_finder.rb
+8
-0
app/helpers/groups_helper.rb
app/helpers/groups_helper.rb
+3
-2
changelogs/unreleased/fix-transfer-group-possibilities.yml
changelogs/unreleased/fix-transfer-group-possibilities.yml
+5
-0
spec/helpers/groups_helper_spec.rb
spec/helpers/groups_helper_spec.rb
+33
-0
No files found.
app/finders/groups_finder.rb
View file @
22fe2fb4
...
...
@@ -11,6 +11,7 @@
# parent: Group
# all_available: boolean (defaults to true)
# min_access_level: integer
# exclude_group_ids: array of integers
#
# Users with full private access can see all groups. The `owned` and `parent`
# params can be used to restrict the groups that are returned.
...
...
@@ -29,6 +30,7 @@ class GroupsFinder < UnionFinder
items
=
all_groups
.
map
do
|
item
|
item
=
by_parent
(
item
)
item
=
by_custom_attributes
(
item
)
item
=
exclude_group_ids
(
item
)
item
end
...
...
@@ -72,6 +74,12 @@ class GroupsFinder < UnionFinder
end
# rubocop: enable CodeReuse/ActiveRecord
def
exclude_group_ids
(
groups
)
return
groups
unless
params
[
:exclude_group_ids
]
groups
.
id_not_in
(
params
[
:exclude_group_ids
])
end
# rubocop: disable CodeReuse/ActiveRecord
def
by_parent
(
groups
)
return
groups
unless
params
[
:parent
]
...
...
app/helpers/groups_helper.rb
View file @
22fe2fb4
...
...
@@ -118,11 +118,12 @@ module GroupsHelper
end
def
parent_group_options
(
current_group
)
groups
=
current_user
.
owned_groups
.
sort_by
(
&
:human_name
).
map
do
|
group
|
exclude_groups
=
current_group
.
self_and_descendants
.
pluck_primary_key
exclude_groups
<<
current_group
.
parent_id
if
current_group
.
parent_id
groups
=
GroupsFinder
.
new
(
current_user
,
min_access_level:
Gitlab
::
Access
::
OWNER
,
exclude_group_ids:
exclude_groups
).
execute
.
sort_by
(
&
:human_name
).
map
do
|
group
|
{
id:
group
.
id
,
text:
group
.
human_name
}
end
groups
.
delete_if
{
|
group
|
group
[
:id
]
==
current_group
.
id
}
groups
.
to_json
end
...
...
changelogs/unreleased/fix-transfer-group-possibilities.yml
0 → 100644
View file @
22fe2fb4
---
title
:
Fix group transfer selection possibilities
merge_request
:
26123
author
:
Peter Marko
type
:
fixed
spec/helpers/groups_helper_spec.rb
View file @
22fe2fb4
...
...
@@ -229,4 +229,37 @@ describe GroupsHelper do
expect
(
helper
.
group_sidebar_links
).
not_to
include
(
*
cross_project_features
)
end
end
describe
'parent_group_options'
,
:nested_groups
do
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
,
name:
'group'
)
}
let
(
:group2
)
{
create
(
:group
,
name:
'group2'
)
}
before
do
group
.
add_owner
(
current_user
)
group2
.
add_owner
(
current_user
)
end
it
'includes explicitly owned groups except self'
do
expect
(
parent_group_options
(
group2
)).
to
eq
([{
id:
group
.
id
,
text:
group
.
human_name
}].
to_json
)
end
it
'excludes parent group'
do
subgroup
=
create
(
:group
,
parent:
group2
)
expect
(
parent_group_options
(
subgroup
)).
to
eq
([{
id:
group
.
id
,
text:
group
.
human_name
}].
to_json
)
end
it
'includes subgroups with inherited ownership'
do
subgroup
=
create
(
:group
,
parent:
group
)
expect
(
parent_group_options
(
group2
)).
to
eq
([{
id:
group
.
id
,
text:
group
.
human_name
},
{
id:
subgroup
.
id
,
text:
subgroup
.
human_name
}].
to_json
)
end
it
'excludes own subgroups'
do
create
(
:group
,
parent:
group2
)
expect
(
parent_group_options
(
group2
)).
to
eq
([{
id:
group
.
id
,
text:
group
.
human_name
}].
to_json
)
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