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.isAdminOrGlobalModOrSelf(socket.uid, data.uid);
|
||||||
await user.checkMinReputation(socket.uid, data.uid, 'min:rep:profile-picture');
|
await user.checkMinReputation(socket.uid, data.uid, 'min:rep:profile-picture');
|
||||||
|
data.callerUid = socket.uid;
|
||||||
return await user.uploadCroppedPicture(data);
|
return await user.uploadCroppedPicture(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -148,10 +148,11 @@ module.exports = function (User) {
|
|||||||
const uploadedImage = await image.uploadImage(filename, 'profile', picture);
|
const uploadedImage = await image.uploadImage(filename, 'profile', picture);
|
||||||
|
|
||||||
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;
|
||||||
} finally {
|
} finally {
|
||||||
await file.delete(picture.path);
|
await file.delete(picture.path);
|
||||||
|
|||||||
@@ -1156,6 +1156,7 @@ describe('User', () => {
|
|||||||
type: 'image/png',
|
type: 'image/png',
|
||||||
};
|
};
|
||||||
User.uploadCroppedPicture({
|
User.uploadCroppedPicture({
|
||||||
|
callerUid: uid,
|
||||||
uid: uid,
|
uid: uid,
|
||||||
file: picture,
|
file: picture,
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
@@ -1167,6 +1168,7 @@ describe('User', () => {
|
|||||||
|
|
||||||
it('should return error if profile image has no mime type', (done) => {
|
it('should return error if profile image has no mime type', (done) => {
|
||||||
User.uploadCroppedPicture({
|
User.uploadCroppedPicture({
|
||||||
|
callerUid: uid,
|
||||||
uid: uid,
|
uid: uid,
|
||||||
imageData: 'data:image/invalid;base64,R0lGODlhPQBEAPeoAJosM/',
|
imageData: 'data:image/invalid;base64,R0lGODlhPQBEAPeoAJosM/',
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
@@ -1189,6 +1191,7 @@ describe('User', () => {
|
|||||||
const temp = meta.config.maximumProfileImageSize;
|
const temp = meta.config.maximumProfileImageSize;
|
||||||
meta.config.maximumProfileImageSize = 1;
|
meta.config.maximumProfileImageSize = 1;
|
||||||
User.uploadCroppedPicture({
|
User.uploadCroppedPicture({
|
||||||
|
callerUid: uid,
|
||||||
uid: 1,
|
uid: 1,
|
||||||
imageData: goodImage,
|
imageData: goodImage,
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
@@ -1202,6 +1205,7 @@ describe('User', () => {
|
|||||||
|
|
||||||
it('should not allow image data with bad MIME type to be passed in', (done) => {
|
it('should not allow image data with bad MIME type to be passed in', (done) => {
|
||||||
User.uploadCroppedPicture({
|
User.uploadCroppedPicture({
|
||||||
|
callerUid: uid,
|
||||||
uid: 1,
|
uid: 1,
|
||||||
imageData: badImage,
|
imageData: badImage,
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user