From 1bf33272cc88a6ec24bae46de9f562e28b972a0b Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Fri, 6 Jul 2018 09:35:49 -0300 Subject: [PATCH] Fix strange behavior at users.setPreferences REST API --- packages/rocketchat-api/server/v1/users.js | 23 ++++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/rocketchat-api/server/v1/users.js b/packages/rocketchat-api/server/v1/users.js index 4968333125577..1a9ce262f64af 100644 --- a/packages/rocketchat-api/server/v1/users.js +++ b/packages/rocketchat-api/server/v1/users.js @@ -352,26 +352,23 @@ RocketChat.API.v1.addRoute('users.setPreferences', { authRequired: true }, { }) }); - let preferences; const userId = this.bodyParams.userId ? this.bodyParams.userId : this.userId; + const userData = { + _id: userId, + settings: { + preferences: this.bodyParams.data + } + }; + if (this.bodyParams.data.language) { const language = this.bodyParams.data.language; delete this.bodyParams.data.language; - preferences = _.extend({ _id: userId, settings: { preferences: this.bodyParams.data }, language }); - } else { - preferences = _.extend({ _id: userId, settings: { preferences: this.bodyParams.data } }); - } - - // Keep compatibility with old values - if (preferences.emailNotificationMode === 'all') { - preferences.emailNotificationMode = 'mentions'; - } else if (preferences.emailNotificationMode === 'disabled') { - preferences.emailNotificationMode = 'nothing'; + userData.language = language; } - Meteor.runAsUser(this.userId, () => RocketChat.saveUser(this.userId, preferences)); + Meteor.runAsUser(this.userId, () => RocketChat.saveUser(this.userId, userData)); - return RocketChat.API.v1.success({ user: RocketChat.models.Users.findOneById(this.bodyParams.userId, { fields: preferences }) }); + return RocketChat.API.v1.success({ user: RocketChat.models.Users.findOneById(this.bodyParams.userId, { fields: 'settings.preferences' }) }); } });