mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +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'); | ||||
|  | ||||
| 		const image = await user.uploadCroppedPictureFile({ | ||||
| 			callerUid: req.uid, | ||||
| 			uid: updateUid, | ||||
| 			file: userPhoto, | ||||
| 		}); | ||||
|   | ||||
| @@ -38,10 +38,11 @@ module.exports = function (SocketUser) { | ||||
| 			data.bgColor = validBackgrounds[0]; | ||||
| 		} | ||||
|  | ||||
| 		await user.setUserFields(data.uid, { | ||||
| 			picture, | ||||
| 		await user.updateProfile(socket.uid, { | ||||
| 			uid: data.uid, | ||||
| 			picture: picture, | ||||
| 			'icon:bgColor': data.bgColor, | ||||
| 		}); | ||||
| 		}, ['picture', 'icon:bgColor']); | ||||
| 	}; | ||||
|  | ||||
| 	SocketUser.removeUploadedPicture = async function (socket, data) { | ||||
|   | ||||
| @@ -108,10 +108,11 @@ module.exports = function (User) { | ||||
| 		}); | ||||
|  | ||||
| 		await deleteCurrentPicture(data.uid, 'uploadedpicture'); | ||||
| 		await User.setUserFields(data.uid, { | ||||
| 		await User.updateProfile(data.callerUid, { | ||||
| 			uid: data.uid, | ||||
| 			uploadedpicture: uploadedImage.url, | ||||
| 			picture: uploadedImage.url, | ||||
| 		}); | ||||
| 		}, ['uploadedpicture', 'picture']); | ||||
| 		return uploadedImage; | ||||
| 	}; | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
|  | ||||
| 'use strict'; | ||||
|  | ||||
| const _ = require('lodash'); | ||||
| const async = require('async'); | ||||
| const validator = require('validator'); | ||||
| const winston = require('winston'); | ||||
| @@ -13,11 +14,14 @@ const groups = require('../groups'); | ||||
| const plugins = require('../plugins'); | ||||
|  | ||||
| module.exports = function (User) { | ||||
| 	User.updateProfile = async function (uid, data) { | ||||
| 	User.updateProfile = async function (uid, data, extraFields) { | ||||
| 		let fields = [ | ||||
| 			'username', 'email', 'fullname', 'website', 'location', | ||||
| 			'groupTitle', 'birthday', 'signature', 'aboutme', | ||||
| 		]; | ||||
| 		if (Array.isArray(extraFields)) { | ||||
| 			fields = _.uniq(fields.concat(extraFields)); | ||||
| 		} | ||||
| 		if (!data.uid) { | ||||
| 			throw new Error('[[error:invalid-update-uid]]'); | ||||
| 		} | ||||
|   | ||||
| @@ -871,7 +871,7 @@ describe('User', () => { | ||||
| 					signature: 'nodebb is good', | ||||
| 					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.equal(result.username, 'updatedUserName'); | ||||
| @@ -887,6 +887,8 @@ describe('User', () => { | ||||
| 								assert(userData[key].startsWith('$2a$')); | ||||
| 							} | ||||
| 						}); | ||||
| 						// updateProfile only saves valid fields | ||||
| 						assert.strictEqual(userData.invalid, undefined); | ||||
| 						done(); | ||||
| 					}); | ||||
| 				}); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user