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
Jérome Perrin
gitlab-ce
Commits
574b3efd
Commit
574b3efd
authored
Jul 14, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes the user order being overriden in the autocomplete controller
parent
60b91b46
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
6 deletions
+25
-6
app/controllers/autocomplete_controller.rb
app/controllers/autocomplete_controller.rb
+2
-2
app/models/user.rb
app/models/user.rb
+1
-1
changelogs/unreleased/fix-exact-matches-of-username-and-email-on-top-of-the-user-search.yml
...tches-of-username-and-email-on-top-of-the-user-search.yml
+4
-0
spec/controllers/autocomplete_controller_spec.rb
spec/controllers/autocomplete_controller_spec.rb
+15
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+3
-3
No files found.
app/controllers/autocomplete_controller.rb
View file @
574b3efd
...
@@ -5,10 +5,10 @@ class AutocompleteController < ApplicationController
...
@@ -5,10 +5,10 @@ class AutocompleteController < ApplicationController
def
users
def
users
@users
||=
User
.
none
@users
||=
User
.
none
@users
=
@users
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@users
=
@users
.
where
.
not
(
id:
params
[
:skip_users
])
if
params
[
:skip_users
].
present?
@users
=
@users
.
active
@users
=
@users
.
active
@users
=
@users
.
reorder
(
:name
)
@users
=
@users
.
reorder
(
:name
)
@users
=
@users
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@users
=
@users
.
where
.
not
(
id:
params
[
:skip_users
])
if
params
[
:skip_users
].
present?
@users
=
@users
.
page
(
params
[
:page
]).
per
(
params
[
:per_page
])
@users
=
@users
.
page
(
params
[
:page
]).
per
(
params
[
:per_page
])
if
params
[
:todo_filter
].
present?
&&
current_user
if
params
[
:todo_filter
].
present?
&&
current_user
...
...
app/models/user.rb
View file @
574b3efd
...
@@ -314,7 +314,7 @@ class User < ActiveRecord::Base
...
@@ -314,7 +314,7 @@ class User < ActiveRecord::Base
table
[
:name
].
matches
(
pattern
)
table
[
:name
].
matches
(
pattern
)
.
or
(
table
[
:email
].
matches
(
pattern
))
.
or
(
table
[
:email
].
matches
(
pattern
))
.
or
(
table
[
:username
].
matches
(
pattern
))
.
or
(
table
[
:username
].
matches
(
pattern
))
).
reorder
(
order
%
{
query:
ActiveRecord
::
Base
.
connection
.
quote
(
query
)
},
id: :desc
)
).
reorder
(
order
%
{
query:
ActiveRecord
::
Base
.
connection
.
quote
(
query
)
},
:name
)
end
end
# searches user by given pattern
# searches user by given pattern
...
...
changelogs/unreleased/fix-exact-matches-of-username-and-email-on-top-of-the-user-search.yml
0 → 100644
View file @
574b3efd
---
title
:
Exact matches of username and email are now on top of the user search
merge_request
:
12868
author
:
spec/controllers/autocomplete_controller_spec.rb
View file @
574b3efd
...
@@ -97,6 +97,21 @@ describe AutocompleteController do
...
@@ -97,6 +97,21 @@ describe AutocompleteController do
it
{
expect
(
body
.
size
).
to
eq
User
.
count
}
it
{
expect
(
body
.
size
).
to
eq
User
.
count
}
end
end
context
'user order'
do
it
'shows exact matches first'
do
reported_user
=
create
(
:user
,
username:
'reported_user'
,
name:
'Doug'
)
user
=
create
(
:user
,
username:
'user'
,
name:
'User'
)
user1
=
create
(
:user
,
username:
'user1'
,
name:
'Ian'
)
sign_in
(
user
)
get
(
:users
,
search:
'user'
)
response_usernames
=
JSON
.
parse
(
response
.
body
).
map
{
|
user
|
user
[
'username'
]
}
expect
(
response_usernames
.
take
(
3
)).
to
match_array
([
user
.
username
,
reported_user
.
username
,
user1
.
username
])
end
end
context
'limited users per page'
do
context
'limited users per page'
do
let
(
:per_page
)
{
2
}
let
(
:per_page
)
{
2
}
...
...
spec/models/user_spec.rb
View file @
574b3efd
...
@@ -763,7 +763,7 @@ describe User, models: true do
...
@@ -763,7 +763,7 @@ describe User, models: true do
end
end
it
'returns users with a partially matching name'
do
it
'returns users with a partially matching name'
do
expect
(
described_class
.
search
(
user
.
name
[
0
..
2
])).
to
eq
([
user
2
,
user
])
expect
(
described_class
.
search
(
user
.
name
[
0
..
2
])).
to
eq
([
user
,
user2
])
end
end
it
'returns users with a matching name regardless of the casing'
do
it
'returns users with a matching name regardless of the casing'
do
...
@@ -777,7 +777,7 @@ describe User, models: true do
...
@@ -777,7 +777,7 @@ describe User, models: true do
end
end
it
'returns users with a partially matching Email'
do
it
'returns users with a partially matching Email'
do
expect
(
described_class
.
search
(
user
.
email
[
0
..
2
])).
to
eq
([
user
2
,
user
])
expect
(
described_class
.
search
(
user
.
email
[
0
..
2
])).
to
eq
([
user
,
user2
])
end
end
it
'returns users with a matching Email regardless of the casing'
do
it
'returns users with a matching Email regardless of the casing'
do
...
@@ -791,7 +791,7 @@ describe User, models: true do
...
@@ -791,7 +791,7 @@ describe User, models: true do
end
end
it
'returns users with a partially matching username'
do
it
'returns users with a partially matching username'
do
expect
(
described_class
.
search
(
user
.
username
[
0
..
2
])).
to
eq
([
user
2
,
user
])
expect
(
described_class
.
search
(
user
.
username
[
0
..
2
])).
to
eq
([
user
,
user2
])
end
end
it
'returns users with a matching username regardless of the casing'
do
it
'returns users with a matching username regardless of the casing'
do
...
...
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