Skip to content

Commit

Permalink
Merge pull request weseek#9099 from weseek/fix/151652-153892-the-issu…
Browse files Browse the repository at this point in the history
…e-users-can-browse-the-content-of-revision-in-history-of-perticular-page-when-broken-revision-document-exists

fix: Display revisions only if they are not corrupted
  • Loading branch information
mergify[bot] authored Oct 7, 2024
2 parents e899315 + 2f87e3c commit c857555
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion apps/app/src/server/routes/apiv3/revisions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ErrorV3 } from '@growi/core/dist/models';
import { serializeUserSecurely } from '@growi/core/dist/models/serializers';
import express from 'express';
import { connection } from 'mongoose';

import { Revision } from '~/server/models/revision';
import { normalizeLatestRevisionIfBroken } from '~/server/service/revision/normalize-latest-revision-if-broken';
Expand All @@ -14,6 +15,8 @@ const { query, param } = require('express-validator');

const router = express.Router();

const MIGRATION_FILE_NAME = '20211227060705-revision-path-to-page-id-schema-migration--fixed-7549';

/**
* @swagger
* tags:
Expand Down Expand Up @@ -110,6 +113,23 @@ module.exports = (crowi) => {
* description: Return revisions belong to page
*
*/
let cachedAppliedAt = null;

const getAppliedAtOfTheMigrationFile = async() => {

if (cachedAppliedAt != null) {
return cachedAppliedAt;
}

const migrationCollection = connection.collection('migrations');
const migration = await migrationCollection.findOne({ fileName: { $regex: `^${MIGRATION_FILE_NAME}` } });
const appliedAt = migration.appliedAt;

cachedAppliedAt = appliedAt;

return appliedAt;
};

router.get('/list', certifySharedPage, accessTokenParser, loginRequired, validator.retrieveRevisions, apiV3FormValidator, async(req, res) => {
const pageId = req.query.pageId;
const limit = req.query.limit || await crowi.configManager.getConfig('crowi', 'customize:showPageLimitationS') || 10;
Expand All @@ -131,6 +151,9 @@ module.exports = (crowi) => {

try {
const page = await Page.findOne({ _id: pageId });

const appliedAt = await getAppliedAtOfTheMigrationFile();

const queryOpts = {
offset,
sort: { createdAt: -1 },
Expand All @@ -143,8 +166,14 @@ module.exports = (crowi) => {
queryOpts.pagination = true;
}

const queryCondition = {
pageId: page._id,
createdAt: { $gt: appliedAt },
};

// https://redmine.weseek.co.jp/issues/151652
const paginateResult = await Revision.paginate(
{ pageId: page._id },
queryCondition,
queryOpts,
);

Expand Down

0 comments on commit c857555

Please sign in to comment.