BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
03755fb3
Commit
03755fb3
authored
Nov 21, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ee-flog' into 'master'
Reduce method complexity in AutocompleteController Backport of gitlab-org/gitlab-ee!58 See merge request !1833
parents
94b90db5
5a4c56c3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
31 deletions
+27
-31
autocomplete_controller.rb
app/controllers/autocomplete_controller.rb
+22
-27
autocomplete_controller_spec.rb
spec/controllers/autocomplete_controller_spec.rb
+5
-4
No files found.
app/controllers/autocomplete_controller.rb
View file @
03755fb3
class
AutocompleteController
<
ApplicationController
skip_before_action
:authenticate_user!
,
only:
[
:users
]
before_action
:find_users
,
only:
[
:users
]
def
users
begin
@users
=
if
params
[
:project_id
].
present?
project
=
Project
.
find
(
params
[
:project_id
])
if
can?
(
current_user
,
:read_project
,
project
)
project
.
team
.
users
end
elsif
params
[
:group_id
]
group
=
Group
.
find
(
params
[
:group_id
])
if
can?
(
current_user
,
:read_group
,
group
)
group
.
users
end
elsif
current_user
User
.
all
end
rescue
ActiveRecord
::
RecordNotFound
if
current_user
return
render
json:
{},
status:
404
end
end
if
@users
.
nil?
&&
current_user
.
nil?
authenticate_user!
end
@users
||=
User
.
none
@users
=
@users
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@users
=
@users
.
active
...
...
@@ -49,4 +23,25 @@ class AutocompleteController < ApplicationController
@user
=
User
.
find
(
params
[
:id
])
render
json:
@user
,
only:
[
:name
,
:username
,
:id
],
methods:
[
:avatar_url
]
end
private
def
find_users
@users
=
if
params
[
:project_id
].
present?
project
=
Project
.
find
(
params
[
:project_id
])
return
render_404
unless
can?
(
current_user
,
:read_project
,
project
)
project
.
team
.
users
elsif
params
[
:group_id
].
present?
group
=
Group
.
find
(
params
[
:group_id
])
return
render_404
unless
can?
(
current_user
,
:read_group
,
group
)
group
.
users
elsif
current_user
User
.
all
else
User
.
none
end
end
end
spec/controllers/autocomplete_controller_spec.rb
View file @
03755fb3
...
...
@@ -114,7 +114,7 @@ describe AutocompleteController do
get
(
:users
,
project_id:
project
.
id
)
end
it
{
expect
(
response
.
status
).
to
eq
(
302
)
}
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
end
describe
'GET #users with unknown project'
do
...
...
@@ -122,7 +122,7 @@ describe AutocompleteController do
get
(
:users
,
project_id:
'unknown'
)
end
it
{
expect
(
response
.
status
).
to
eq
(
302
)
}
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
end
describe
'GET #users with inaccessible group'
do
...
...
@@ -131,7 +131,7 @@ describe AutocompleteController do
get
(
:users
,
group_id:
user
.
namespace
.
id
)
end
it
{
expect
(
response
.
status
).
to
eq
(
302
)
}
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
end
describe
'GET #users with no project'
do
...
...
@@ -139,7 +139,8 @@ describe AutocompleteController do
get
(
:users
)
end
it
{
expect
(
response
.
status
).
to
eq
(
302
)
}
it
{
expect
(
body
).
to
be_kind_of
(
Array
)
}
it
{
expect
(
body
.
size
).
to
eq
0
}
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