Parcourir la source

Merge branch 'feat/impl-custom-delegator-and-initialization' into feat/migrate-initial-named-queries

Taichi Masuyama il y a 4 ans
Parent
commit
32a0c4d59b

+ 0 - 2
packages/app/src/server/models/index.js

@@ -1,9 +1,7 @@
 import Page from '~/server/models/page';
-import NamedQuery from '~/server/models/named-query';
 
 module.exports = {
   Page,
-  NamedQuery,
   // TODO GW-2746 bulk export pages
   // PageArchive: require('./page-archive'),
   PageTagRelation: require('./page-tag-relation'),

+ 12 - 4
packages/app/src/server/models/obsolete-page.js

@@ -219,16 +219,24 @@ export class PageQueryBuilder {
     return this;
   }
 
-  addConditionAsRootOrHasParent() {
+  addConditionAsNonRootPage() {
+    this.query = this.query.and({ path: { $ne: '/' } });
+
+    return this;
+  }
+
+  addConditionAsNotMigrated() {
     this.query = this.query
-      .and({ $or: [{ parent: null }, { path: '/' }] });
+      .and({ parent: null });
 
     return this;
   }
 
-  addConditionAsNotRootOrHasParent() {
+  addConditionAsMigrated() {
     this.query = this.query
-      .and({ $nor: [{ parent: null }, { path: '/' }] });
+      .and({ parent: { $ne: null } });
+
+    return this;
   }
 
   /*

+ 5 - 1
packages/app/src/server/service/search-delegator/private-legacy-pages.ts

@@ -22,6 +22,9 @@ class PrivateLegacyPagesDelegator implements SearchDelegator<Data> {
     if (offset == null || limit == null) {
       throw Error('PrivateLegacyPagesDelegator requires pagination options (offset, limit).');
     }
+    if (user == null && userGroups == null) {
+      throw Error('Either of user and userGroups must not be null.');
+    }
 
     // find private legacy pages
     const Page = mongoose.model('Page') as PageModel;
@@ -30,7 +33,8 @@ class PrivateLegacyPagesDelegator implements SearchDelegator<Data> {
     const queryBuilder = new PageQueryBuilder(Page.find());
 
     const pages: PageDocument[] = await queryBuilder
-      .addConditionAsRootOrHasParent()
+      .addConditionAsNonRootPage()
+      .addConditionAsNotMigrated()
       .addConditionToFilteringByViewer(user, userGroups)
       .addConditionToPagenate(offset, limit)
       .query