Taichi Masuyama 4 лет назад
Родитель
Сommit
89a8fef63d

+ 30 - 0
packages/app/src/server/models/page.ts

@@ -897,6 +897,36 @@ export function generateGrantCondition(
   };
 }
 
+/**
+ * Returns true if the page's schema is v4 by checking its values.
+ * This does not check grantedUser or grantedGroup.
+ * @param page PageDocument
+ * @returns boolean
+ */
+schema.statics.isV4Page = function(page): boolean {
+  const {
+    path, parent, grant, status,
+  } = page;
+
+  if (grant === GRANT_RESTRICTED || grant === GRANT_SPECIFIED) {
+    return false;
+  }
+
+  if (status === STATUS_DELETED) {
+    return false;
+  }
+
+  if (isTopPage(path)) {
+    return false;
+  }
+
+  if (parent != null) {
+    return false;
+  }
+
+  return true;
+};
+
 schema.statics.generateGrantCondition = generateGrantCondition;
 
 export type PageCreateOptions = {

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

@@ -367,15 +367,10 @@ class PageGrantService {
 
     for await (const page of pages) {
       const {
-        path, grant, status, grantedUsers: grantedUserIds, grantedGroup: grantedGroupId,
+        path, grant, grantedUsers: grantedUserIds, grantedGroup: grantedGroupId,
       } = page;
 
-      if (grant === Page.GRANT_RESTRICTED || grant === Page.GRANT_SPECIFIED) {
-        nonNormalizable.push(page);
-        continue;
-      }
-
-      if (status === Page.STATUS_DELETED) {
+      if (Page.isV4Page(page)) {
         nonNormalizable.push(page);
         continue;
       }