mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: change uploadCroppedPicture to use updateProfile as well
This commit is contained in:
@@ -36,6 +36,7 @@ module.exports = function (SocketUser) {
|
||||
}
|
||||
await user.isAdminOrGlobalModOrSelf(socket.uid, data.uid);
|
||||
await user.checkMinReputation(socket.uid, data.uid, 'min:rep:profile-picture');
|
||||
data.callerUid = socket.uid;
|
||||
return await user.uploadCroppedPicture(data);
|
||||
};
|
||||
|
||||
|
||||
@@ -148,10 +148,11 @@ module.exports = function (User) {
|
||||
const uploadedImage = await image.uploadImage(filename, 'profile', picture);
|
||||
|
||||
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;
|
||||
} finally {
|
||||
await file.delete(picture.path);
|
||||
|
||||
@@ -1156,6 +1156,7 @@ describe('User', () => {
|
||||
type: 'image/png',
|
||||
};
|
||||
User.uploadCroppedPicture({
|
||||
callerUid: uid,
|
||||
uid: uid,
|
||||
file: picture,
|
||||
}, (err) => {
|
||||
@@ -1167,6 +1168,7 @@ describe('User', () => {
|
||||
|
||||
it('should return error if profile image has no mime type', (done) => {
|
||||
User.uploadCroppedPicture({
|
||||
callerUid: uid,
|
||||
uid: uid,
|
||||
imageData: 'data:image/invalid;base64,R0lGODlhPQBEAPeoAJosM/',
|
||||
}, (err) => {
|
||||
@@ -1189,6 +1191,7 @@ describe('User', () => {
|
||||
const temp = meta.config.maximumProfileImageSize;
|
||||
meta.config.maximumProfileImageSize = 1;
|
||||
User.uploadCroppedPicture({
|
||||
callerUid: uid,
|
||||
uid: 1,
|
||||
imageData: goodImage,
|
||||
}, (err) => {
|
||||
@@ -1202,6 +1205,7 @@ describe('User', () => {
|
||||
|
||||
it('should not allow image data with bad MIME type to be passed in', (done) => {
|
||||
User.uploadCroppedPicture({
|
||||
callerUid: uid,
|
||||
uid: 1,
|
||||
imageData: badImage,
|
||||
}, (err) => {
|
||||
|
||||
Reference in New Issue
Block a user