|
|
@@ -693,7 +693,7 @@ module.exports = function(crowi) {
|
|
|
/**
|
|
|
* find pages that is match with `path` and its descendants
|
|
|
*/
|
|
|
- pageSchema.statics.findListWithDescendants = async function(path, user, option) {
|
|
|
+ pageSchema.statics.findListWithDescendants = async function(path, user, option = {}) {
|
|
|
const builder = new PageQueryBuilder(this.find());
|
|
|
builder.addConditionToListWithDescendants(path, option);
|
|
|
|
|
|
@@ -1094,21 +1094,18 @@ module.exports = function(crowi) {
|
|
|
throw new Error('This method does NOT supports deleting trashed pages.');
|
|
|
}
|
|
|
|
|
|
- const findOpts = { includeRedirect: true };
|
|
|
- const result = await this.findListWithDescendants(targetPage.path, user, findOpts);
|
|
|
+ // find descendants (this array does not include GRANT_RESTRICTED)
|
|
|
+ const result = await this.findListWithDescendants(targetPage.path, user);
|
|
|
const pages = result.pages;
|
|
|
+ // add targetPage if 'grant' is GRANT_RESTRICTED
|
|
|
+ // because findListWithDescendants excludes GRANT_RESTRICTED pages
|
|
|
+ if (targetPage.grant === GRANT_RESTRICTED) {
|
|
|
+ pages.push(targetPage);
|
|
|
+ }
|
|
|
|
|
|
- let updatedPage = null;
|
|
|
await Promise.all(pages.map((page) => {
|
|
|
- const isParent = (page.path === targetPage.path);
|
|
|
- const p = this.deletePage(page, user, options);
|
|
|
- if (isParent) {
|
|
|
- updatedPage = p;
|
|
|
- }
|
|
|
- return p;
|
|
|
+ return this.deletePage(page, user, options);
|
|
|
}));
|
|
|
-
|
|
|
- return updatedPage;
|
|
|
};
|
|
|
|
|
|
pageSchema.statics.revertDeletedPage = async function(page, user, options = {}) {
|
|
|
@@ -1185,17 +1182,23 @@ module.exports = function(crowi) {
|
|
|
/**
|
|
|
* Delete Bookmarks, Attachments, Revisions, Pages and emit delete
|
|
|
*/
|
|
|
- pageSchema.statics.completelyDeletePageRecursively = async function(pagePath, user, options = {}) {
|
|
|
+ pageSchema.statics.completelyDeletePageRecursively = async function(targetPage, user, options = {}) {
|
|
|
+ const pagePath = targetPage.path;
|
|
|
|
|
|
- const findOpts = { includeRedirect: true, includeTrashed: true };
|
|
|
+ const findOpts = { includeTrashed: true };
|
|
|
+
|
|
|
+ // find descendants (this array does not include GRANT_RESTRICTED)
|
|
|
const result = await this.findListWithDescendants(pagePath, user, findOpts);
|
|
|
const pages = result.pages;
|
|
|
+ // add targetPage if 'grant' is GRANT_RESTRICTED
|
|
|
+ // because findListWithDescendants excludes GRANT_RESTRICTED pages
|
|
|
+ if (targetPage.grant === GRANT_RESTRICTED) {
|
|
|
+ pages.push(targetPage);
|
|
|
+ }
|
|
|
|
|
|
await Promise.all(pages.map((page) => {
|
|
|
return this.completelyDeletePage(page, user, options);
|
|
|
}));
|
|
|
-
|
|
|
- return pagePath;
|
|
|
};
|
|
|
|
|
|
pageSchema.statics.removeByPath = function(path) {
|