Explorar o código

creating a page from the page tree

Shun Miyazawa %!s(int64=4) %!d(string=hai) anos
pai
achega
0d46ce3f00

+ 2 - 2
packages/app/src/components/Sidebar/PageTree/Item.tsx

@@ -261,15 +261,15 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
     setNewPageInputShown(false);
     const parentPath = pathUtils.addTrailingSlash(page.path as string);
     const newPagePath = `${parentPath}${inputText}`;
-    const initialBody = `# ${newPagePath}`;
     const isCreatable = pagePathUtils.isCreatablePage(newPagePath);
 
     if (isCreatable) {
       const body = {
         path: newPagePath,
-        body: initialBody,
+        body: '',
         grant: page.grant,
         grantUserGroupId: page.grantedGroup,
+        createFromPageTree: true,
       };
 
       try {

+ 11 - 2
packages/app/src/server/routes/apiv3/pages.js

@@ -168,6 +168,7 @@ module.exports = (crowi) => {
       body('isSlackEnabled').if(value => value != null).isBoolean().withMessage('isSlackEnabled must be boolean'),
       body('slackChannels').if(value => value != null).isString().withMessage('slackChannels must be string'),
       body('pageTags').if(value => value != null).isArray().withMessage('pageTags must be array'),
+      body('createFromPageTree').optional().isBoolean().withMessage('createFromPageTree must be boolean'),
     ],
     renamePage: [
       body('pageId').isMongoId().withMessage('pageId is required'),
@@ -244,6 +245,9 @@ module.exports = (crowi) => {
    *                    type: array
    *                    items:
    *                      $ref: '#/components/schemas/Tag'
+   *                  createFromPageTree:
+   *                    type: boolean
+   *                    description: Whether the page was created from the page tree or not
    *                required:
    *                  - body
    *                  - path
@@ -270,10 +274,10 @@ module.exports = (crowi) => {
    */
   router.post('/', accessTokenParser, loginRequiredStrictly, csrf, validator.createPage, apiV3FormValidator, async(req, res) => {
     const {
-      body, grant, grantUserGroupId, overwriteScopesOfDescendants, isSlackEnabled, slackChannels, pageTags,
+      grant, grantUserGroupId, overwriteScopesOfDescendants, isSlackEnabled, slackChannels, pageTags, createFromPageTree,
     } = req.body;
 
-    let { path } = req.body;
+    let { path, body } = req.body;
 
     // check whether path starts slash
     path = pathUtils.addHeadingSlash(path);
@@ -284,6 +288,11 @@ module.exports = (crowi) => {
       options.grantUserGroupId = grantUserGroupId;
     }
 
+    const isEnabledAttachTitleHeader = await crowi.configManager.getConfig('crowi', 'customize:isEnabledAttachTitleHeader');
+    if (createFromPageTree && isEnabledAttachTitleHeader) {
+      body = `# ${path}`;
+    }
+
     let createdPage;
     try {
       createdPage = await createPageAction({