|
@@ -573,7 +573,7 @@ module.exports = function(crowi, app) {
|
|
|
*/
|
|
*/
|
|
|
api.create = async function(req, res) {
|
|
api.create = async function(req, res) {
|
|
|
const body = req.body.body || null;
|
|
const body = req.body.body || null;
|
|
|
- const pagePath = req.body.path || null;
|
|
|
|
|
|
|
+ let pagePath = req.body.path || null;
|
|
|
const grant = req.body.grant || null;
|
|
const grant = req.body.grant || null;
|
|
|
const grantUserGroupId = req.body.grantUserGroupId || null;
|
|
const grantUserGroupId = req.body.grantUserGroupId || null;
|
|
|
const overwriteScopesOfDescendants = req.body.overwriteScopesOfDescendants || null;
|
|
const overwriteScopesOfDescendants = req.body.overwriteScopesOfDescendants || null;
|
|
@@ -586,6 +586,9 @@ module.exports = function(crowi, app) {
|
|
|
return res.json(ApiResponse.error('Parameters body and path are required.'));
|
|
return res.json(ApiResponse.error('Parameters body and path are required.'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // check whether path starts slash
|
|
|
|
|
+ pagePath = pathUtils.addHeadingSlash(pagePath);
|
|
|
|
|
+
|
|
|
// check page existence
|
|
// check page existence
|
|
|
const isExist = await Page.count({ path: pagePath }) > 0;
|
|
const isExist = await Page.count({ path: pagePath }) > 0;
|
|
|
if (isExist) {
|
|
if (isExist) {
|
|
@@ -1064,7 +1067,7 @@ module.exports = function(crowi, app) {
|
|
|
api.rename = async function(req, res) {
|
|
api.rename = async function(req, res) {
|
|
|
const pageId = req.body.page_id;
|
|
const pageId = req.body.page_id;
|
|
|
const previousRevision = req.body.revision_id || null;
|
|
const previousRevision = req.body.revision_id || null;
|
|
|
- const newPagePath = pathUtils.normalizePath(req.body.new_path);
|
|
|
|
|
|
|
+ let newPagePath = pathUtils.normalizePath(req.body.new_path);
|
|
|
const options = {
|
|
const options = {
|
|
|
createRedirectPage: (req.body.create_redirect != null),
|
|
createRedirectPage: (req.body.create_redirect != null),
|
|
|
updateMetadata: (req.body.remain_metadata == null),
|
|
updateMetadata: (req.body.remain_metadata == null),
|
|
@@ -1076,6 +1079,9 @@ module.exports = function(crowi, app) {
|
|
|
return res.json(ApiResponse.error(`Could not use the path '${newPagePath})'`, 'invalid_path'));
|
|
return res.json(ApiResponse.error(`Could not use the path '${newPagePath})'`, 'invalid_path'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // check whether path starts slash
|
|
|
|
|
+ newPagePath = pathUtils.addHeadingSlash(newPagePath);
|
|
|
|
|
+
|
|
|
const isExist = await Page.count({ path: newPagePath }) > 0;
|
|
const isExist = await Page.count({ path: newPagePath }) > 0;
|
|
|
if (isExist) {
|
|
if (isExist) {
|
|
|
// if page found, cannot cannot rename to that path
|
|
// if page found, cannot cannot rename to that path
|
|
@@ -1130,7 +1136,7 @@ module.exports = function(crowi, app) {
|
|
|
*/
|
|
*/
|
|
|
api.duplicate = async function(req, res) {
|
|
api.duplicate = async function(req, res) {
|
|
|
const pageId = req.body.page_id;
|
|
const pageId = req.body.page_id;
|
|
|
- const newPagePath = pathUtils.normalizePath(req.body.new_path);
|
|
|
|
|
|
|
+ let newPagePath = pathUtils.normalizePath(req.body.new_path);
|
|
|
|
|
|
|
|
const page = await Page.findByIdAndViewer(pageId, req.user);
|
|
const page = await Page.findByIdAndViewer(pageId, req.user);
|
|
|
|
|
|
|
@@ -1138,6 +1144,9 @@ module.exports = function(crowi, app) {
|
|
|
return res.json(ApiResponse.error(`Page '${pageId}' is not found or forbidden`, 'notfound_or_forbidden'));
|
|
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();
|
|
await page.populateDataToShowRevision();
|
|
|
const originTags = await page.findRelatedTagsById();
|
|
const originTags = await page.findRelatedTagsById();
|
|
|
|
|
|