|
|
@@ -176,7 +176,6 @@ module.exports = (crowi) => {
|
|
|
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('shouldGeneratePath').optional().isBoolean().withMessage('shouldGeneratePath is must be boolean or undefined'),
|
|
|
- body('shouldReturnIfPathExists').optional().isBoolean().withMessage('shouldReturnIfPathExists is must be boolean or undefined'),
|
|
|
],
|
|
|
renamePage: [
|
|
|
body('pageId').isMongoId().withMessage('pageId is required'),
|
|
|
@@ -240,15 +239,11 @@ module.exports = (crowi) => {
|
|
|
return [];
|
|
|
}
|
|
|
|
|
|
- async function checkIsPathExists(path) {
|
|
|
- const Page = mongoose.model('Page');
|
|
|
- const response = await Page.findByPath(path);
|
|
|
- return response != null;
|
|
|
- }
|
|
|
-
|
|
|
async function generateUniquePath(basePath, index = 1) {
|
|
|
+ const Page = mongoose.model('Page');
|
|
|
const path = basePath + index;
|
|
|
- const isPathExists = await checkIsPathExists(path);
|
|
|
+ const response = await Page.findByPath(path);
|
|
|
+ const isPathExists = response != null;
|
|
|
if (isPathExists) {
|
|
|
return generateUniquePath(basePath, index + 1);
|
|
|
}
|
|
|
@@ -286,9 +281,6 @@ module.exports = (crowi) => {
|
|
|
* shouldGeneratePath:
|
|
|
* type: boolean
|
|
|
* description: Determine whether a new path should be generated
|
|
|
- * shouldReturnIfPathExists:
|
|
|
- * type: boolean
|
|
|
- * description: Determine whether a should return response if path exists
|
|
|
* required:
|
|
|
* - body
|
|
|
* - path
|
|
|
@@ -315,7 +307,7 @@ module.exports = (crowi) => {
|
|
|
*/
|
|
|
router.post('/', accessTokenParser, loginRequiredStrictly, excludeReadOnlyUser, addActivity, validator.createPage, apiV3FormValidator, async(req, res) => {
|
|
|
const {
|
|
|
- body, grant, grantUserGroupId, overwriteScopesOfDescendants, isSlackEnabled, slackChannels, pageTags, shouldGeneratePath, shouldReturnIfPathExists,
|
|
|
+ body, grant, grantUserGroupId, overwriteScopesOfDescendants, isSlackEnabled, slackChannels, pageTags, shouldGeneratePath,
|
|
|
} = req.body;
|
|
|
|
|
|
let { path } = req.body;
|
|
|
@@ -323,18 +315,6 @@ module.exports = (crowi) => {
|
|
|
// check whether path starts slash
|
|
|
path = addHeadingSlash(path);
|
|
|
|
|
|
- if (shouldReturnIfPathExists) {
|
|
|
- try {
|
|
|
- const isPathExists = await checkIsPathExists(path);
|
|
|
- if (isPathExists) {
|
|
|
- return res.apiv3({}, 200);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- return res.apiv3Err(err);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
if (shouldGeneratePath) {
|
|
|
try {
|
|
|
const rootPath = '/';
|