Просмотр исходного кода

Merge branch 'master' into rc/3.0.0

Yuki Takei 8 лет назад
Родитель
Сommit
1042d1dd6c
7 измененных файлов с 69 добавлено и 33 удалено
  1. 5 0
      CHANGES.md
  2. 2 4
      lib/models/comment.js
  3. 9 7
      lib/models/page.js
  4. 14 6
      lib/routes/comment.js
  5. 2 2
      package.json
  6. 1 1
      resource/js/util/markdown-it/plantuml.js
  7. 36 13
      yarn.lock

+ 5 - 0
CHANGES.md

@@ -5,6 +5,11 @@ CHANGES
 
 * Improvement: Ensure to set absolute url from root when attaching files when `FILE_UPLOAD=local`
 * Fix: Inline code blocks that includes doller sign are broken
+* Fix: Comment count is not updated when a comment of the page is deleted
+* Improvement: i18n in `/admin` (WIP)
+* Support: Upgrade libs
+    * googleapis
+    * markdown-it-plantuml
 
 ## 2.4.1
 

+ 2 - 4
lib/models/comment.js

@@ -122,10 +122,8 @@ module.exports = function(crowi) {
       , Comment = crowi.model('Comment')
     ;
 
-    Comment.countCommentByPageId(savedComment.page)
-    .then(function(count) {
-      return Page.updateCommentCount(savedComment.page, count);
-    }).then(function(page) {
+    Page.updateCommentCount(savedComment.page)
+    .then(function(page) {
       debug('CommentCount Updated', page);
     }).catch(function() {
     });

+ 9 - 7
lib/models/page.js

@@ -16,7 +16,8 @@ module.exports = function(crowi) {
 
     , pageEvent = crowi.event('page')
 
-    , pageSchema;
+    , pageSchema
+    , Comment = crowi.model('Comment');
 
   function isPortalPath(path) {
     if (path.match(/.*\/$/)) {
@@ -305,18 +306,19 @@ module.exports = function(crowi) {
     });
   };
 
-  pageSchema.statics.updateCommentCount = function (page, num)
+  pageSchema.statics.updateCommentCount = function (pageId)
   {
     var self = this;
-
-    return new Promise(function(resolve, reject) {
-      self.update({_id: page}, {commentCount: num}, {}, function(err, data) {
+    var Comment = crowi.model("Comment");
+    return Comment.countCommentByPageId(pageId)
+    .then(function(count) {
+      self.update({_id: pageId}, {commentCount: count}, {}, function(err, data) {
         if (err) {
           debug('Update commentCount Error', err);
-          return reject(err);
+          throw err;
         }
 
-        return resolve(data);
+        return data;
       });
     });
   };

+ 14 - 6
lib/routes/comment.js

@@ -82,15 +82,23 @@ module.exports = function(crowi, app) {
   api.remove = function(req, res){
     var commentId = req.body.comment_id;
     if (!commentId) {
-      return res.json(ApiResponse.error(`'comment_id' is undefined`));
+      return Promise.resolve(res.json(ApiResponse.error(`'comment_id' is undefined`)));
     }
 
-    return Comment.remove({_id: commentId})
-      .then(function() {
-        return res.json(ApiResponse.success({}));
-      }).catch(function(err) {
-        return res.json(ApiResponse.error(err));
+    return Comment.findById(commentId).exec()
+      .then(function(comment) {
+        return comment.remove()
+        .then(function() {
+           return Page.updateCommentCount(comment.page);
+        })
+        .then(function() {
+           return res.json(ApiResponse.success({})); 
+        });
+      })
+      .catch(function(err) {
+        return res.json(ApiResponse.error(err)); 
       });
+
   };
 
   return actions;

+ 2 - 2
package.json

@@ -84,7 +84,7 @@
     "express-session": "~1.15.0",
     "express-webpack-assets": "^0.1.0",
     "file-loader": "^1.1.0",
-    "googleapis": "^26.0.0",
+    "googleapis": "^27.0.0",
     "graceful-fs": "^4.1.11",
     "i18next": "^10.0.1",
     "i18next-express-middleware": "^1.0.5",
@@ -99,7 +99,7 @@
     "markdown-it-footnote": "^3.0.1",
     "markdown-it-mathjax": "^2.0.0",
     "markdown-it-named-headers": "^0.0.4",
-    "markdown-it-plantuml": "^0.3.1",
+    "markdown-it-plantuml": "^1.0.0",
     "markdown-it-task-lists": "^2.1.0",
     "markdown-it-toc-and-anchor-with-slugid": "^1.1.2",
     "md5": "^2.2.1",

+ 1 - 1
resource/js/util/markdown-it/plantuml.js

@@ -13,7 +13,7 @@ export default class PlantUMLConfigurer {
   }
 
   configure(md) {
-    md.use(require('markdown-it-plantuml'), 'name', {
+    md.use(require('markdown-it-plantuml'), {
       generateSource: this.generateSource,
     });
   }

+ 36 - 13
yarn.lock

@@ -2348,7 +2348,7 @@ express@^4.15.2, express@^4.16.1:
     utils-merge "1.0.1"
     vary "~1.1.2"
 
-extend@3, extend@~3.0.0, extend@~3.0.1:
+extend@3, extend@^3.0.1, extend@~3.0.0, extend@~3.0.1:
   version "3.0.1"
   resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"
 
@@ -2603,6 +2603,14 @@ gaze@^1.0.0:
   dependencies:
     globule "^1.0.0"
 
+gcp-metadata@^0.6.0:
+  version "0.6.1"
+  resolved "https://registry.yarnpkg.com/gcp-metadata/-/gcp-metadata-0.6.1.tgz#62d54871fc6aeeac6a688e094abc886cb7aaacd0"
+  dependencies:
+    axios "^0.17.1"
+    extend "^3.0.1"
+    retry-axios "0.3.0"
+
 generate-function@^2.0.0:
   version "2.0.0"
   resolved "https://registry.yarnpkg.com/generate-function/-/generate-function-2.0.0.tgz#6858fe7c0969b7d4e9093337647ac79f60dfbe74"
@@ -2687,15 +2695,17 @@ good-listener@^1.2.2:
   dependencies:
     delegate "^3.1.2"
 
-google-auth-library@^1.1.0:
-  version "1.2.1"
-  resolved "https://registry.yarnpkg.com/google-auth-library/-/google-auth-library-1.2.1.tgz#20eb9d585b1837a703712abdb787da4984982b64"
+google-auth-library@^1.3.1:
+  version "1.3.1"
+  resolved "https://registry.yarnpkg.com/google-auth-library/-/google-auth-library-1.3.1.tgz#a0456166c9538ee062c51b8e70765a5a0e13e757"
   dependencies:
-    axios "^0.17.1"
+    axios "^0.18.0"
+    gcp-metadata "^0.6.0"
     gtoken "^2.1.0"
     jws "^3.1.4"
     lodash.isstring "^4.0.1"
     lru-cache "^4.1.1"
+    retry-axios "^0.3.2"
 
 google-p12-pem@^1.0.0:
   version "1.0.0"
@@ -2704,14 +2714,15 @@ google-p12-pem@^1.0.0:
     node-forge "^0.7.1"
     pify "^3.0.0"
 
-googleapis@^26.0.0:
-  version "26.0.1"
-  resolved "https://registry.yarnpkg.com/googleapis/-/googleapis-26.0.1.tgz#e1efb43b00546b1ad8c055a83cf210d5422b7f42"
+googleapis@^27.0.0:
+  version "27.0.0"
+  resolved "https://registry.yarnpkg.com/googleapis/-/googleapis-27.0.0.tgz#c210633b43e7047b65d33da40c489b6d8f9c02b8"
   dependencies:
-    google-auth-library "^1.1.0"
+    google-auth-library "^1.3.1"
+    pify "^3.0.0"
     qs "^6.5.1"
     string-template "1.0.0"
-    uuid "^3.1.0"
+    uuid "^3.2.1"
 
 graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
   version "4.1.11"
@@ -3742,9 +3753,9 @@ markdown-it-named-headers@^0.0.4:
   dependencies:
     string "^3.0.1"
 
-markdown-it-plantuml@^0.3.1:
-  version "0.3.1"
-  resolved "https://registry.yarnpkg.com/markdown-it-plantuml/-/markdown-it-plantuml-0.3.1.tgz#f338df4d691a5561364e65809b6812bcb3d8b047"
+markdown-it-plantuml@^1.0.0:
+  version "1.0.0"
+  resolved "https://registry.yarnpkg.com/markdown-it-plantuml/-/markdown-it-plantuml-1.0.0.tgz#7b6a351a1d9275705c09626b02d873301e5899c2"
 
 markdown-it-task-lists@^2.1.0:
   version "2.1.0"
@@ -5515,6 +5526,14 @@ resolve@^1.0.0:
   dependencies:
     path-parse "^1.0.5"
 
+retry-axios@0.3.0:
+  version "0.3.0"
+  resolved "https://registry.yarnpkg.com/retry-axios/-/retry-axios-0.3.0.tgz#7858ad369872d6acaf05fd97b0490969c9c35ee2"
+
+retry-axios@^0.3.2:
+  version "0.3.2"
+  resolved "https://registry.yarnpkg.com/retry-axios/-/retry-axios-0.3.2.tgz#5757c80f585b4cc4c4986aa2ffd47a60c6d35e13"
+
 retry@^0.9.0:
   version "0.9.0"
   resolved "https://registry.yarnpkg.com/retry/-/retry-0.9.0.tgz#6f697e50a0e4ddc8c8f7fb547a9b60dead43678d"
@@ -6312,6 +6331,10 @@ uuid@3.1.0, uuid@^3.0.0, uuid@^3.1.0:
   version "3.1.0"
   resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"
 
+uuid@^3.2.1:
+  version "3.2.1"
+  resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.2.1.tgz#12c528bb9d58d0b9265d9a2f6f0fe8be17ff1f14"
+
 uws@~0.14.4:
   version "0.14.5"
   resolved "https://registry.yarnpkg.com/uws/-/uws-0.14.5.tgz#67aaf33c46b2a587a5f6666d00f7691328f149dc"