|
|
@@ -568,15 +568,43 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} body
|
|
|
* @apiParam {String} page_id
|
|
|
* @apiParam {String} revision_id
|
|
|
+ * @apiParam {String} grant
|
|
|
*
|
|
|
* In the case of the page exists:
|
|
|
* - If revision_id is specified => update the page,
|
|
|
* - If revision_id is not specified => error.
|
|
|
*/
|
|
|
api.update = function(req, res){
|
|
|
- var pagePath = req.query.path || null;
|
|
|
- var pageId = req.query.page_id || null;
|
|
|
- var revisionId = req.query.revision_id || null;
|
|
|
+ var pageBody = req.body.body || null;
|
|
|
+ var pageId = req.body.page_id || null;
|
|
|
+ var revisionId = req.body.revision_id || null;
|
|
|
+ var grant = req.body.grant || null;
|
|
|
+
|
|
|
+ if (pageId === null || pageBody === null) {
|
|
|
+ return res.json(ApiResponse.error('page_id, revision_id, body is required.'));
|
|
|
+ }
|
|
|
+
|
|
|
+ Page.findPageByIdAndGrantedUser(pageId, req.user)
|
|
|
+ .then(function(pageData) {
|
|
|
+ if (pageData && !pageData.isUpdatable(revisionId)) {
|
|
|
+ throw new Error('Revision error.');
|
|
|
+ };
|
|
|
+
|
|
|
+ var grantOption = {grant: pageData.grant};
|
|
|
+ if (grant !== null) {
|
|
|
+ grantOption.grant = grant;
|
|
|
+ }
|
|
|
+ return Page.updatePage(pageData, pageBody, req.user, grantOption);
|
|
|
+ }).then(function(pageData) {
|
|
|
+ var result = {
|
|
|
+ page: pageData.toObject(),
|
|
|
+ };
|
|
|
+ result.page.lastUpdateUser = User.filterToPublicFields(result.page.lastUpdateUser);
|
|
|
+ return res.json(ApiResponse.success(result));
|
|
|
+ }).catch(function(err) {
|
|
|
+ debug('error on _api/pages.update', err);
|
|
|
+ return res.json(ApiResponse.error(err));
|
|
|
+ });
|
|
|
|
|
|
};
|
|
|
|