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
852b5613
Commit
852b5613
authored
Jul 31, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix namespaces_helper reporting multiple groups
parent
0085b76f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
app/helpers/namespaces_helper.rb
app/helpers/namespaces_helper.rb
+5
-2
spec/helpers/namespaces_helper_spec.rb
spec/helpers/namespaces_helper_spec.rb
+9
-0
No files found.
app/helpers/namespaces_helper.rb
View file @
852b5613
...
...
@@ -14,8 +14,11 @@ module NamespacesHelper
extra_group
=
Group
.
find
(
extra_group
)
if
Namespace
.
find
(
extra_group
).
kind
==
'group'
end
if
extra_group
&&
extra_group
.
is_a?
(
Group
)
&&
(
!
Group
.
exists?
(
name:
extra_group
.
name
)
||
Ability
.
allowed?
(
current_user
,
:read_group
,
extra_group
))
groups
|=
[
extra_group
]
if
extra_group
&&
extra_group
.
is_a?
(
Group
)
# Avoid duplicate groups if one already exists by that name
existing_group
=
Group
.
find_by
(
name:
extra_group
.
name
)
extra_group
=
existing_group
if
existing_group
groups
|=
[
extra_group
]
if
Ability
.
allowed?
(
current_user
,
:read_group
,
extra_group
)
end
options
=
[]
...
...
spec/helpers/namespaces_helper_spec.rb
View file @
852b5613
...
...
@@ -31,6 +31,15 @@ describe NamespacesHelper do
expect
(
options
).
to
include
(
user
.
name
)
end
it
'avoids duplicate groups when extra_group is used'
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
admin
)
options
=
helper
.
namespaces_options
(
user_group
.
id
,
display_path:
true
,
extra_group:
build
(
:group
,
name:
admin_group
.
name
))
expect
(
options
.
scan
(
"data-name=
\"
#{
admin_group
.
name
}
\"
"
).
count
).
to
eq
(
1
)
expect
(
options
).
to
include
(
admin_group
.
name
)
end
it
'returns only groups if groups_only option is true'
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
...
...
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