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

* fix error message when creating an user with blocked username

* update tests

* fix i18n

* fix eslint error

Co-authored-by: dougfabris <devfabris@gmail.com>
pull/22405/head^2
Lucas Sartor Chauvin 4 years ago committed by GitHub
parent dee7b5f040
commit b9aa5a31bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/lib/server/functions/checkUsernameAvailability.js
  2. 7
      app/ui-login/client/username/username.html
  3. 5
      app/ui-login/client/username/username.js
  4. 1
      packages/rocketchat-i18n/i18n/en.i18n.json
  5. 1
      packages/rocketchat-i18n/i18n/pt-BR.i18n.json
  6. 2
      tests/end-to-end/api/01-users.js

@ -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';
@ -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

@ -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>

@ -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);

@ -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",

@ -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.",

@ -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);
});

Loading…
Cancel
Save