Browse Source

Merge pull request #837 from weseek/master

release v3.3.9
Yuki Takei 7 years ago
parent
commit
221e5e672d

+ 9 - 1
CHANGES.md

@@ -1,9 +1,17 @@
 CHANGES
 ========
 
-## 3.3.8-RC
+## 3.3.9-RC
 
+* Fix: Import from Qiita:Team doesn't work
+    * Introduced by 3.3.0
 * Fix: Typeahead shows autocomplete wrongly
+    * Introduced by 3.3.8
+* Support: Upgrade libs
+    * react-bootstrap-typeahead
+
+## 3.3.8
+
 * Fix: Move/Duplicate don't work
     * Introduced by 3.3.7
 * Fix: Server doesn't respond when root page is restricted

+ 2 - 2
package.json

@@ -1,6 +1,6 @@
 {
   "name": "growi",
-  "version": "3.3.8-RC",
+  "version": "3.3.9-RC",
   "description": "Team collaboration software using markdown",
   "tags": [
     "wiki",
@@ -184,7 +184,7 @@
     "postcss-loader": "^3.0.0",
     "react": "^16.7.0",
     "react-bootstrap": "^0.32.1",
-    "react-bootstrap-typeahead": "^3.3.2",
+    "react-bootstrap-typeahead": "^3.3.4",
     "react-clipboard.js": "^2.0.0",
     "react-codemirror2": "^5.1.0",
     "react-dom": "^16.4.1",

+ 12 - 5
src/client/styles/scss/_search.scss

@@ -30,6 +30,7 @@
   }
   .rbt-menu {
     margin-top: 3px;
+
     li a span {
       .page-path {
         display: inline;
@@ -100,11 +101,6 @@
       width: 300px;
     }
   }
-  .rbt-menu {
-    margin-top: 33px;   // DIRTY HACK
-                        //   note: 'transform: translate3d(0px, XXpx, 0px)' calculation has failed on .search-top
-                        //         since upgrade react-bootstrap-typeahead to v3.3.2 -- 2019.02.05 Yuki Takei
-  }
 }
 .search-sidebar {
   .search-form, .form-group, .rbt-input.form-control, .input-group {
@@ -115,6 +111,17 @@
   }
 }
 
+@mixin search-typeahead-rbtmenu-mt($margin-top) {
+  .search-typeahead .rbt-menu {
+    margin-top: $margin-top;    // DIRTY HACK
+                                //   note: 'transform: translate3d(0px, XXpx, 0px)' calculation has failed
+                                //         since upgrade react-bootstrap-typeahead to v3.3.2 -- 2019.02.05 Yuki Takei
+  }
+}
+#search-top, #renamePage, #duplicatePage, .search-page-input {
+  @include search-typeahead-rbtmenu-mt(36px);
+}
+
 .search-result {
 
   .search-result-list {

+ 37 - 41
src/server/models/bookmark.js

@@ -2,6 +2,7 @@ module.exports = function(crowi) {
   const debug = require('debug')('growi:models:bookmark');
   const mongoose = require('mongoose');
   const ObjectId = mongoose.Schema.Types.ObjectId;
+  const bookmarkEvent = crowi.event('bookmark');
 
   let bookmarkSchema = null;
 
@@ -79,27 +80,24 @@ module.exports = function(crowi) {
     });
   };
 
-  bookmarkSchema.statics.add = function(page, user) {
+  bookmarkSchema.statics.add = async function(page, user) {
     const Bookmark = this;
 
-    return new Promise(function(resolve, reject) {
-      const newBookmark = new Bookmark;
-
-      newBookmark.page = page;
-      newBookmark.user = user;
-      newBookmark.createdAt = Date.now();
-      newBookmark.save(function(err, bookmark) {
-        debug('Bookmark.save', err, bookmark);
-        if (err) {
-          if (err.code === 11000) { // duplicate key (dummy reesponse of new object)
-            return resolve(newBookmark);
-          }
-          return reject(err);
-        }
-
-        resolve(bookmark);
-      });
-    });
+    const newBookmark = new Bookmark({ page, user, createdAt: Date.now() });
+
+    try {
+      const bookmark = await newBookmark.save();
+      bookmarkEvent.emit('create', page._id);
+      return bookmark;
+    }
+    catch (err) {
+      if (err.code === 11000) {
+        // duplicate key (dummy response of new object)
+        return newBookmark;
+      }
+      debug('Bookmark.save failed', err);
+      throw err;
+    }
   };
 
   /**
@@ -107,34 +105,32 @@ module.exports = function(crowi) {
    * used only when removing the page
    * @param {string} pageId
    */
-  bookmarkSchema.statics.removeBookmarksByPageId = function(pageId) {
+  bookmarkSchema.statics.removeBookmarksByPageId = async function(pageId) {
     const Bookmark = this;
 
-    return new Promise(function(resolve, reject) {
-      Bookmark.remove({page: pageId}, function(err, data) {
-        if (err) {
-          debug('Bookmark.remove failed (removeBookmarkByPage)', err);
-          return reject(err);
-        }
-
-        return resolve(data);
-      });
-    });
+    try {
+      const data = await Bookmark.remove({ page: pageId });
+      bookmarkEvent.emit('delete', pageId);
+      return data;
+    }
+    catch (err) {
+      debug('Bookmark.remove failed (removeBookmarkByPage)', err);
+      throw err;
+    }
   };
 
-  bookmarkSchema.statics.removeBookmark = function(page, user) {
+  bookmarkSchema.statics.removeBookmark = async function(page, user) {
     const Bookmark = this;
 
-    return new Promise(function(resolve, reject) {
-      Bookmark.findOneAndRemove({page: page, user: user}, function(err, data) {
-        if (err) {
-          debug('Bookmark.findOneAndRemove failed', err);
-          return reject(err);
-        }
-
-        return resolve(data);
-      });
-    });
+    try {
+      const data = await Bookmark.findOneAndRemove({ page, user });
+      bookmarkEvent.emit('delete', page);
+      return data;
+    }
+    catch (err) {
+      debug('Bookmark.findOneAndRemove failed', err);
+      throw err;
+    }
   };
 
   return mongoose.model('Bookmark', bookmarkSchema);

+ 29 - 34
src/server/util/createGrowiPagesFromImports.js

@@ -11,44 +11,39 @@ module.exports = crowi => {
    *    user: Object
    * }]
    */
-  const createGrowiPages = (pages) => {
-    let errors = [];
+  const createGrowiPages = async(pages) => {
+    const promises = [];
+    const errors = [];
 
-    return new Promise((resolve, reject) => {
-      const promises = pages.map(page => {
-        return new Promise(async(resolve, reject) => {
-          const path = page.path;
-          const user = page.user;
-          const body = page.body;
-          const isCreatableName = await Page.isCreatableName(path);
-          const isPageNameTaken = await Page.findPage(path, user, null, true);
+    for (let page of pages) {
+      const path = page.path;
+      const user = page.user;
+      const body = page.body;
+      const isCreatableName = await Page.isCreatableName(path);
+      const isPageNameTaken = await Page.findByPathAndViewer(path, user);
 
-          if (isCreatableName && !isPageNameTaken) {
-            try {
-              await Page.create(path, body, user, { grant: Page.GRANT_PUBLIC, grantUserGroupId: null });
-            }
-            catch (err) {
-              errors.push(err);
-            }
-          }
-          else {
-            if (!isCreatableName) {
-              errors.push(new Error(`${path} is not a creatable name in Growi`));
-            }
-            if (isPageNameTaken) {
-              errors.push(new Error(`${path} already exists in Growi`));
-            }
-          }
+      if (isCreatableName && !isPageNameTaken) {
+        try {
+          const promise = Page.create(path, body, user, { grant: Page.GRANT_PUBLIC, grantUserGroupId: null });
+          promises.push(promise);
+        }
+        catch (err) {
+          errors.push(err);
+        }
+      }
+      else {
+        if (!isCreatableName) {
+          errors.push(new Error(`${path} is not a creatable name in Growi`));
+        }
+        if (isPageNameTaken) {
+          errors.push(new Error(`${path} already exists in Growi`));
+        }
+      }
+    }
 
-          resolve();
-        });
-      });
+    await Promise.all(promises);
 
-      Promise.all(promises)
-        .then(() => {
-          resolve(errors);
-        });
-    });
+    return errors;
   };
 
   return createGrowiPages;

+ 1 - 1
src/server/util/search.js

@@ -786,7 +786,7 @@ SearchClient.prototype.syncPageDeleted = function(page, user) {
 SearchClient.prototype.syncBookmarkChanged = async function(pageId) {
   const Page = this.crowi.model('Page');
   const Bookmark = this.crowi.model('Bookmark');
-  const page = await Page.findPageById(pageId);
+  const page = await Page.findById(pageId);
   const bookmarkCount = await Bookmark.countByPageId(pageId);
 
   page.bookmarkCount = bookmarkCount;

+ 4 - 4
yarn.lock

@@ -7524,10 +7524,10 @@ rc@^1.1.7:
     minimist "^1.2.0"
     strip-json-comments "~2.0.1"
 
-react-bootstrap-typeahead@^3.3.2:
-  version "3.3.2"
-  resolved "https://registry.yarnpkg.com/react-bootstrap-typeahead/-/react-bootstrap-typeahead-3.3.2.tgz#ffe0193b6fc4af585d1724b1447d8bf2c871f75a"
-  integrity sha512-BCaFXrN3MefKj2jn8HqeSHu4hWwv1f8WtYWTNOhkz+KN4QtNLwbm7ttxOVuaG8CWk89HYGvF6QEjN5XIFE47hg==
+react-bootstrap-typeahead@^3.3.4:
+  version "3.3.4"
+  resolved "https://registry.yarnpkg.com/react-bootstrap-typeahead/-/react-bootstrap-typeahead-3.3.4.tgz#e0c26332f83cb6964fc3d003f8ffeb4b86fffab5"
+  integrity sha512-LMT+YlThPaB5pU7t8C9ml3kCPVGw6aEbVkpGCJIXcynJ5mxeUhFhGxpYv3UcpU3kFyowksUGG+ePSvqgaEsL7A==
   dependencies:
     classnames "^2.2.0"
     create-react-context "^0.2.3"