Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVE] Wrong error message when trying to create a blocked username #22452

Merged
merged 6 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/lib/server/functions/checkUsernameAvailability.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Meteor } from 'meteor/meteor';
import s from 'underscore.string';
import _ from 'underscore';
import { escapeRegExp } from '@rocket.chat/string-helpers';

import { settings } from '../../../settings';
Expand All @@ -19,7 +20,7 @@ const usernameIsBlocked = (username, usernameBlackList) => usernameBlackList.len

export const checkUsernameAvailability = function(username) {
if (usernameIsBlocked(username, usernameBlackList) || !validateName(username)) {
return false;
throw new Meteor.Error('error-blocked-username', `${ _.escape(username) } is blocked and can't be used!`, { method: 'checkUsernameAvailability', field: username });
}

// Make sure no users are using this username
Expand Down
7 changes: 6 additions & 1 deletion app/ui-login/client/username/username.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
<h2>{{_ "Username_title"}}</h2>
<p>{{_ "Username_description"}}</p>
</header>
{{#if username.error}}
{{#if username.blocked}}
<div class="alert error-color error-background error-border">
{{{_ "error-blocked-username" field=username.escaped}}}
</div>
{{/if}}
{{#if username.unavailable}}
<div class="alert error-color error-background error-border">
{{{_ "error-field-unavailable" field=username.escaped}}}
</div>
Expand Down
5 changes: 3 additions & 2 deletions app/ui-login/client/username/username.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ Template.username.events({

return Meteor.call('setUsername', value, function(err) {
if (err != null) {
console.log(err);
if (err.error === 'username-invalid') {
username.invalid = true;
} else if (err.error === 'error-blocked-username') {
username.blocked = true;
} else {
username.error = true;
username.unavailable = true;
}
username.username = value;
username.escaped = _.escape(value);
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,7 @@
"error-avatar-invalid-url": "Invalid avatar URL: __url__",
"error-avatar-url-handling": "Error while handling avatar setting from a URL (__url__) for __username__",
"error-business-hours-are-closed": "Business Hours are closed",
"error-blocked-username": "<strong>__field__</strong> is blocked and can't be used!",
"error-canned-response-not-found": "Canned Response Not Found",
"error-cannot-delete-app-user": "Deleting app user is not allowed, uninstall the corresponding app to remove it.",
"error-cant-invite-for-direct-room": "Can't invite user to direct rooms",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,7 @@
"error-archived-duplicate-name": "Já há um canal arquivado com o nome '__room_name__'",
"error-avatar-invalid-url": "URL inválida de avatar: __url__",
"error-avatar-url-handling": "Erro durante o manuseio configuração avatar a partir de uma URL (__url__) para __username__",
"error-blocked-username": "<strong>__field__</strong> está bloqueado e não pode ser usado!",
"error-business-hours-are-closed": "Horário de expediente fechado",
"error-cant-invite-for-direct-room": "Não é possível convidar usuários para salas diretas",
"error-channels-setdefault-is-same": "A configuração padrão do canal é a mesma que seria alterada.",
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/api/01-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ describe('[Users]', function() {
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error', `${ name } is already in use :( [error-field-unavailable]`);
expect(res.body).to.have.property('error', `${ name } is blocked and can't be used! [error-blocked-username]`);
})
.end(done);
});
Expand Down