Commit 95471a4d authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch...

Merge branch '215309-improve-the-error-message-username-has-already-been-taken-on-user-creation' into 'master'

Improve User username error for namespace conflict

See merge request gitlab-org/gitlab!47537
parents 1cc51c95 098440b9
......@@ -1378,7 +1378,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
......
---
title: Improve error message when username and namespace conflict
merge_request: 47537
author:
type: changed
......@@ -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})"
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment