yusuketk 6 лет назад
Родитель
Сommit
13679a9757
2 измененных файлов с 10 добавлено и 4 удалено
  1. 7 3
      src/server/models/user.js
  2. 3 1
      src/server/service/passport.js

+ 7 - 3
src/server/models/user.js

@@ -189,7 +189,7 @@ module.exports = function(crowi) {
 
 
   userSchema.methods.updateIsGravatarEnabled = async function(isGravatarEnabled) {
   userSchema.methods.updateIsGravatarEnabled = async function(isGravatarEnabled) {
     this.isGravatarEnabled = isGravatarEnabled;
     this.isGravatarEnabled = isGravatarEnabled;
-    this.imageUrlCached = this.generateImageUrlCached();
+    this.updateImageUrlCached();
     const userData = await this.save();
     const userData = await this.save();
     return userData;
     return userData;
   };
   };
@@ -225,7 +225,7 @@ module.exports = function(crowi) {
 
 
   userSchema.methods.updateImage = async function(attachment) {
   userSchema.methods.updateImage = async function(attachment) {
     this.imageAttachment = attachment;
     this.imageAttachment = attachment;
-    this.imageUrlCached = this.generateImageUrlCached();
+    this.updateImageUrlCached();
     return this.save();
     return this.save();
   };
   };
 
 
@@ -241,10 +241,14 @@ module.exports = function(crowi) {
     }
     }
 
 
     this.imageAttachment = undefined;
     this.imageAttachment = undefined;
-    this.imageUrlCached = this.generateImageUrlCached();
+    this.updateImageUrlCached();
     return this.save();
     return this.save();
   };
   };
 
 
+  userSchema.methods.updateImageUrlCached = function() {
+    this.imageUrlCached = this.generateImageUrlCached();
+  };
+
   userSchema.methods.generateImageUrlCached = function() {
   userSchema.methods.generateImageUrlCached = function() {
     if (this.isGravatarEnabled) {
     if (this.isGravatarEnabled) {
       const email = this.email || '';
       const email = this.email || '';

+ 3 - 1
src/server/service/passport.js

@@ -854,7 +854,9 @@ class PassportService {
         if (user == null) {
         if (user == null) {
           throw new Error('user not found');
           throw new Error('user not found');
         }
         }
-       // [TODO][GW - 1942] add method for updating imageUrlCached
+        if (!user.ImageUrlCached) {
+          user.updateImageUrlCached();
+        }
         done(null, user);
         done(null, user);
       }
       }
       catch (err) {
       catch (err) {