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

Merge branch 'feat/inject-shouldFix-info-to-page-items-for-page-tree' of https://github.com/weseek/growi into feat/inject-shouldFix-info-to-page-items-for-page-tree

yohei0125 3 лет назад
Родитель
Сommit
20b98bec2e

+ 7 - 6
packages/app/src/server/models/page-operation.ts

@@ -47,6 +47,8 @@ export interface IPageOperation {
   options?: IOptionsForResuming,
   incForUpdatingDescendantCount?: number,
   unprocessableExpiryDate: Date,
+
+  isProcessable(): boolean
 }
 
 export interface PageOperationDocument extends IPageOperation, Document {}
@@ -57,7 +59,6 @@ export interface PageOperationModel extends Model<PageOperationDocument> {
   findByIdAndUpdatePageActionStage(pageOpId: ObjectIdLike, stage: PageActionStage): Promise<PageOperationDocumentHasId | null>
   findMainOps(filter?: FilterQuery<PageOperationDocument>, projection?: any, options?: QueryOptions): Promise<PageOperationDocumentHasId[]>
   deleteByActionTypes(deleteTypeList: PageActionType[]): Promise<void>
-  isProcessable(pageOp: PageOperationDocument): boolean
   extendExpiryDate(operationId: ObjectIdLike): Promise<void>
 }
 
@@ -136,11 +137,6 @@ schema.statics.deleteByActionTypes = async function(
   logger.info(`Deleted all PageOperation documents with actionType: [${actionTypes}]`);
 };
 
-schema.statics.isProcessable = function(pageOp: PageOperationDocument): boolean {
-  const { unprocessableExpiryDate } = pageOp;
-  return unprocessableExpiryDate == null || (unprocessableExpiryDate != null && new Date() > unprocessableExpiryDate);
-};
-
 /**
  * add TIME_TO_ADD_SEC to current time and update unprocessableExpiryDate with it
  */
@@ -149,4 +145,9 @@ schema.statics.extendExpiryDate = async function(operationId: ObjectIdLike): Pro
   await this.findByIdAndUpdate(operationId, { unprocessableExpiryDate: date });
 };
 
+schema.methods.isProcessable = function(): boolean {
+  const { unprocessableExpiryDate } = this;
+  return unprocessableExpiryDate == null || (unprocessableExpiryDate != null && new Date() > unprocessableExpiryDate);
+};
+
 export default getOrCreateModel<PageOperationDocument, PageOperationModel>('PageOperation', schema);

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

@@ -92,9 +92,7 @@ class PageOperationService {
       const pageId = pageOp.page._id.toString();
 
       const actionType = pageOp.actionType;
-      // Todo: dynamically change the value based on PageOperation prop,
-      // https://redmine.weseek.co.jp/issues/95971
-      const isProcessable = true;
+      const isProcessable = pageOp.isProcessable();
 
       // processData for processInfo
       const processData: IPageOperationProcessData = { [actionType]: { isProcessable } };

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

@@ -603,7 +603,7 @@ class PageService {
     if (pageOp == null) {
       throw Error('There is nothing to be processed right now');
     }
-    const isProcessable = await PageOperation.isProcessable(pageOp);
+    const isProcessable = pageOp.isProcessable();
     if (!isProcessable) {
       throw Error('This page operation is currently being processed');
     }