Skip to content

Commit

Permalink
feat: change uploadCroppedPicture to use updateProfile as well
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Mar 3, 2021
1 parent a598abc commit 0af9d26
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/socket.io/user/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
5 changes: 3 additions & 2 deletions src/user/picture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions test/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ describe('User', () => {
type: 'image/png',
};
User.uploadCroppedPicture({
callerUid: uid,
uid: uid,
file: picture,
}, (err) => {
Expand All @@ -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) => {
Expand All @@ -1189,6 +1191,7 @@ describe('User', () => {
const temp = meta.config.maximumProfileImageSize;
meta.config.maximumProfileImageSize = 1;
User.uploadCroppedPicture({
callerUid: uid,
uid: 1,
imageData: goodImage,
}, (err) => {
Expand All @@ -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) => {
Expand Down

0 comments on commit 0af9d26

Please sign in to comment.