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

Added option to exclude wip pages in pages/recent

Shun Miyazawa 2 лет назад
Родитель
Сommit
058e8ff28f
2 измененных файлов с 26 добавлено и 1 удалено
  1. 17 0
      apps/app/src/server/models/page.ts
  2. 9 1
      apps/app/src/server/routes/apiv3/pages/index.js

+ 17 - 0
apps/app/src/server/models/page.ts

@@ -204,6 +204,18 @@ export class PageQueryBuilder {
     return this;
     return this;
   }
   }
 
 
+  addConditionToExcludeWipPage(): PageQueryBuilder {
+    this.query = this.query
+      .and({
+        $or: [
+          { wip: undefined },
+          { wip: false },
+        ],
+      });
+
+    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.
@@ -655,10 +667,15 @@ schema.statics.findRecentUpdatedPages = async function(
 
 
   const baseQuery = this.find({});
   const baseQuery = this.find({});
   const queryBuilder = new PageQueryBuilder(baseQuery, includeEmpty);
   const queryBuilder = new PageQueryBuilder(baseQuery, includeEmpty);
+
   if (!options.includeTrashed) {
   if (!options.includeTrashed) {
     queryBuilder.addConditionToExcludeTrashed();
     queryBuilder.addConditionToExcludeTrashed();
   }
   }
 
 
+  if (!options.includeWipPage) {
+    queryBuilder.addConditionToExcludeWipPage();
+  }
+
   queryBuilder.addConditionToListWithDescendants(path, options);
   queryBuilder.addConditionToListWithDescendants(path, options);
   queryBuilder.populateDataToList(User.USER_FIELDS_EXCEPT_CONFIDENTIAL);
   queryBuilder.populateDataToList(User.USER_FIELDS_EXCEPT_CONFIDENTIAL);
   await queryBuilder.addViewerCondition(user);
   await queryBuilder.addViewerCondition(user);

+ 9 - 1
apps/app/src/server/routes/apiv3/pages/index.js

@@ -160,6 +160,11 @@ module.exports = (crowi) => {
   const addActivity = generateAddActivityMiddleware(crowi);
   const addActivity = generateAddActivityMiddleware(crowi);
 
 
   const validator = {
   const validator = {
+    recent: [
+      query('limit').optional().isInt().withMessage('limit must be integer'),
+      query('offset').optional().isInt().withMessage('offset must be integer'),
+      query('includeWipPage').optional().isBoolean().withMessage('includeWipPages must be boolean'),
+    ],
     renamePage: [
     renamePage: [
       body('pageId').isMongoId().withMessage('pageId is required'),
       body('pageId').isMongoId().withMessage('pageId is required'),
       body('revisionId').optional({ nullable: true }).isMongoId().withMessage('revisionId is required'), // required when v4
       body('revisionId').optional({ nullable: true }).isMongoId().withMessage('revisionId is required'), // required when v4
@@ -216,12 +221,15 @@ module.exports = (crowi) => {
    *            description: Return pages recently updated
    *            description: Return pages recently updated
    *
    *
    */
    */
-  router.get('/recent', accessTokenParser, loginRequired, async(req, res) => {
+  router.get('/recent', accessTokenParser, loginRequired, validator.recent, apiV3FormValidator, async(req, res) => {
     const limit = parseInt(req.query.limit) || 20;
     const limit = parseInt(req.query.limit) || 20;
     const offset = parseInt(req.query.offset) || 0;
     const offset = parseInt(req.query.offset) || 0;
+    const includeWipPage = JSON.parse(req.query.includeWipPage ?? true); // String to boolean, Requires validation by express-validator before conversion
+
     const queryOptions = {
     const queryOptions = {
       offset,
       offset,
       limit,
       limit,
+      includeWipPage,
       includeTrashed: false,
       includeTrashed: false,
       isRegExpEscapedFromPath: true,
       isRegExpEscapedFromPath: true,
       sort: 'updatedAt',
       sort: 'updatedAt',