Parcourir la source

Merge pull request #2066 from weseek/imprv/chage-how-to-get-image-from-user-data-in-front

Imprv/chage how to get image from user data in front
Yuki Takei il y a 6 ans
Parent
commit
04d05a57b5

+ 1 - 1
src/client/js/components/PageHistory.jsx

@@ -49,7 +49,7 @@ class PageHistory extends React.Component {
     const diffOpened = {};
     const lastId = rev.length - 1;
     res.revisions.forEach((revision, i) => {
-      const user = this.props.crowi.findUserById(revision.author);
+      const user = revision.author;
       if (user) {
         rev[i].author = user;
       }

+ 6 - 24
src/client/js/components/User/UserPicture.jsx

@@ -1,5 +1,4 @@
 import React from 'react';
-import md5 from 'md5';
 import PropTypes from 'prop-types';
 
 const DEFAULT_IMAGE = '/images/icons/user.svg';
@@ -7,28 +6,6 @@ const DEFAULT_IMAGE = '/images/icons/user.svg';
 // TODO UserComponent?
 export default class UserPicture extends React.Component {
 
-  getUserPicture(user) {
-    // gravatar
-    if (user.isGravatarEnabled === true) {
-      return this.generateGravatarSrc(user);
-    }
-    // uploaded image
-    if (user.image != null) {
-      return user.image;
-    }
-    if (user.imageAttachment != null) {
-      return user.imageAttachment.filePathProxied;
-    }
-
-    return DEFAULT_IMAGE;
-  }
-
-  generateGravatarSrc(user) {
-    const email = user.email || '';
-    const hash = md5(email.trim().toLowerCase());
-    return `https://gravatar.com/avatar/${hash}`;
-  }
-
   getClassName() {
     const className = ['img-circle', 'picture'];
     // size
@@ -56,9 +33,14 @@ export default class UserPicture extends React.Component {
       return this.renderForNull();
     }
 
+    if (!user.imageUrlCached) {
+      // [TODO][GW-1942] add imageUrlCached
+      return this.renderForNull();
+    }
+
     const imgElem = (
       <img
-        src={this.getUserPicture(user)}
+        src={user.imageUrlCached}
         alt={user.username}
         className={this.getClassName()}
       />

+ 0 - 1
src/server/models/bookmark.js

@@ -45,7 +45,6 @@ module.exports = function(crowi) {
     const Bookmark = this;
     const User = crowi.model('User');
 
-    // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
     return Bookmark.populate(bookmarks, {
       path: 'page',
       populate: {

+ 0 - 5
src/server/models/page.js

@@ -109,7 +109,6 @@ const addSlashOfEnd = (path) => {
  */
 /* eslint-disable object-curly-newline, object-property-newline */
 const populateDataToShowRevision = (page, userPublicFields) => {
-  // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
   return page
     .populate([
       { path: 'lastUpdateUser', model: 'User', select: userPublicFields },
@@ -265,7 +264,6 @@ class PageQueryBuilder {
   }
 
   populateDataToList(userPublicFields) {
-    // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
     this.query = this.query
       .populate({
         path: 'lastUpdateUser',
@@ -461,7 +459,6 @@ module.exports = function(crowi) {
   pageSchema.methods.populateDataToShowRevision = async function() {
     validateCrowi();
 
-    // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
     const User = crowi.model('User');
     return populateDataToShowRevision(this, User.USER_PUBLIC_FIELDS)
       .execPopulate();
@@ -756,7 +753,6 @@ module.exports = function(crowi) {
     const totalCount = await builder.query.exec('count');
 
     // find
-    // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
     builder.populateDataToList(User.USER_PUBLIC_FIELDS);
     const pages = await builder.query.exec('find');
 
@@ -798,7 +794,6 @@ module.exports = function(crowi) {
     // count
     const totalCount = await builder.query.exec('count');
 
-    // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
     // find
     builder.addConditionToPagenate(opt.offset, opt.limit, sortOpt);
     builder.populateDataToList(User.USER_PUBLIC_FIELDS);

+ 0 - 1
src/server/models/user-group-relation.js

@@ -87,7 +87,6 @@ class UserGroupRelation {
   static findAllRelationForUserGroup(userGroup) {
     const User = UserGroupRelation.crowi.model('User');
     debug('findAllRelationForUserGroup is called', userGroup);
-    // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
     return this
       .find({ relatedGroup: userGroup })
       .populate({

+ 0 - 1
src/server/routes/apiv3/user-group.js

@@ -577,7 +577,6 @@ module.exports = (crowi) => {
     const { id } = req.params;
     const { limit, offset } = req.query;
 
-    // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
     try {
       const { docs, total } = await Page.paginate({
         grant: Page.GRANT_USER_GROUP,

+ 0 - 1
src/server/routes/apiv3/users.js

@@ -167,7 +167,6 @@ module.exports = (crowi) => {
     };
 
     try {
-    // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
       const paginateResult = await User.paginate(
         {
           $and: [

+ 0 - 1
src/server/routes/attachment.js

@@ -352,7 +352,6 @@ module.exports = function(crowi, app) {
       return res.json(ApiResponse.error('Parameters page_id is required.'));
     }
 
-    // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
     let attachments = await Attachment.find({ page: id })
       .sort({ updatedAt: 1 })
       .populate({ path: 'creator', select: User.USER_PUBLIC_FIELDS });

+ 0 - 1
src/server/routes/comment.js

@@ -127,7 +127,6 @@ module.exports = function(crowi, app) {
       return res.json(ApiResponse.error(err));
     }
 
-    // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
     const comments = await fetcher.populate(
       { path: 'creator', select: User.USER_PUBLIC_FIELDS },
     );

+ 0 - 1
src/server/routes/page.js

@@ -265,7 +265,6 @@ module.exports = function(crowi, app) {
   }
 
   async function addRenderVarsForUserPage(renderVars, page, requestUser) {
-    // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
     const userData = await User.findUserByUsername(User.getUsernameByPath(page.path));
 
     if (userData != null) {

+ 1 - 1
src/server/routes/revision.js

@@ -170,7 +170,7 @@ module.exports = function(crowi, app) {
       Page.findByIdAndViewer(pageId, req.user)
         .then((pageData) => {
           debug('Page found', pageData._id, pageData.path);
-          return Revision.findRevisionIdList(pageData.path);
+          return Revision.findRevisionList(pageData.path);
         })
         .then((revisions) => {
           return res.json(ApiResponse.success({ revisions }));

+ 0 - 1
src/server/routes/user.js

@@ -138,7 +138,6 @@ module.exports = function(crowi, app) {
 
     const data = {};
     try {
-      // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
       const users = await userFetcher;
       data.users = users.map((user) => {
         // omit email

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

@@ -850,7 +850,6 @@ class PassportService {
     });
     passport.deserializeUser(async(id, done) => {
       try {
-        // [TODO][user-profile-cache][GW-1775] change how to get profile image data in client side.
         const user = await User.findById(id);
         if (user == null) {
           throw new Error('user not found');

+ 4 - 2
src/server/views/layout-growi/widget/header.html

@@ -19,7 +19,8 @@
         <li>
           <div class="d-flex align-items-center not-affix">
             <a class="m-r-5" href="{{ userPageRoot(page.creator) }}" data-toggle="tooltip" data-placement="bottom" title="{{ page.creator.name|default(author.name) }}">
-              <img src="{{ page.creator|default(author)|picture }}" class="picture img-circle">
+              <!-- [TODO][GW-1942] add method for updating imageUrlCached -->
+              <img src="{{ page.creator.imageUrlCached|default(author.imageUrlCached) }}" class="picture img-circle">
             </a>
             <div>
               <div>Created by <a href="{{ userPageRoot(page.creator) }}">{{ page.creator.name|default(author.name) }}</a></div>
@@ -28,7 +29,8 @@
           </div>
           <div class="d-flex align-items-center only-affix">
             <a class="m-r-5" href="{{ userPageRoot(page.creator) }}" data-toggle="tooltip" data-placement="bottom" title="{{ page.creator.name|default(author.name) }}">
-              <img src="{{ page.creator|default(author)|picture }}" class="picture picture-xs img-circle">
+              <!-- [TODO][GW-1942] add method for updating imageUrlCached -->
+              <img src="{{ page.creator.imageUrlCached|default(author.imageUrlCached) }}" class="picture picture-xs img-circle">
             </a>
             <div class="ml-auto">
               <div>Created at <span class="text-muted">{{ page.createdAt|datetz('Y/m/d H:i:s') }}</span></div>

+ 2 - 1
src/server/views/widget/page_list.html

@@ -8,7 +8,8 @@
 {% endif %}
 
 <li>
-  <img src="{{ page.lastUpdateUser|picture }}" class="picture img-circle">
+  <!-- [TODO][GW-1942] add method for updating imageUrlCached -->
+  <img src="{{ page.lastUpdateUser.imageUrlCached }}" class="picture img-circle">
   <a href="{{ page.path }}"
     class="page-list-link"
     data-path="{{ page.path }}">{{ decodeURIComponent(page.path) }}

+ 2 - 1
src/server/views/widget/user_page_header.html

@@ -4,7 +4,8 @@
     <h4 id="revision-path"></h4>
 
     <div class="users-info d-flex align-items-center">
-      <img src="{{ pageUser|picture }}" class="picture img-circle">
+    <!-- [TODO][GW-1942] add method for updating imageUrlCached -->
+      <img src="{{ pageUser.imageUrlCached }}" class="picture img-circle">
       <div class="users-meta" style="flex: 1;">
         <div class="d-flex align-items-center">
           <h1>