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
098440b9
Commit
098440b9
authored
Jan 13, 2021
by
Jackie Fraser
Committed by
Gabriel Mazetto
Jan 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve User username error for namespace conflict
parent
86a789cd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
3 deletions
+16
-3
app/models/user.rb
app/models/user.rb
+8
-1
changelogs/unreleased/215309-improve-the-error-message-username-has-already-been-taken-on-user-.yml
...rror-message-username-has-already-been-taken-on-user-.yml
+5
-0
config/locales/en.yml
config/locales/en.yml
+1
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+1
-1
spec/services/users/update_service_spec.rb
spec/services/users/update_service_spec.rb
+1
-1
No files found.
app/models/user.rb
View file @
098440b9
...
...
@@ -1377,7 +1377,14 @@ class User < ApplicationRecord
def
set_username_errors
namespace_path_errors
=
self
.
errors
.
delete
(
:"namespace.path"
)
self
.
errors
[
:username
].
concat
(
namespace_path_errors
)
if
namespace_path_errors
return
unless
namespace_path_errors
&
.
any?
if
namespace_path_errors
.
include?
(
'has already been taken'
)
&&
!
User
.
exists?
(
username:
username
)
self
.
errors
.
add
(
:base
,
:username_exists_as_a_different_namespace
)
else
self
.
errors
[
:username
].
concat
(
namespace_path_errors
)
end
end
def
username_changed_hook
...
...
changelogs/unreleased/215309-improve-the-error-message-username-has-already-been-taken-on-user-.yml
0 → 100644
View file @
098440b9
---
title
:
Improve error message when username and namespace conflict
merge_request
:
47537
author
:
type
:
changed
config/locales/en.yml
View file @
098440b9
...
...
@@ -169,6 +169,7 @@ en:
format
:
"
%{attribute}
%{message}"
messages
:
label_already_exists_at_group_level
:
"
already
exists
at
group
level
for
%{group}.
Please
choose
another
one."
username_exists_as_a_different_namespace
:
A user, alias, or group already exists with that username.
wrong_size
:
"
is
the
wrong
size
(should
be
%{file_size})"
size_too_small
:
"
is
too
small
(should
be
at
least
%{file_size})"
size_too_big
:
"
is
too
big
(should
be
at
most
%{file_size})"
...
...
spec/models/user_spec.rb
View file @
098440b9
...
...
@@ -4280,7 +4280,7 @@ RSpec.describe User do
it
'adds the namespace errors to the user'
do
user
.
update
(
username:
new_username
)
expect
(
user
.
errors
.
full_messages
.
first
).
to
eq
(
'
Username has already been taken
'
)
expect
(
user
.
errors
.
full_messages
.
first
).
to
eq
(
'
A user, alias, or group already exists with that username.
'
)
end
end
end
...
...
spec/services/users/update_service_spec.rb
View file @
098440b9
...
...
@@ -31,7 +31,7 @@ RSpec.describe Users::UpdateService do
result
=
update_user
(
user
,
{
username:
'taken'
})
end
.
not_to
change
{
user
.
reload
.
username
}
expect
(
result
[
:status
]).
to
eq
(
:error
)
expect
(
result
[
:message
]).
to
eq
(
'
Username has already been taken
'
)
expect
(
result
[
:message
]).
to
eq
(
'
A user, alias, or group already exists with that username.
'
)
end
it
'updates the status if status params were given'
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