mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: use updateProfile for picture change
so it triggers action:user:updateProfile
This commit is contained in:
@@ -134,6 +134,7 @@ editController.uploadPicture = async function (req, res, next) {
|
|||||||
await user.checkMinReputation(req.uid, updateUid, 'min:rep:profile-picture');
|
await user.checkMinReputation(req.uid, updateUid, 'min:rep:profile-picture');
|
||||||
|
|
||||||
const image = await user.uploadCroppedPictureFile({
|
const image = await user.uploadCroppedPictureFile({
|
||||||
|
callerUid: req.uid,
|
||||||
uid: updateUid,
|
uid: updateUid,
|
||||||
file: userPhoto,
|
file: userPhoto,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -38,10 +38,11 @@ module.exports = function (SocketUser) {
|
|||||||
data.bgColor = validBackgrounds[0];
|
data.bgColor = validBackgrounds[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
await user.setUserFields(data.uid, {
|
await user.updateProfile(socket.uid, {
|
||||||
picture,
|
uid: data.uid,
|
||||||
|
picture: picture,
|
||||||
'icon:bgColor': data.bgColor,
|
'icon:bgColor': data.bgColor,
|
||||||
});
|
}, ['picture', 'icon:bgColor']);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.removeUploadedPicture = async function (socket, data) {
|
SocketUser.removeUploadedPicture = async function (socket, data) {
|
||||||
|
|||||||
@@ -108,10 +108,11 @@ module.exports = function (User) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await deleteCurrentPicture(data.uid, 'uploadedpicture');
|
await deleteCurrentPicture(data.uid, 'uploadedpicture');
|
||||||
await User.setUserFields(data.uid, {
|
await User.updateProfile(data.callerUid, {
|
||||||
|
uid: data.uid,
|
||||||
uploadedpicture: uploadedImage.url,
|
uploadedpicture: uploadedImage.url,
|
||||||
picture: uploadedImage.url,
|
picture: uploadedImage.url,
|
||||||
});
|
}, ['uploadedpicture', 'picture']);
|
||||||
return uploadedImage;
|
return uploadedImage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const _ = require('lodash');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
const validator = require('validator');
|
const validator = require('validator');
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
@@ -13,11 +14,14 @@ const groups = require('../groups');
|
|||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
|
||||||
module.exports = function (User) {
|
module.exports = function (User) {
|
||||||
User.updateProfile = async function (uid, data) {
|
User.updateProfile = async function (uid, data, extraFields) {
|
||||||
let fields = [
|
let fields = [
|
||||||
'username', 'email', 'fullname', 'website', 'location',
|
'username', 'email', 'fullname', 'website', 'location',
|
||||||
'groupTitle', 'birthday', 'signature', 'aboutme',
|
'groupTitle', 'birthday', 'signature', 'aboutme',
|
||||||
];
|
];
|
||||||
|
if (Array.isArray(extraFields)) {
|
||||||
|
fields = _.uniq(fields.concat(extraFields));
|
||||||
|
}
|
||||||
if (!data.uid) {
|
if (!data.uid) {
|
||||||
throw new Error('[[error:invalid-update-uid]]');
|
throw new Error('[[error:invalid-update-uid]]');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -871,7 +871,7 @@ describe('User', () => {
|
|||||||
signature: 'nodebb is good',
|
signature: 'nodebb is good',
|
||||||
password: '123456',
|
password: '123456',
|
||||||
};
|
};
|
||||||
socketUser.updateProfile({ uid: uid }, { ...data, password: '123456' }, (err, result) => {
|
socketUser.updateProfile({ uid: uid }, { ...data, password: '123456', invalid: 'field' }, (err, result) => {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
assert.equal(result.username, 'updatedUserName');
|
assert.equal(result.username, 'updatedUserName');
|
||||||
@@ -887,6 +887,8 @@ describe('User', () => {
|
|||||||
assert(userData[key].startsWith('$2a$'));
|
assert(userData[key].startsWith('$2a$'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// updateProfile only saves valid fields
|
||||||
|
assert.strictEqual(userData.invalid, undefined);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user