Skip to content
Snippets Groups Projects
Commit 6cfc53ff authored by Marcos Spessatto Defendi's avatar Marcos Spessatto Defendi Committed by Rodrigo Nascimento
Browse files

Fix REST users.updateOwnBasicInfo, disallow names with whitespaces and save...

Fix REST users.updateOwnBasicInfo, disallow names with whitespaces and save custom fields only if it is necessary (#11204)

[FIX] REST endpoint `users.updateOwnBasicInfo` was not returning errors for invalid names and trying to save custom fields when empty
parent 93bc5c69
No related branches found
No related tags found
No related merge requests found
Meteor.methods({
saveUserProfile(settings, customFields) {
check(settings, Object);
check(customFields, Match.Maybe(Object));
if (!RocketChat.settings.get('Accounts_AllowUserProfileChange')) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
......@@ -33,7 +34,9 @@ Meteor.methods({
}
if (settings.realname) {
RocketChat.setRealName(Meteor.userId(), settings.realname);
if (!RocketChat.setRealName(Meteor.userId(), settings.realname)) {
throw new Meteor.Error('error-could-not-change-name', 'Could not change name', { method: 'saveUserProfile' });
}
}
if (settings.username) {
......@@ -67,7 +70,9 @@ Meteor.methods({
RocketChat.models.Users.setProfile(Meteor.userId(), {});
RocketChat.saveCustomFields(Meteor.userId(), customFields);
if (customFields && Object.keys(customFields).length) {
RocketChat.saveCustomFields(Meteor.userId(), customFields);
}
return true;
}
......
......@@ -396,6 +396,22 @@ describe('[Users]', function() {
.end(done);
});
it('should throw an error when the name is only whitespaces', (done) => {
request.post(api('users.updateOwnBasicInfo'))
.set(credentials)
.send({
data: {
name: ' '
}
})
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
})
.end(done);
});
it('should set new email as \'unverified\'', (done) => {
request.post(api('users.updateOwnBasicInfo'))
.set(userCredentials)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment