mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #10069, don't modify fields array
use a single setObjectFields for the profile update
This commit is contained in:
@@ -52,11 +52,15 @@ module.exports = function (User) {
|
|||||||
uids = uids.map(uid => (isNaN(uid) ? 0 : parseInt(uid, 10)));
|
uids = uids.map(uid => (isNaN(uid) ? 0 : parseInt(uid, 10)));
|
||||||
|
|
||||||
const fieldsToRemove = [];
|
const fieldsToRemove = [];
|
||||||
|
fields = fields.slice();
|
||||||
ensureRequiredFields(fields, fieldsToRemove);
|
ensureRequiredFields(fields, fieldsToRemove);
|
||||||
|
|
||||||
const uniqueUids = _.uniq(uids).filter(uid => uid > 0);
|
const uniqueUids = _.uniq(uids).filter(uid => uid > 0);
|
||||||
|
|
||||||
const results = await plugins.hooks.fire('filter:user.whitelistFields', { uids: uids, whitelist: fieldWhitelist.slice() });
|
const results = await plugins.hooks.fire('filter:user.whitelistFields', {
|
||||||
|
uids: uids,
|
||||||
|
whitelist: fieldWhitelist.slice(),
|
||||||
|
});
|
||||||
if (!fields.length) {
|
if (!fields.length) {
|
||||||
fields = results.whitelist;
|
fields = results.whitelist;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const async = require('async');
|
|
||||||
const validator = require('validator');
|
const validator = require('validator');
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
|
|
||||||
@@ -38,8 +37,8 @@ module.exports = function (User) {
|
|||||||
await validateData(uid, data);
|
await validateData(uid, data);
|
||||||
|
|
||||||
const oldData = await User.getUserFields(updateUid, fields);
|
const oldData = await User.getUserFields(updateUid, fields);
|
||||||
|
const updateData = {};
|
||||||
await async.each(fields, async (field) => {
|
await Promise.all(fields.map(async (field) => {
|
||||||
if (!(data[field] !== undefined && typeof data[field] === 'string')) {
|
if (!(data[field] !== undefined && typeof data[field] === 'string')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -53,9 +52,12 @@ module.exports = function (User) {
|
|||||||
} else if (field === 'fullname') {
|
} else if (field === 'fullname') {
|
||||||
return await updateFullname(updateUid, data.fullname);
|
return await updateFullname(updateUid, data.fullname);
|
||||||
}
|
}
|
||||||
|
updateData[field] = data[field];
|
||||||
|
}));
|
||||||
|
|
||||||
await User.setUserField(updateUid, field, data[field]);
|
if (Object.keys(updateData).length) {
|
||||||
});
|
await User.setUserFields(updateUid, updateData);
|
||||||
|
}
|
||||||
|
|
||||||
plugins.hooks.fire('action:user.updateProfile', {
|
plugins.hooks.fire('action:user.updateProfile', {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
|
|||||||
@@ -724,6 +724,12 @@ describe('User', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not modify the fields array passed in', async () => {
|
||||||
|
const fields = ['username', 'email'];
|
||||||
|
await User.getUserFields(testUid, fields);
|
||||||
|
assert.deepStrictEqual(fields, ['username', 'email']);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return an icon text and valid background if username and picture is explicitly requested', async () => {
|
it('should return an icon text and valid background if username and picture is explicitly requested', async () => {
|
||||||
const payload = await User.getUserFields(testUid, ['username', 'picture']);
|
const payload = await User.getUserFields(testUid, ['username', 'picture']);
|
||||||
const validBackgrounds = await User.getIconBackgrounds(testUid);
|
const validBackgrounds = await User.getIconBackgrounds(testUid);
|
||||||
|
|||||||
Reference in New Issue
Block a user