Răsfoiți Sursa

add new option

itizawa 5 ani în urmă
părinte
comite
503488c1d3
2 a modificat fișierele cu 11 adăugiri și 8 ștergeri
  1. 8 4
      src/server/models/page.js
  2. 3 4
      src/server/service/page.js

+ 8 - 4
src/server/models/page.js

@@ -144,6 +144,8 @@ class PageQueryBuilder {
    * If top page, return without doing anything.
    */
   addConditionToListWithDescendants(path, option) {
+    const excludeParent = option.excludeParent || false;
+
     // No request is set for the top page
     if (isTopPage(path)) {
       return this;
@@ -154,12 +156,14 @@ class PageQueryBuilder {
 
     const startsPattern = escapeStringRegexp(pathWithTrailingSlash);
 
+    const filters = [{ path: new RegExp(`^${startsPattern}`) }];
+    if (!excludeParent) {
+      filters.push({ path: pathNormalized });
+    }
+
     this.query = this.query
       .and({
-        $or: [
-          { path: pathNormalized },
-          { path: new RegExp(`^${startsPattern}`) },
-        ],
+        $or: filters,
       });
 
     return this;

+ 3 - 4
src/server/service/page.js

@@ -80,7 +80,7 @@ class PageService {
     const Revision = this.crowi.model('Revision');
     const newPagePathPrefix = newPagePath;
     const pathRegExp = new RegExp(`^${escapeStringRegexp(page.path)}`, 'i');
-    const pages = await Page.findManageableListWithDescendants(page, user);
+    const pages = await Page.findManageableListWithDescendants(page, user, { excludeParent: true });
     const revisions = await Revision.find({ path: pathRegExp });
 
     // Mapping to set to the body of the new revision
@@ -146,10 +146,9 @@ class PageService {
     pages.forEach(page => readable.push(page));
     readable.push(null);
 
-    const newPath = page.path.replace(pathRegExp, newPagePathPrefix);
-    const newParentpage = await Page.findByPath(newPath);
+    const parentPage = await this.duplicate(page, newPagePath, user);
 
-    return newParentpage;
+    return parentPage;
   }
 
   // delete multiple pages