shinoka7 6 лет назад
Родитель
Сommit
47d09a5e18
1 измененных файлов с 4 добавлено и 5 удалено
  1. 4 5
      src/server/routes/attachment.js

+ 4 - 5
src/server/routes/attachment.js

@@ -345,21 +345,20 @@ module.exports = function(crowi, app) {
    * @apiParam {String} attachment_id
    */
   api.removeProfileImage = async function(req, res) {
-    const id = req.body.attachment_id;
-
-    const attachment = await Attachment.findById(id);
+    const user = req.user;
+    const attachment = await Attachment.findById(user.imageAttachment);
 
     if (attachment == null) {
       return res.json(ApiResponse.error('attachment not found'));
     }
 
-    const isDeletable = await isDeletableByUser(req.user, attachment);
+    const isDeletable = await isDeletableByUser(user, attachment);
     if (!isDeletable) {
       return res.json(ApiResponse.error(`Forbidden to remove the attachment '${attachment.id}'`));
     }
 
     try {
-      await req.user.deleteImage();
+      await user.deleteImage();
     }
     catch (err) {
       return res.status(500).json(ApiResponse.error('Error while deleting image'));