|
|
@@ -5,7 +5,6 @@ const debug = require('debug')('growi:models:page');
|
|
|
const { Writable } = require('stream');
|
|
|
const { createBatchStream } = require('@server/util/batch-stream');
|
|
|
const { isTrashPage } = require('@commons/util/path-utils');
|
|
|
-const streamToPromise = require('stream-to-promise');
|
|
|
const { serializePageSecurely } = require('../models/serializers/page-serializer');
|
|
|
|
|
|
const BULK_REINDEX_SIZE = 100;
|
|
|
@@ -58,10 +57,6 @@ class PageService {
|
|
|
// sanitize path
|
|
|
newPagePath = this.crowi.xss.process(newPagePath); // eslint-disable-line no-param-reassign
|
|
|
|
|
|
- if (isRecursively) {
|
|
|
- await this.renameDescendantsWithStream(page, newPagePath, user, options);
|
|
|
- }
|
|
|
-
|
|
|
const update = {};
|
|
|
// update Page
|
|
|
update.path = newPagePath;
|
|
|
@@ -79,6 +74,10 @@ class PageService {
|
|
|
await Page.create(path, body, user, { redirectTo: newPagePath });
|
|
|
}
|
|
|
|
|
|
+ if (isRecursively) {
|
|
|
+ this.renameDescendantsWithStream(page, newPagePath, user, options);
|
|
|
+ }
|
|
|
+
|
|
|
this.pageEvent.emit('delete', page, user, socketClientId);
|
|
|
this.pageEvent.emit('create', renamedPage, user, socketClientId);
|
|
|
|
|
|
@@ -142,9 +141,6 @@ class PageService {
|
|
|
*/
|
|
|
async renameDescendantsWithStream(targetPage, newPagePath, user, options = {}) {
|
|
|
const Page = this.crowi.model('Page');
|
|
|
- const UserGroupRelation = this.crowi.model('UserGroupRelation');
|
|
|
-
|
|
|
- const userGroups = await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user);
|
|
|
const newPagePathPrefix = newPagePath;
|
|
|
const { PageQueryBuilder } = Page;
|
|
|
const pathRegExp = new RegExp(`^${escapeStringRegexp(targetPage.path)}`, 'i');
|
|
|
@@ -152,7 +148,7 @@ class PageService {
|
|
|
const readStream = new PageQueryBuilder(Page.find())
|
|
|
.addConditionToExcludeRedirect()
|
|
|
.addConditionToListOnlyDescendants(targetPage.path)
|
|
|
- .addConditionToFilteringByViewer(user, userGroups)
|
|
|
+ .addConditionToFilteringByViewer(user)
|
|
|
.query
|
|
|
.lean()
|
|
|
.cursor({ batchSize: BULK_REINDEX_SIZE });
|
|
|
@@ -186,8 +182,6 @@ class PageService {
|
|
|
readStream
|
|
|
.pipe(createBatchStream(BULK_REINDEX_SIZE))
|
|
|
.pipe(writeStream);
|
|
|
-
|
|
|
- return streamToPromise(writeStream);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -240,14 +234,14 @@ class PageService {
|
|
|
|
|
|
newPagePath = this.crowi.xss.process(newPagePath); // eslint-disable-line no-param-reassign
|
|
|
|
|
|
- if (isRecursively) {
|
|
|
- await this.duplicateDescendantsWithStream(page, newPagePath, user);
|
|
|
- }
|
|
|
-
|
|
|
const createdPage = await Page.create(
|
|
|
newPagePath, page.revision.body, user, options,
|
|
|
);
|
|
|
|
|
|
+ if (isRecursively) {
|
|
|
+ this.duplicateDescendantsWithStream(page, newPagePath, user);
|
|
|
+ }
|
|
|
+
|
|
|
// take over tags
|
|
|
const originTags = await page.findRelatedTagsById();
|
|
|
let savedTags = [];
|
|
|
@@ -348,9 +342,6 @@ class PageService {
|
|
|
|
|
|
async duplicateDescendantsWithStream(page, newPagePath, user) {
|
|
|
const Page = this.crowi.model('Page');
|
|
|
- const UserGroupRelation = this.crowi.model('UserGroupRelation');
|
|
|
-
|
|
|
- const userGroups = await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user);
|
|
|
const newPagePathPrefix = newPagePath;
|
|
|
const pathRegExp = new RegExp(`^${escapeStringRegexp(page.path)}`, 'i');
|
|
|
|
|
|
@@ -359,7 +350,7 @@ class PageService {
|
|
|
const readStream = new PageQueryBuilder(Page.find())
|
|
|
.addConditionToExcludeRedirect()
|
|
|
.addConditionToListOnlyDescendants(page.path)
|
|
|
- .addConditionToFilteringByViewer(user, userGroups)
|
|
|
+ .addConditionToFilteringByViewer(user)
|
|
|
.query
|
|
|
.lean()
|
|
|
.cursor({ batchSize: BULK_REINDEX_SIZE });
|
|
|
@@ -394,7 +385,6 @@ class PageService {
|
|
|
.pipe(createBatchStream(BULK_REINDEX_SIZE))
|
|
|
.pipe(writeStream);
|
|
|
|
|
|
- return streamToPromise(writeStream);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -490,15 +480,12 @@ class PageService {
|
|
|
*/
|
|
|
async deleteDescendantsWithStream(targetPage, user, options = {}) {
|
|
|
const Page = this.crowi.model('Page');
|
|
|
- const UserGroupRelation = this.crowi.model('UserGroupRelation');
|
|
|
-
|
|
|
- const userGroups = await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user);
|
|
|
const { PageQueryBuilder } = Page;
|
|
|
|
|
|
const readStream = new PageQueryBuilder(Page.find())
|
|
|
.addConditionToExcludeRedirect()
|
|
|
.addConditionToListOnlyDescendants(targetPage.path)
|
|
|
- .addConditionToFilteringByViewer(user, userGroups)
|
|
|
+ .addConditionToFilteringByViewer(user)
|
|
|
.query
|
|
|
.lean()
|
|
|
.cursor({ batchSize: BULK_REINDEX_SIZE });
|
|
|
@@ -569,15 +556,12 @@ class PageService {
|
|
|
*/
|
|
|
async deleteCompletelyDescendantsWithStream(targetPage, user, options = {}) {
|
|
|
const Page = this.crowi.model('Page');
|
|
|
- const UserGroupRelation = this.crowi.model('UserGroupRelation');
|
|
|
-
|
|
|
- const userGroups = await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user);
|
|
|
const { PageQueryBuilder } = Page;
|
|
|
|
|
|
const readStream = new PageQueryBuilder(Page.find())
|
|
|
.addConditionToExcludeRedirect()
|
|
|
.addConditionToListOnlyDescendants(targetPage.path)
|
|
|
- .addConditionToFilteringByViewer(user, userGroups)
|
|
|
+ .addConditionToFilteringByViewer(user)
|
|
|
.query
|
|
|
.lean()
|
|
|
.cursor({ batchSize: BULK_REINDEX_SIZE });
|
|
|
@@ -698,15 +682,12 @@ class PageService {
|
|
|
*/
|
|
|
async revertDeletedDescendantsWithStream(targetPage, user, options = {}) {
|
|
|
const Page = this.crowi.model('Page');
|
|
|
- const UserGroupRelation = this.crowi.model('UserGroupRelation');
|
|
|
-
|
|
|
- const userGroups = await UserGroupRelation.findAllUserGroupIdsRelatedToUser(user);
|
|
|
const { PageQueryBuilder } = Page;
|
|
|
|
|
|
const readStream = new PageQueryBuilder(Page.find())
|
|
|
.addConditionToExcludeRedirect()
|
|
|
.addConditionToListOnlyDescendants(targetPage.path)
|
|
|
- .addConditionToFilteringByViewer(user, userGroups)
|
|
|
+ .addConditionToFilteringByViewer(user)
|
|
|
.query
|
|
|
.lean()
|
|
|
.cursor({ batchSize: BULK_REINDEX_SIZE });
|