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

add more condition to canOperate

yohei0125 3 лет назад
Родитель
Сommit
db3362fc6e
1 измененных файлов с 28 добавлено и 6 удалено
  1. 28 6
      packages/app/src/server/service/page-operation.ts

+ 28 - 6
packages/app/src/server/service/page-operation.ts

@@ -25,21 +25,33 @@ class PageOperationService {
    * @returns boolean
    */
   async canOperate(isRecursively: boolean, fromPathToOp: string | null, toPathToOp: string | null): Promise<boolean> {
-    const mainOps = await PageOperation.findMainOps();
+    const pageOperations = await PageOperation.find();
 
-    if (mainOps.length === 0) {
+    if (pageOperations.length === 0) {
       return true;
     }
 
-    const toPaths = mainOps.map(op => op.toPath).filter((p): p is string => p != null);
+    const fromPaths = pageOperations.map(op => op.fromPath).filter((p): p is string => p != null);
+    const toPaths = pageOperations.map(op => op.toPath).filter((p): p is string => p != null);
 
     if (isRecursively) {
-
+      // fromPaths
+      if (fromPathToOp != null && !isTrashPage(fromPathToOp)) {
+        const flag = fromPaths.some(p => isEitherOfPathAreaOverlap(p, fromPathToOp));
+        if (flag) return false;
+      }
+      // toPaths
       if (fromPathToOp != null && !isTrashPage(fromPathToOp)) {
         const flag = toPaths.some(p => isEitherOfPathAreaOverlap(p, fromPathToOp));
         if (flag) return false;
       }
 
+      // fromPaths
+      if (toPathToOp != null && !isTrashPage(toPathToOp)) {
+        const flag = fromPaths.some(p => isPathAreaOverlap(p, toPathToOp));
+        if (flag) return false;
+      }
+      // toPaths
       if (toPathToOp != null && !isTrashPage(toPathToOp)) {
         const flag = toPaths.some(p => isPathAreaOverlap(p, toPathToOp));
         if (flag) return false;
@@ -47,17 +59,27 @@ class PageOperationService {
 
     }
     else {
-
+      // fromPaths
+      if (fromPathToOp != null && !isTrashPage(fromPathToOp)) {
+        const flag = fromPaths.some(p => isPathAreaOverlap(p, fromPathToOp));
+        if (flag) return false;
+      }
+      // toPaths
       if (fromPathToOp != null && !isTrashPage(fromPathToOp)) {
         const flag = toPaths.some(p => isPathAreaOverlap(p, fromPathToOp));
         if (flag) return false;
       }
 
+      // fromPaths
+      if (toPathToOp != null && !isTrashPage(toPathToOp)) {
+        const flag = fromPaths.some(p => isPathAreaOverlap(p, toPathToOp));
+        if (flag) return false;
+      }
+      // toPaths
       if (toPathToOp != null && !isTrashPage(toPathToOp)) {
         const flag = toPaths.some(p => isPathAreaOverlap(p, toPathToOp));
         if (flag) return false;
       }
-
     }
 
     return true;