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
b2277c71
Commit
b2277c71
authored
Oct 31, 2019
by
Alper Akgun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
"Suggests" API for uniquifying usernames
parent
eafd98ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
1 deletion
+52
-1
app/controllers/users_controller.rb
app/controllers/users_controller.rb
+9
-1
config/routes/user.rb
config/routes/user.rb
+1
-0
spec/controllers/users_controller_spec.rb
spec/controllers/users_controller_spec.rb
+42
-0
No files found.
app/controllers/users_controller.rb
View file @
b2277c71
...
...
@@ -16,7 +16,7 @@ class UsersController < ApplicationController
skip_before_action
:authenticate_user!
prepend_before_action
(
only:
[
:show
])
{
authenticate_sessionless_user!
(
:rss
)
}
before_action
:user
,
except:
[
:exists
]
before_action
:user
,
except:
[
:exists
,
:suggests
]
before_action
:authorize_read_user_profile!
,
only:
[
:calendar
,
:calendar_activities
,
:groups
,
:projects
,
:contributed_projects
,
:starred_projects
,
:snippets
]
...
...
@@ -114,6 +114,14 @@ class UsersController < ApplicationController
render
json:
{
exists:
!!
Namespace
.
find_by_path_or_name
(
params
[
:username
])
}
end
def
suggests
namespace_path
=
params
[
:username
]
exists
=
!!
Namespace
.
find_by_path_or_name
(
namespace_path
)
suggestions
=
exists
?
[
Namespace
.
clean_path
(
namespace_path
)]
:
[]
render
json:
{
exists:
exists
,
suggests:
suggestions
}
end
private
def
user
...
...
config/routes/user.rb
View file @
b2277c71
...
...
@@ -55,6 +55,7 @@ scope(constraints: { username: Gitlab::PathRegex.root_namespace_route_regex }) d
get
:starred
,
as: :starred_projects
get
:snippets
get
:exists
get
:suggests
get
:activity
get
'/'
,
to:
redirect
(
'%{username}'
),
as:
nil
end
...
...
spec/controllers/users_controller_spec.rb
View file @
b2277c71
...
...
@@ -348,6 +348,48 @@ describe UsersController do
end
end
describe
'GET #suggests'
do
context
'when user exists'
do
it
'returns JSON indicating the user exists and a suggestion'
do
get
:suggests
,
params:
{
username:
user
.
username
}
expected_json
=
{
exists:
true
,
suggests:
[
"
#{
user
.
username
}
1"
]
}.
to_json
expect
(
response
.
body
).
to
eq
(
expected_json
)
end
context
'when the casing is different'
do
let
(
:user
)
{
create
(
:user
,
username:
'CamelCaseUser'
)
}
it
'returns JSON indicating the user exists and a suggestion'
do
get
:suggests
,
params:
{
username:
user
.
username
.
downcase
}
expected_json
=
{
exists:
true
,
suggests:
[
"
#{
user
.
username
.
downcase
}
1"
]
}.
to_json
expect
(
response
.
body
).
to
eq
(
expected_json
)
end
end
end
context
'when the user does not exist'
do
it
'returns JSON indicating the user does not exist'
do
get
:suggests
,
params:
{
username:
'foo'
}
expected_json
=
{
exists:
false
,
suggests:
[]
}.
to_json
expect
(
response
.
body
).
to
eq
(
expected_json
)
end
context
'when a user changed their username'
do
let
(
:redirect_route
)
{
user
.
namespace
.
redirect_routes
.
create
(
path:
'old-username'
)
}
it
'returns JSON indicating a user by that username does not exist'
do
get
:suggests
,
params:
{
username:
'old-username'
}
expected_json
=
{
exists:
false
,
suggests:
[]
}.
to_json
expect
(
response
.
body
).
to
eq
(
expected_json
)
end
end
end
end
describe
'#ensure_canonical_path'
do
before
do
sign_in
(
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