Forráskód Böngészése

consistency of task title

zahmis 5 éve
szülő
commit
6a9841bb33

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

@@ -54,7 +54,7 @@ const PageDuplicateModal = (props) => {
     try {
       setErrorCode(null);
       setErrorMessage(null);
-      const res = await appContainer.apiv3Post('/pages/duplicate', { pageId, pageNameInput });
+      const res = await appContainer.apiPost('/pages.duplicate', { page_id: pageId, new_path: pageNameInput });
       const { page } = res;
       window.location.href = encodeURI(`${page.path}?duplicated=${path}`);
     }

+ 0 - 33
src/server/routes/apiv3/pages.js

@@ -16,8 +16,6 @@ module.exports = (crowi) => {
   const loginRequired = require('../../middlewares/login-required')(crowi, true);
   const adminRequired = require('../../middlewares/admin-required')(crowi);
   const csrf = require('../../middlewares/csrf')(crowi);
-  const pathUtils = require('growi-commons').pathUtils;
-  const ApiResponse = require('../../util/apiResponse');
 
   const Page = crowi.model('Page');
 
@@ -84,37 +82,6 @@ module.exports = (crowi) => {
     }
   });
 
-  /**
-   * GW-3143 edit swagger
-   */
-  router.post('/duplicate', async(req, res) => {
-    const { pageId, pageNameInput } = req.body;
-    let newPagePath = pathUtils.normalizePath(pageNameInput);
-
-    const page = await Page.findByIdAndViewer(pageId, req.user);
-
-    if (page == null) {
-      return res.json(ApiResponse.error(`Page '${pageId}' is not found or forbidden`, 'notfound_or_forbidden'));
-    }
-
-    // check whether path starts slash
-    newPagePath = pathUtils.addHeadingSlash(newPagePath);
-
-    await page.populateDataToShowRevision();
-    const originTags = await page.findRelatedTagsById();
-
-    req.body.path = newPagePath;
-    req.body.body = page.revision.body;
-    req.body.grant = page.grant;
-    req.body.grantedUsers = page.grantedUsers;
-    req.body.grantUserGroupId = page.grantedGroup;
-    req.body.pageTags = originTags;
-
-    // return api.create(req, res);
-    // 以下はダミーです
-    return res.apiv3({});
-  });
-
   router.get('/duplicate', loginRequired, async(req, res) => {
     const { path, pageId } = req.query;
     const searchWord = new RegExp(`^${path}`);

+ 2 - 1
src/server/routes/index.js

@@ -147,7 +147,8 @@ module.exports = function(crowi, app) {
   app.post('/_api/pages.rename'       , accessTokenParser , loginRequiredStrictly , csrf, page.api.rename);
   app.post('/_api/pages.remove'       , loginRequiredStrictly , csrf, page.api.remove); // (Avoid from API Token)
   app.post('/_api/pages.revertRemove' , loginRequiredStrictly , csrf, page.api.revertRemove); // (Avoid from API Token)
-  app.post('/_api/pages.unlink'       , loginRequiredStrictly , csrf, page.api.unlink); // (Avoid from API Token)
+  app.post('/_api/pages.unlink', loginRequiredStrictly, csrf, page.api.unlink); // (Avoid from API Token)
+  app.post('/_api/pages.duplicate', accessTokenParser, loginRequiredStrictly, csrf, page.api.duplicate);
   app.get('/tags'                     , loginRequired, tag.showPage);
   app.get('/_api/tags.list'           , accessTokenParser, loginRequired, tag.api.list);
   app.get('/_api/tags.search'         , accessTokenParser, loginRequired, tag.api.search);

+ 72 - 0
src/server/routes/page.js

@@ -1446,6 +1446,78 @@ module.exports = function(crowi, app) {
     return page;
   };
 
+  /**
+   * @swagger
+   *
+   *    /pages.duplicate:
+   *      post:
+   *        tags: [Pages]
+   *        operationId: duplicatePage
+   *        summary: /pages.duplicate
+   *        description: Duplicate page
+   *        requestBody:
+   *          content:
+   *            application/json:
+   *              schema:
+   *                properties:
+   *                  page_id:
+   *                    $ref: '#/components/schemas/Page/properties/_id'
+   *                  new_path:
+   *                    $ref: '#/components/schemas/Page/properties/path'
+   *                required:
+   *                  - page_id
+   *        responses:
+   *          200:
+   *            description: Succeeded to duplicate page.
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  properties:
+   *                    ok:
+   *                      $ref: '#/components/schemas/V1Response/properties/ok'
+   *                    page:
+   *                      $ref: '#/components/schemas/Page'
+   *                    tags:
+   *                      $ref: '#/components/schemas/Tags'
+   *          403:
+   *            $ref: '#/components/responses/403'
+   *          500:
+   *            $ref: '#/components/responses/500'
+   */
+  /**
+   * @api {post} /pages.duplicate Duplicate page
+   * @apiName DuplicatePage
+   * @apiGroup Page
+   *
+   * @apiParam {String} page_id Page Id.
+   * @apiParam {String} new_path New path name.
+   */
+  api.duplicate = async function(req, res) {
+    const pageId = req.body.page_id;
+    let newPagePath = pathUtils.normalizePath(req.body.new_path);
+
+    const page = await Page.findByIdAndViewer(pageId, req.user);
+
+    if (page == null) {
+      return res.json(ApiResponse.error(`Page '${pageId}' is not found or forbidden`, 'notfound_or_forbidden'));
+    }
+
+    // check whether path starts slash
+    newPagePath = pathUtils.addHeadingSlash(newPagePath);
+
+    await page.populateDataToShowRevision();
+    const originTags = await page.findRelatedTagsById();
+
+    req.body.path = newPagePath;
+    req.body.body = page.revision.body;
+    req.body.grant = page.grant;
+    req.body.grantedUsers = page.grantedUsers;
+    req.body.grantUserGroupId = page.grantedGroup;
+    req.body.pageTags = originTags;
+
+    return api.create(req, res);
+  };
+
   /**
    * @api {post} /pages.unlink Remove the redirecting page
    * @apiName UnlinkPage