|
|
@@ -527,7 +527,7 @@ module.exports = function(crowi, app) {
|
|
|
// check page existence
|
|
|
const isExist = await Page.count({path: pagePath}) > 0;
|
|
|
if (isExist) {
|
|
|
- return res.json(ApiResponse.error('Page exists'));
|
|
|
+ return res.json(ApiResponse.error('Page exists', 'already_exists'));
|
|
|
}
|
|
|
|
|
|
const options = {grant, grantUserGroupId, socketClientId};
|
|
|
@@ -584,13 +584,13 @@ module.exports = function(crowi, app) {
|
|
|
// check page existence
|
|
|
const isExist = await Page.count({_id: pageId}) > 0;
|
|
|
if (!isExist) {
|
|
|
- return res.json(ApiResponse.error(`Page('${pageId}' is not found or forbidden`));
|
|
|
+ return res.json(ApiResponse.error(`Page('${pageId}' is not found or forbidden`, 'notfound_or_forbidden'));
|
|
|
}
|
|
|
|
|
|
// check revision
|
|
|
let page = await Page.findByIdAndViewer(pageId, req.user);
|
|
|
if (page != null && revisionId != null && !page.isUpdatable(revisionId)) {
|
|
|
- return res.json(ApiResponse.error('Posted param "revisionId" is outdated.'));
|
|
|
+ return res.json(ApiResponse.error('Posted param "revisionId" is outdated.', 'outdated'));
|
|
|
}
|
|
|
|
|
|
const options = {isSyncRevisionToHackmd, socketClientId};
|
|
|
@@ -602,7 +602,9 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- page = await Page.updatePage(page, pageBody, req.user, options);
|
|
|
+ const Revision = crowi.model('Revision');
|
|
|
+ const previousRevision = await Revision.findById(revisionId);
|
|
|
+ page = await Page.updatePage(page, pageBody, previousRevision.body, req.user, options);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error('error on _api/pages.update', err);
|
|
|
@@ -656,7 +658,7 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
if (page == null) {
|
|
|
- throw new Error(`Page '${pageId || pagePath}' is not found or forbidden`);
|
|
|
+ throw new Error(`Page '${pageId || pagePath}' is not found or forbidden`, 'notfound_or_forbidden');
|
|
|
}
|
|
|
|
|
|
page.initLatestRevisionField();
|
|
|
@@ -836,7 +838,7 @@ module.exports = function(crowi, app) {
|
|
|
let page = await Page.findByIdAndViewer(pageId, req.user);
|
|
|
|
|
|
if (page == null) {
|
|
|
- return res.json(ApiResponse.error(`Page '${pageId}' is not found or forbidden`));
|
|
|
+ return res.json(ApiResponse.error(`Page '${pageId}' is not found or forbidden`, 'notfound_or_forbidden'));
|
|
|
}
|
|
|
|
|
|
debug('Delete page', page._id, page.path);
|
|
|
@@ -852,7 +854,7 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
else {
|
|
|
if (!page.isUpdatable(previousRevision)) {
|
|
|
- throw new Error('Someone could update this page, so couldn\'t delete.');
|
|
|
+ return res.json(ApiResponse.error('Someone could update this page, so couldn\'t delete.', 'outdated'));
|
|
|
}
|
|
|
|
|
|
if (isRecursively) {
|
|
|
@@ -865,7 +867,7 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error('Error occured while get setting', err);
|
|
|
- return res.json(ApiResponse.error('Failed to delete page.'));
|
|
|
+ return res.json(ApiResponse.error('Failed to delete page.', 'unknown'));
|
|
|
}
|
|
|
|
|
|
debug('Page deleted', page.path);
|
|
|
@@ -896,7 +898,7 @@ module.exports = function(crowi, app) {
|
|
|
try {
|
|
|
page = await Page.findByIdAndViewer(pageId, req.user);
|
|
|
if (page == null) {
|
|
|
- throw new Error(`Page '${pageId}' is not found or forbidden`);
|
|
|
+ throw new Error(`Page '${pageId}' is not found or forbidden`, 'notfound_or_forbidden');
|
|
|
}
|
|
|
|
|
|
if (isRecursively) {
|
|
|
@@ -937,16 +939,16 @@ module.exports = function(crowi, app) {
|
|
|
moveUnderTrees: req.body.move_trees || 0,
|
|
|
socketClientId: +req.body.socketClientId || undefined,
|
|
|
};
|
|
|
- const isRecursiveMove = req.body.move_recursively || 0;
|
|
|
+ const isRecursively = req.body.recursively || 0;
|
|
|
|
|
|
if (!Page.isCreatableName(newPagePath)) {
|
|
|
- return res.json(ApiResponse.error(`このページ名は作成できません (${newPagePath})`));
|
|
|
+ return res.json(ApiResponse.error(`Could not use the path '${newPagePath})'`, 'invalid_path'));
|
|
|
}
|
|
|
|
|
|
const isExist = await Page.count({ path: newPagePath }) > 0;
|
|
|
if (isExist) {
|
|
|
// if page found, cannot cannot rename to that path
|
|
|
- return res.json(ApiResponse.error(`'new_path=${newPagePath}' already exists`));
|
|
|
+ return res.json(ApiResponse.error(`'new_path=${newPagePath}' already exists`, 'already_exists'));
|
|
|
}
|
|
|
|
|
|
let page;
|
|
|
@@ -955,14 +957,14 @@ module.exports = function(crowi, app) {
|
|
|
page = await Page.findByIdAndViewer(pageId, req.user);
|
|
|
|
|
|
if (page == null) {
|
|
|
- throw new Error(`Page '${pageId}' is not found or forbidden`);
|
|
|
+ return res.json(ApiResponse.error(`Page '${pageId}' is not found or forbidden`, 'notfound_or_forbidden'));
|
|
|
}
|
|
|
|
|
|
if (!page.isUpdatable(previousRevision)) {
|
|
|
- throw new Error('Someone could update this page, so couldn\'t delete.');
|
|
|
+ return res.json(ApiResponse.error('Someone could update this page, so couldn\'t delete.', 'outdated'));
|
|
|
}
|
|
|
|
|
|
- if (isRecursiveMove) {
|
|
|
+ if (isRecursively) {
|
|
|
page = await Page.renameRecursively(page, newPagePath, req.user, options);
|
|
|
}
|
|
|
else {
|
|
|
@@ -971,7 +973,7 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
- return res.json(ApiResponse.error('Failed to update page.'));
|
|
|
+ return res.json(ApiResponse.error('Failed to update page.', 'unknown'));
|
|
|
}
|
|
|
|
|
|
const result = {};
|
|
|
@@ -1000,7 +1002,7 @@ module.exports = function(crowi, app) {
|
|
|
const page = await Page.findByIdAndViewer(pageId, req.user);
|
|
|
|
|
|
if (page == null) {
|
|
|
- throw new Error(`Page '${pageId}' is not found or forbidden`);
|
|
|
+ return res.json(ApiResponse.error(`Page '${pageId}' is not found or forbidden`, 'notfound_or_forbidden'));
|
|
|
}
|
|
|
|
|
|
await page.populateDataToShowRevision();
|