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

Apply isExistUserByUserPagePath

Shun Miyazawa 2 лет назад
Родитель
Сommit
be9faa7d22
1 измененных файлов с 22 добавлено и 1 удалено
  1. 22 1
      apps/app/src/server/routes/apiv3/pages.js

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

@@ -1,7 +1,7 @@
 
 
 import { PageGrant } from '@growi/core';
 import { PageGrant } from '@growi/core';
 import { ErrorV3 } from '@growi/core/dist/models';
 import { ErrorV3 } from '@growi/core/dist/models';
-import { isCreatablePage, isTrashPage } from '@growi/core/dist/utils/page-path-utils';
+import { isCreatablePage, isTrashPage, isUserPage } from '@growi/core/dist/utils/page-path-utils';
 import { normalizePath, addHeadingSlash, attachTitleHeader } from '@growi/core/dist/utils/path-utils';
 import { normalizePath, addHeadingSlash, attachTitleHeader } from '@growi/core/dist/utils/path-utils';
 
 
 import { SupportedTargetModel, SupportedAction } from '~/interfaces/activity';
 import { SupportedTargetModel, SupportedAction } from '~/interfaces/activity';
@@ -303,6 +303,13 @@ module.exports = (crowi) => {
     // check whether path starts slash
     // check whether path starts slash
     path = addHeadingSlash(path);
     path = addHeadingSlash(path);
 
 
+    if (isUserPage(path)) {
+      const isExistUser = await User.isExistUserByUserPagePath(path);
+      if (!isExistUser) {
+        return res.apiv3Err("Unable to create a page under a non-existent user's user page");
+      }
+    }
+
     const options = { overwriteScopesOfDescendants };
     const options = { overwriteScopesOfDescendants };
     if (grant != null) {
     if (grant != null) {
       options.grant = grant;
       options.grant = grant;
@@ -526,6 +533,13 @@ module.exports = (crowi) => {
       return res.apiv3Err(new ErrorV3(`Could not use the path '${newPagePath}'`, 'invalid_path'), 409);
       return res.apiv3Err(new ErrorV3(`Could not use the path '${newPagePath}'`, 'invalid_path'), 409);
     }
     }
 
 
+    if (isUserPage(newPagePath)) {
+      const isExistUser = await User.isExistUserByUserPagePath(newPagePath);
+      if (!isExistUser) {
+        return res.apiv3Err("Unable to rename a page under a non-existent user's user page");
+      }
+    }
+
     // check whether path starts slash
     // check whether path starts slash
     newPagePath = addHeadingSlash(newPagePath);
     newPagePath = addHeadingSlash(newPagePath);
 
 
@@ -756,6 +770,13 @@ module.exports = (crowi) => {
         return res.apiv3Err(new ErrorV3('This page path is invalid', 'invalid_path'), 400);
         return res.apiv3Err(new ErrorV3('This page path is invalid', 'invalid_path'), 400);
       }
       }
 
 
+      if (isUserPage(newPagePath)) {
+        const isExistUser = await User.isExistUserByUserPagePath(newPagePath);
+        if (!isExistUser) {
+          return res.apiv3Err("Unable to rename a page under a non-existent user's user page");
+        }
+      }
+
       // check page existence
       // check page existence
       const isExist = (await Page.count({ path: newPagePath })) > 0;
       const isExist = (await Page.count({ path: newPagePath })) > 0;
       if (isExist) {
       if (isExist) {