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

return undefined if the path is root path

yohei0125 3 лет назад
Родитель
Сommit
cd947d21e6
2 измененных файлов с 8 добавлено и 3 удалено
  1. 6 1
      packages/app/src/server/models/page.ts
  2. 2 2
      packages/app/src/server/service/page.ts

+ 6 - 1
packages/app/src/server/models/page.ts

@@ -915,7 +915,12 @@ export function generateGrantCondition(
 
 
 schema.statics.generateGrantCondition = generateGrantCondition;
 schema.statics.generateGrantCondition = generateGrantCondition;
 
 
-schema.statics.findNotEmptyClosestAncestor = async function(path: string): Promise<PageDocument> {
+// find ancestor page with isEmpty: false. If parameter path is '/', return undefined
+schema.statics.findNonEmptyClosestAncestor = async function(path: string): Promise<PageDocument | undefined> {
+  if (path === '/') {
+    return;
+  }
+
   const builderForAncestors = new PageQueryBuilder(this.find(), false); // empty page not included
   const builderForAncestors = new PageQueryBuilder(this.find(), false); // empty page not included
 
 
   const ancestors = await builderForAncestors
   const ancestors = await builderForAncestors

+ 2 - 2
packages/app/src/server/service/page.ts

@@ -2178,8 +2178,8 @@ class PageService {
     if (page.isEmpty) {
     if (page.isEmpty) {
       // Need non-empty ancestor page to get its creator id because empty page does NOT have it.
       // Need non-empty ancestor page to get its creator id because empty page does NOT have it.
       // Use creator id of ancestor page to determine whether the empty page is deletable
       // Use creator id of ancestor page to determine whether the empty page is deletable
-      const notEmptyClosestAncestor = await Page.findNotEmptyClosestAncestor(page.path);
-      const creatorId = notEmptyClosestAncestor.creator;
+      const nonEmptyClosestAncestor = await Page.findNonEmptyClosestAncestor(page.path);
+      const creatorId = nonEmptyClosestAncestor != null ? nonEmptyClosestAncestor.creator : page.creator;
 
 
       const isDeletable = this.canDelete(page.path, creatorId, operator, false);
       const isDeletable = this.canDelete(page.path, creatorId, operator, false);
       const isAbleToDeleteCompletely = this.canDeleteCompletely(page.path, creatorId, operator, false); // use normal delete config
       const isAbleToDeleteCompletely = this.canDeleteCompletely(page.path, creatorId, operator, false); // use normal delete config