zahmis 5 лет назад
Родитель
Сommit
2ef02ace53
2 измененных файлов с 14 добавлено и 10 удалено
  1. 2 1
      src/client/js/components/PageDuplicateModal.jsx
  2. 12 9
      src/server/routes/apiv3/pages.js

+ 2 - 1
src/client/js/components/PageDuplicateModal.jsx

@@ -72,9 +72,10 @@ const PageDuplicateModal = (props) => {
       setErrorMessage(null);
       const res = await appContainer.apiv3Post('/pages/duplicate', { pageId, pageNameInput });
       const { result } = res;
-      window.location.href = encodeURI(`${result.path}?duplicated=${path}`);
+      window.location.href = encodeURI(`${result}?duplicated=${path}`);
     }
     catch (err) {
+      console.log(err);
       setErrorCode(err.code);
       setErrorMessage(err.message);
     }

+ 12 - 9
src/server/routes/apiv3/pages.js

@@ -5,6 +5,8 @@ const logger = loggerFactory('growi:routes:apiv3:pages'); // eslint-disable-line
 const express = require('express');
 const pathUtils = require('growi-commons').pathUtils;
 
+const ErrorV3 = require('../../models/vo/error-apiv3');
+
 
 const router = express.Router();
 
@@ -24,6 +26,7 @@ module.exports = (crowi) => {
   const PageTagRelation = crowi.model('PageTagRelation');
   const GlobalNotificationSetting = crowi.model('GlobalNotificationSetting');
 
+
   const globalNotificationService = crowi.getGlobalNotificationService();
   const { pageService, slackNotificationService } = crowi;
 
@@ -204,6 +207,15 @@ module.exports = (crowi) => {
     req.body.grantUserGroupId = page.grantedGroup;
     req.body.pageTags = originTags;
 
+    // check page existence
+    const isExist = (await Page.count(req.body.path)) > 0;
+    if (isExist) {
+      res.code = 'page_exists';
+      return res.apiv3Err(new ErrorV3('Page exists'), 409);
+      // return res.apiv3Err('Page exists', 409);
+
+    }
+
     const createdPage = await Page.create(req.body.path, req.body.body, req.user);
 
     let savedTags;
@@ -214,15 +226,6 @@ module.exports = (crowi) => {
 
     const result = { page: pageService.serializeToObj(createdPage), tags: savedTags };
 
-
-    // global notification
-    try {
-      await globalNotificationService.fire(GlobalNotificationSetting.EVENT.PAGE_CREATE, createdPage, req.user);
-    }
-    catch (err) {
-      logger.error('Create notification failed', err);
-    }
-
     return res.apiv3(result);
   });