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

Replaced redirectTo => PageRedirect

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

+ 0 - 1
packages/app/src/interfaces/page.ts

@@ -17,7 +17,6 @@ export interface IPage {
   parent: Ref<IPage> | null,
   parent: Ref<IPage> | null,
   descendantCount: number,
   descendantCount: number,
   isEmpty: boolean,
   isEmpty: boolean,
-  redirectTo: string,
   grant: number,
   grant: number,
   grantedUsers: Ref<IUser>[],
   grantedUsers: Ref<IUser>[],
   grantedGroup: Ref<any>,
   grantedGroup: Ref<any>,

+ 0 - 44
packages/app/src/server/models/obsolete-page.js

@@ -104,11 +104,6 @@ export class PageQueryBuilder {
     return this;
     return this;
   }
   }
 
 
-  addConditionToExcludeRedirect() {
-    this.query = this.query.and({ redirectTo: null });
-    return this;
-  }
-
   /**
   /**
    * generate the query to find the pages '{path}/*' and '{path}' self.
    * generate the query to find the pages '{path}/*' and '{path}' self.
    * If top page, return without doing anything.
    * If top page, return without doing anything.
@@ -690,10 +685,6 @@ export const getPageSchema = (crowi) => {
     return queryBuilder.query.exec();
     return queryBuilder.query.exec();
   };
   };
 
 
-  pageSchema.statics.findByRedirectTo = function(path) {
-    return this.findOne({ redirectTo: path });
-  };
-
   /**
   /**
    * find pages that is match with `path` and its descendants
    * find pages that is match with `path` and its descendants
    */
    */
@@ -714,7 +705,6 @@ export const getPageSchema = (crowi) => {
 
 
     const builder = new PageQueryBuilder(this.find(), includeEmpty);
     const builder = new PageQueryBuilder(this.find(), includeEmpty);
     builder.addConditionToListWithDescendants(page.path, option);
     builder.addConditionToListWithDescendants(page.path, option);
-    builder.addConditionToExcludeRedirect();
 
 
     // add grant conditions
     // add grant conditions
     await addConditionToFilteringByViewerToEdit(builder, user);
     await addConditionToFilteringByViewerToEdit(builder, user);
@@ -765,9 +755,6 @@ export const getPageSchema = (crowi) => {
     const opt = Object.assign({}, option);
     const opt = Object.assign({}, option);
     const builder = new PageQueryBuilder(this.find({ _id: { $in: ids } }));
     const builder = new PageQueryBuilder(this.find({ _id: { $in: ids } }));
 
 
-    if (excludeRedirect) {
-      builder.addConditionToExcludeRedirect();
-    }
     builder.addConditionToPagenate(opt.offset, opt.limit);
     builder.addConditionToPagenate(opt.offset, opt.limit);
 
 
     // count
     // count
@@ -804,10 +791,6 @@ export const getPageSchema = (crowi) => {
     if (!opt.includeTrashed) {
     if (!opt.includeTrashed) {
       builder.addConditionToExcludeTrashed();
       builder.addConditionToExcludeTrashed();
     }
     }
-    // exclude redirect pages
-    if (!opt.includeRedirect) {
-      builder.addConditionToExcludeRedirect();
-    }
 
 
     // add grant conditions
     // add grant conditions
     await addConditionToFilteringByViewerForList(builder, user, showAnyoneKnowsLink);
     await addConditionToFilteringByViewerForList(builder, user, showAnyoneKnowsLink);
@@ -1009,7 +992,6 @@ export const getPageSchema = (crowi) => {
     const Page = this;
     const Page = this;
     const Revision = crowi.model('Revision');
     const Revision = crowi.model('Revision');
     const format = options.format || 'markdown';
     const format = options.format || 'markdown';
-    const redirectTo = options.redirectTo || null;
     const grantUserGroupId = options.grantUserGroupId || null;
     const grantUserGroupId = options.grantUserGroupId || null;
 
 
     // sanitize path
     // sanitize path
@@ -1031,7 +1013,6 @@ export const getPageSchema = (crowi) => {
     page.path = path;
     page.path = path;
     page.creator = user;
     page.creator = user;
     page.lastUpdateUser = user;
     page.lastUpdateUser = user;
-    page.redirectTo = redirectTo;
     page.status = STATUS_PUBLISHED;
     page.status = STATUS_PUBLISHED;
 
 
     await validateAppliedScope(user, grant, grantUserGroupId);
     await validateAppliedScope(user, grant, grantUserGroupId);
@@ -1079,8 +1060,6 @@ export const getPageSchema = (crowi) => {
     const builder = new PageQueryBuilder(this.find());
     const builder = new PageQueryBuilder(this.find());
     builder.addConditionToListWithDescendants(parentPage.path);
     builder.addConditionToListWithDescendants(parentPage.path);
 
 
-    builder.addConditionToExcludeRedirect();
-
     // add grant conditions
     // add grant conditions
     await addConditionToFilteringByViewerToEdit(builder, user);
     await addConditionToFilteringByViewerToEdit(builder, user);
 
 
@@ -1105,29 +1084,6 @@ export const getPageSchema = (crowi) => {
     return this.findOneAndRemove({ path }).exec();
     return this.findOneAndRemove({ path }).exec();
   };
   };
 
 
-  /**
-   * remove the page that is redirecting to specified `pagePath` recursively
-   *  ex: when
-   *    '/page1' redirects to '/page2' and
-   *    '/page2' redirects to '/page3'
-   *    and given '/page3',
-   *    '/page1' and '/page2' will be removed
-   *
-   * @param {string} pagePath
-   */
-  pageSchema.statics.removeRedirectOriginPageByPath = async function(pagePath) {
-    const redirectPage = await this.findByRedirectTo(pagePath);
-
-    if (redirectPage == null) {
-      return;
-    }
-
-    // remove
-    await this.findByIdAndRemove(redirectPage.id);
-    // remove recursive
-    await this.removeRedirectOriginPageByPath(redirectPage.path);
-  };
-
   pageSchema.statics.findListByPathsArray = async function(paths, includeEmpty = false) {
   pageSchema.statics.findListByPathsArray = async function(paths, includeEmpty = false) {
     const queryBuilder = new PageQueryBuilder(this.find(), includeEmpty);
     const queryBuilder = new PageQueryBuilder(this.find(), includeEmpty);
     queryBuilder.addConditionToListByPathsArray(paths);
     queryBuilder.addConditionToListByPathsArray(paths);

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

@@ -74,7 +74,6 @@ const schema = new Schema<PageDocument, PageModel>({
     type: String, required: true, index: true,
     type: String, required: true, index: true,
   },
   },
   revision: { type: ObjectId, ref: 'Revision' },
   revision: { type: ObjectId, ref: 'Revision' },
-  redirectTo: { type: String, index: true },
   status: { type: String, default: STATUS_PUBLISHED, index: true },
   status: { type: String, default: STATUS_PUBLISHED, index: true },
   grant: { type: Number, default: GRANT_PUBLIC, index: true },
   grant: { type: Number, default: GRANT_PUBLIC, index: true },
   grantedUsers: [{ type: ObjectId, ref: 'User' }],
   grantedUsers: [{ type: ObjectId, ref: 'User' }],

+ 0 - 4
packages/app/src/server/routes/apiv3/page.js

@@ -74,10 +74,6 @@ const ErrorV3 = require('../../models/vo/error-apiv3');
  *            type: string
  *            type: string
  *            description: page path
  *            description: page path
  *            example: /
  *            example: /
- *          redirectTo:
- *            type: string
- *            description: redirect path
- *            example: ""
  *          revision:
  *          revision:
  *            type: string
  *            type: string
  *            description: page revision
  *            description: page revision

+ 0 - 4
packages/app/src/server/routes/apiv3/pages.js

@@ -110,10 +110,6 @@ const LIMIT_FOR_LIST = 10;
  *            type: string
  *            type: string
  *            description: page path
  *            description: page path
  *            example: /Sandbox/Math
  *            example: /Sandbox/Math
- *          redirectTo:
- *            type: string
- *            description: redirect path
- *            example: ""
  *          revision:
  *          revision:
  *            type: string
  *            type: string
  *            description: revision ID
  *            description: revision ID

+ 11 - 9
packages/app/src/server/routes/page.js

@@ -1,9 +1,11 @@
 import { pagePathUtils } from '@growi/core';
 import { pagePathUtils } from '@growi/core';
 import urljoin from 'url-join';
 import urljoin from 'url-join';
 import { body } from 'express-validator';
 import { body } from 'express-validator';
+import mongoose from 'mongoose';
 
 
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 import UpdatePost from '../models/update-post';
 import UpdatePost from '../models/update-post';
+import { PageRedirectModel } from '../models/page-redirect';
 
 
 const { isCreatablePage, isTopPage } = pagePathUtils;
 const { isCreatablePage, isTopPage } = pagePathUtils;
 const { serializePageSecurely } = require('../models/serializers/page-serializer');
 const { serializePageSecurely } = require('../models/serializers/page-serializer');
@@ -71,10 +73,6 @@ const { serializeUserSecurely } = require('../models/serializers/user-serializer
  *            type: string
  *            type: string
  *            description: page path
  *            description: page path
  *            example: /
  *            example: /
- *          redirectTo:
- *            type: string
- *            description: redirect path
- *            example: ""
  *          revision:
  *          revision:
  *            $ref: '#/components/schemas/Revision'
  *            $ref: '#/components/schemas/Revision'
  *          status:
  *          status:
@@ -146,6 +144,7 @@ module.exports = function(crowi, app) {
   const PageTagRelation = crowi.model('PageTagRelation');
   const PageTagRelation = crowi.model('PageTagRelation');
   const GlobalNotificationSetting = crowi.model('GlobalNotificationSetting');
   const GlobalNotificationSetting = crowi.model('GlobalNotificationSetting');
   const ShareLink = crowi.model('ShareLink');
   const ShareLink = crowi.model('ShareLink');
+  const PageRedirect = mongoose.model('PageRedirect');
 
 
   const ApiResponse = require('../util/apiResponse');
   const ApiResponse = require('../util/apiResponse');
   const getToday = require('../util/getToday');
   const getToday = require('../util/getToday');
@@ -429,11 +428,6 @@ module.exports = function(crowi, app) {
 
 
     const { path } = page; // this must exist
     const { path } = page; // this must exist
 
 
-    if (page.redirectTo) {
-      debug(`Redirect to '${page.redirectTo}'`);
-      return res.redirect(`${encodeURI(page.redirectTo)}?redirectFrom=${encodeURIComponent(path)}`);
-    }
-
     logger.debug('Page is found when processing pageShowForGrowiBehavior', page._id, path);
     logger.debug('Page is found when processing pageShowForGrowiBehavior', page._id, path);
 
 
     const limit = 50;
     const limit = 50;
@@ -611,6 +605,14 @@ module.exports = function(crowi, app) {
    */
    */
   async function redirector(req, res, next, path) {
   async function redirector(req, res, next, path) {
     const pages = await Page.findByPathAndViewer(path, req.user, null, false, true);
     const pages = await Page.findByPathAndViewer(path, req.user, null, false, true);
+
+    if (pages.length === 0) {
+      const pageRedirect = await PageRedirect.findOne({ fromPath: path });
+      if (pageRedirect != null) {
+        return res.redirect(`${encodeURI(pageRedirect.toPath)}?redirectFrom=${encodeURIComponent(path)}`);
+      }
+    }
+
     const { redirectFrom } = req.query;
     const { redirectFrom } = req.query;
 
 
     if (pages.length >= 2) {
     if (pages.length >= 2) {

+ 0 - 1
packages/app/src/server/service/page.ts

@@ -254,7 +254,6 @@ class PageService {
 
 
     const builder = new PageQueryBuilder(Page.find(), true)
     const builder = new PageQueryBuilder(Page.find(), true)
       .addConditionAsNotMigrated() // to avoid affecting v5 pages
       .addConditionAsNotMigrated() // to avoid affecting v5 pages
-      .addConditionToExcludeRedirect()
       .addConditionToListOnlyDescendants(targetPagePath);
       .addConditionToListOnlyDescendants(targetPagePath);
 
 
     await Page.addConditionToFilteringByViewerToEdit(builder, userToOperate);
     await Page.addConditionToFilteringByViewerToEdit(builder, userToOperate);

+ 3 - 3
packages/app/src/server/service/search-delegator/elasticsearch.ts

@@ -87,7 +87,7 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
   }
   }
 
 
   shouldIndexed(page) {
   shouldIndexed(page) {
-    return page.revision != null && page.redirectTo == null;
+    return page.revision != null;
   }
   }
 
 
   initClient() {
   initClient() {
@@ -418,8 +418,8 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
     const shouldIndexed = this.shouldIndexed.bind(this);
     const shouldIndexed = this.shouldIndexed.bind(this);
     const bulkWrite = this.client.bulk.bind(this.client);
     const bulkWrite = this.client.bulk.bind(this.client);
 
 
-    const findQuery = new PageQueryBuilder(queryFactory()).addConditionToExcludeRedirect().query;
-    const countQuery = new PageQueryBuilder(queryFactory()).addConditionToExcludeRedirect().query;
+    const findQuery = new PageQueryBuilder(queryFactory()).query;
+    const countQuery = new PageQueryBuilder(queryFactory()).query;
 
 
     const totalCount = await countQuery.count();
     const totalCount = await countQuery.count();
 
 

+ 48 - 48
packages/app/src/test/integration/service/page.test.js

@@ -384,8 +384,8 @@ describe('PageService', () => {
       test('rename page with createRedirectPage option', async() => {
       test('rename page with createRedirectPage option', async() => {
 
 
         const resultPage = await crowi.pageService.renamePage(parentForRename3, '/renamed3', testUser2, { createRedirectPage: true });
         const resultPage = await crowi.pageService.renamePage(parentForRename3, '/renamed3', testUser2, { createRedirectPage: true });
-        const redirectedFromPage = await Page.findOne({ path: '/parentForRename3' });
-        const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename3' });
+        // const redirectedFromPage = await Page.findOne({ path: '/parentForRename3' });
+        // const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename3' });
 
 
         expect(xssSpy).toHaveBeenCalled();
         expect(xssSpy).toHaveBeenCalled();
         expect(renameDescendantsWithStreamSpy).not.toHaveBeenCalled();
         expect(renameDescendantsWithStreamSpy).not.toHaveBeenCalled();
@@ -395,13 +395,13 @@ describe('PageService', () => {
         expect(resultPage.updatedAt).toEqual(parentForRename3.updatedAt);
         expect(resultPage.updatedAt).toEqual(parentForRename3.updatedAt);
         expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
         expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
 
 
-        expect(redirectedFromPage).not.toBeNull();
-        expect(redirectedFromPage.path).toBe('/parentForRename3');
-        expect(redirectedFromPage.redirectTo).toBe('/renamed3');
+        // expect(redirectedFromPage).not.toBeNull();
+        // expect(redirectedFromPage.path).toBe('/parentForRename3');
+        // expect(redirectedFromPage.redirectTo).toBe('/renamed3');
 
 
-        expect(redirectedFromPageRevision).not.toBeNull();
-        expect(redirectedFromPageRevision.path).toBe('/parentForRename3');
-        expect(redirectedFromPageRevision.body).toBe('redirect /renamed3');
+        // expect(redirectedFromPageRevision).not.toBeNull();
+        // expect(redirectedFromPageRevision.path).toBe('/parentForRename3');
+        // expect(redirectedFromPageRevision.body).toBe('redirect /renamed3');
       });
       });
 
 
       test('rename page with isRecursively', async() => {
       test('rename page with isRecursively', async() => {
@@ -480,8 +480,8 @@ describe('PageService', () => {
 
 
       await crowi.pageService.renameDescendants([childForRename3], testUser2, { createRedirectPage: true }, oldPagePathPrefix, newPagePathPrefix);
       await crowi.pageService.renameDescendants([childForRename3], testUser2, { createRedirectPage: true }, oldPagePathPrefix, newPagePathPrefix);
       const resultPage = await Page.findOne({ path: '/renamed3/child' });
       const resultPage = await Page.findOne({ path: '/renamed3/child' });
-      const redirectedFromPage = await Page.findOne({ path: '/parentForRename3/child' });
-      const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename3/child' });
+      // const redirectedFromPage = await Page.findOne({ path: '/parentForRename3/child' });
+      // const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForRename3/child' });
 
 
       expect(resultPage).not.toBeNull();
       expect(resultPage).not.toBeNull();
       expect(pageEventSpy).toHaveBeenCalledWith('updateMany', [childForRename3], testUser2);
       expect(pageEventSpy).toHaveBeenCalledWith('updateMany', [childForRename3], testUser2);
@@ -490,13 +490,13 @@ describe('PageService', () => {
       expect(resultPage.updatedAt).toEqual(childForRename3.updatedAt);
       expect(resultPage.updatedAt).toEqual(childForRename3.updatedAt);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
 
 
-      expect(redirectedFromPage).not.toBeNull();
-      expect(redirectedFromPage.path).toBe('/parentForRename3/child');
-      expect(redirectedFromPage.redirectTo).toBe('/renamed3/child');
+      // expect(redirectedFromPage).not.toBeNull();
+      // expect(redirectedFromPage.path).toBe('/parentForRename3/child');
+      // expect(redirectedFromPage.redirectTo).toBe('/renamed3/child');
 
 
-      expect(redirectedFromPageRevision).not.toBeNull();
-      expect(redirectedFromPageRevision.path).toBe('/parentForRename3/child');
-      expect(redirectedFromPageRevision.body).toBe('redirect /renamed3/child');
+      // expect(redirectedFromPageRevision).not.toBeNull();
+      // expect(redirectedFromPageRevision.path).toBe('/parentForRename3/child');
+      // expect(redirectedFromPageRevision.body).toBe('redirect /renamed3/child');
     });
     });
   });
   });
 
 
@@ -597,8 +597,8 @@ describe('PageService', () => {
 
 
     test('delete page without options', async() => {
     test('delete page without options', async() => {
       const resultPage = await crowi.pageService.deletePage(parentForDelete1, testUser2, { });
       const resultPage = await crowi.pageService.deletePage(parentForDelete1, testUser2, { });
-      const redirectedFromPage = await Page.findOne({ path: '/parentForDelete1' });
-      const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForDelete1' });
+      // const redirectedFromPage = await Page.findOne({ path: '/parentForDelete1' });
+      // const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForDelete1' });
 
 
       expect(getDeletedPageNameSpy).toHaveBeenCalled();
       expect(getDeletedPageNameSpy).toHaveBeenCalled();
       expect(deleteDescendantsWithStreamSpy).not.toHaveBeenCalled();
       expect(deleteDescendantsWithStreamSpy).not.toHaveBeenCalled();
@@ -610,13 +610,13 @@ describe('PageService', () => {
       expect(resultPage.updatedAt).toEqual(parentForDelete1.updatedAt);
       expect(resultPage.updatedAt).toEqual(parentForDelete1.updatedAt);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
 
 
-      expect(redirectedFromPage).not.toBeNull();
-      expect(redirectedFromPage.path).toBe('/parentForDelete1');
-      expect(redirectedFromPage.redirectTo).toBe('/trash/parentForDelete1');
+      // expect(redirectedFromPage).not.toBeNull();
+      // expect(redirectedFromPage.path).toBe('/parentForDelete1');
+      // expect(redirectedFromPage.redirectTo).toBe('/trash/parentForDelete1');
 
 
-      expect(redirectedFromPageRevision).not.toBeNull();
-      expect(redirectedFromPageRevision.path).toBe('/parentForDelete1');
-      expect(redirectedFromPageRevision.body).toBe('redirect /trash/parentForDelete1');
+      // expect(redirectedFromPageRevision).not.toBeNull();
+      // expect(redirectedFromPageRevision.path).toBe('/parentForDelete1');
+      // expect(redirectedFromPageRevision.body).toBe('redirect /trash/parentForDelete1');
 
 
       expect(pageEventSpy).toHaveBeenCalledWith('delete', parentForDelete1, testUser2);
       expect(pageEventSpy).toHaveBeenCalledWith('delete', parentForDelete1, testUser2);
       expect(pageEventSpy).toHaveBeenCalledWith('create', resultPage, testUser2);
       expect(pageEventSpy).toHaveBeenCalledWith('create', resultPage, testUser2);
@@ -625,8 +625,8 @@ describe('PageService', () => {
 
 
     test('delete page with isRecursively', async() => {
     test('delete page with isRecursively', async() => {
       const resultPage = await crowi.pageService.deletePage(parentForDelete2, testUser2, { }, true);
       const resultPage = await crowi.pageService.deletePage(parentForDelete2, testUser2, { }, true);
-      const redirectedFromPage = await Page.findOne({ path: '/parentForDelete2' });
-      const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForDelete2' });
+      // const redirectedFromPage = await Page.findOne({ path: '/parentForDelete2' });
+      // const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForDelete2' });
 
 
       expect(getDeletedPageNameSpy).toHaveBeenCalled();
       expect(getDeletedPageNameSpy).toHaveBeenCalled();
       expect(deleteDescendantsWithStreamSpy).toHaveBeenCalled();
       expect(deleteDescendantsWithStreamSpy).toHaveBeenCalled();
@@ -638,13 +638,13 @@ describe('PageService', () => {
       expect(resultPage.updatedAt).toEqual(parentForDelete2.updatedAt);
       expect(resultPage.updatedAt).toEqual(parentForDelete2.updatedAt);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
 
 
-      expect(redirectedFromPage).not.toBeNull();
-      expect(redirectedFromPage.path).toBe('/parentForDelete2');
-      expect(redirectedFromPage.redirectTo).toBe('/trash/parentForDelete2');
+      // expect(redirectedFromPage).not.toBeNull();
+      // expect(redirectedFromPage.path).toBe('/parentForDelete2');
+      // expect(redirectedFromPage.redirectTo).toBe('/trash/parentForDelete2');
 
 
-      expect(redirectedFromPageRevision).not.toBeNull();
-      expect(redirectedFromPageRevision.path).toBe('/parentForDelete2');
-      expect(redirectedFromPageRevision.body).toBe('redirect /trash/parentForDelete2');
+      // expect(redirectedFromPageRevision).not.toBeNull();
+      // expect(redirectedFromPageRevision.path).toBe('/parentForDelete2');
+      // expect(redirectedFromPageRevision.body).toBe('redirect /trash/parentForDelete2');
 
 
       expect(pageEventSpy).toHaveBeenCalledWith('delete', parentForDelete2, testUser2);
       expect(pageEventSpy).toHaveBeenCalledWith('delete', parentForDelete2, testUser2);
       expect(pageEventSpy).toHaveBeenCalledWith('create', resultPage, testUser2);
       expect(pageEventSpy).toHaveBeenCalledWith('create', resultPage, testUser2);
@@ -655,8 +655,8 @@ describe('PageService', () => {
     test('deleteDescendants', async() => {
     test('deleteDescendants', async() => {
       await crowi.pageService.deleteDescendants([childForDelete], testUser2);
       await crowi.pageService.deleteDescendants([childForDelete], testUser2);
       const resultPage = await Page.findOne({ path: '/trash/parentForDelete/child' });
       const resultPage = await Page.findOne({ path: '/trash/parentForDelete/child' });
-      const redirectedFromPage = await Page.findOne({ path: '/parentForDelete/child' });
-      const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForDelete/child' });
+      // const redirectedFromPage = await Page.findOne({ path: '/parentForDelete/child' });
+      // const redirectedFromPageRevision = await Revision.findOne({ path: '/parentForDelete/child' });
 
 
       expect(resultPage.status).toBe(Page.STATUS_DELETED);
       expect(resultPage.status).toBe(Page.STATUS_DELETED);
       expect(resultPage.path).toBe('/trash/parentForDelete/child');
       expect(resultPage.path).toBe('/trash/parentForDelete/child');
@@ -665,13 +665,13 @@ describe('PageService', () => {
       expect(resultPage.updatedAt).toEqual(childForDelete.updatedAt);
       expect(resultPage.updatedAt).toEqual(childForDelete.updatedAt);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
       expect(resultPage.lastUpdateUser).toEqual(testUser1._id);
 
 
-      expect(redirectedFromPage).not.toBeNull();
-      expect(redirectedFromPage.path).toBe('/parentForDelete/child');
-      expect(redirectedFromPage.redirectTo).toBe('/trash/parentForDelete/child');
+      // expect(redirectedFromPage).not.toBeNull();
+      // expect(redirectedFromPage.path).toBe('/parentForDelete/child');
+      // expect(redirectedFromPage.redirectTo).toBe('/trash/parentForDelete/child');
 
 
-      expect(redirectedFromPageRevision).not.toBeNull();
-      expect(redirectedFromPageRevision.path).toBe('/parentForDelete/child');
-      expect(redirectedFromPageRevision.body).toBe('redirect /trash/parentForDelete/child');
+      // expect(redirectedFromPageRevision).not.toBeNull();
+      // expect(redirectedFromPageRevision.path).toBe('/parentForDelete/child');
+      // expect(redirectedFromPageRevision.body).toBe('redirect /trash/parentForDelete/child');
     });
     });
   });
   });
 
 
@@ -753,14 +753,14 @@ describe('PageService', () => {
 
 
     test('revert deleted page when the redirect from page exists', async() => {
     test('revert deleted page when the redirect from page exists', async() => {
 
 
-      findByPathSpy = jest.spyOn(Page, 'findByPath').mockImplementation(() => {
-        return { redirectTo: '/trash/parentForRevert1' };
-      });
+      // findByPathSpy = jest.spyOn(Page, 'findByPath').mockImplementation(() => {
+      //   return { redirectTo: '/trash/parentForRevert1' };
+      // });
 
 
       const resultPage = await crowi.pageService.revertDeletedPage(parentForRevert1, testUser2);
       const resultPage = await crowi.pageService.revertDeletedPage(parentForRevert1, testUser2);
 
 
       expect(getRevertDeletedPageNameSpy).toHaveBeenCalledWith(parentForRevert1.path);
       expect(getRevertDeletedPageNameSpy).toHaveBeenCalledWith(parentForRevert1.path);
-      expect(findByPathSpy).toHaveBeenCalledWith('/parentForRevert1');
+      // expect(findByPathSpy).toHaveBeenCalledWith('/parentForRevert1');
       expect(deleteCompletelySpy).toHaveBeenCalled();
       expect(deleteCompletelySpy).toHaveBeenCalled();
       expect(revertDeletedDescendantsWithStreamSpy).not.toHaveBeenCalled();
       expect(revertDeletedDescendantsWithStreamSpy).not.toHaveBeenCalled();
 
 
@@ -793,9 +793,9 @@ describe('PageService', () => {
 
 
     test('revert deleted descendants', async() => {
     test('revert deleted descendants', async() => {
 
 
-      findSpy = jest.spyOn(Page, 'find').mockImplementation(() => {
-        return [{ path: '/parentForRevert/child', redirectTo: '/trash/parentForRevert/child' }];
-      });
+      // findSpy = jest.spyOn(Page, 'find').mockImplementation(() => {
+      //   return [{ path: '/parentForRevert/child', redirectTo: '/trash/parentForRevert/child' }];
+      // });
 
 
       await crowi.pageService.revertDeletedDescendants([childForRevert], testUser2);
       await crowi.pageService.revertDeletedDescendants([childForRevert], testUser2);
       const resultPage = await Page.findOne({ path: '/parentForRevert/child' });
       const resultPage = await Page.findOne({ path: '/parentForRevert/child' });
@@ -803,7 +803,7 @@ describe('PageService', () => {
       const revrtedFromPageRevision = await Revision.findOne({ path: '/trash/parentForRevert/child' });
       const revrtedFromPageRevision = await Revision.findOne({ path: '/trash/parentForRevert/child' });
 
 
       expect(getRevertDeletedPageNameSpy).toHaveBeenCalledWith(childForRevert.path);
       expect(getRevertDeletedPageNameSpy).toHaveBeenCalledWith(childForRevert.path);
-      expect(findSpy).toHaveBeenCalledWith({ path: { $in: ['/parentForRevert/child'] } });
+      // expect(findSpy).toHaveBeenCalledWith({ path: { $in: ['/parentForRevert/child'] } });
 
 
       expect(resultPage.path).toBe('/parentForRevert/child');
       expect(resultPage.path).toBe('/parentForRevert/child');
       expect(resultPage.lastUpdateUser._id).toEqual(testUser2._id);
       expect(resultPage.lastUpdateUser._id).toEqual(testUser2._id);

+ 1 - 2
packages/plugin-attachment-refs/src/server/routes/refs.js

@@ -166,8 +166,7 @@ module.exports = (crowi) => {
     if (prefix != null) {
     if (prefix != null) {
       builder = new PageQueryBuilder(Page.find())
       builder = new PageQueryBuilder(Page.find())
         .addConditionToListWithDescendants(prefix)
         .addConditionToListWithDescendants(prefix)
-        .addConditionToExcludeTrashed()
-        .addConditionToExcludeRedirect();
+        .addConditionToExcludeTrashed();
     }
     }
     // builder to get single page
     // builder to get single page
     else {
     else {

+ 1 - 2
packages/plugin-lsx/src/server/routes/lsx.js

@@ -195,8 +195,7 @@ module.exports = (crowi, app) => {
     }
     }
 
 
     builder
     builder
-      .addConditionToExcludeTrashed()
-      .addConditionToExcludeRedirect();
+      .addConditionToExcludeTrashed();
 
 
     return Page.addConditionToFilteringByViewerForList(builder, user);
     return Page.addConditionToFilteringByViewerForList(builder, user);
   }
   }