|
|
@@ -1148,43 +1148,20 @@ module.exports = function(crowi, app) {
|
|
|
* @apiGroup Page
|
|
|
*
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
- * @apiParam {String} path
|
|
|
- * @apiParam {String} revision_id
|
|
|
* @apiParam {String} new_path
|
|
|
- * @apiParam {Bool} create_redirect
|
|
|
*/
|
|
|
api.duplicate = function (req, res) {
|
|
|
var pageId = req.body.page_id;
|
|
|
var newPagePath = Page.normalizePath(req.body.new_path);
|
|
|
- var grant = req.body.grant || null;
|
|
|
var page = {};
|
|
|
|
|
|
- if (!Page.isCreatableName(newPagePath)) {
|
|
|
- return res.json(ApiResponse.error(`このページ名は作成できません (${newPagePath})`));
|
|
|
- }
|
|
|
+ Page.findPageById(pageId)
|
|
|
+ .then(function (pageData) {
|
|
|
+ req.body.path = newPagePath;
|
|
|
+ req.body.body = pageData.revision.body;
|
|
|
+ req.body.grant = pageData.grant;
|
|
|
|
|
|
- Page.findPageByPath(newPagePath)
|
|
|
- .then(function (page) {
|
|
|
- // if page found, cannot cannot duplicate to that path
|
|
|
- return res.json(ApiResponse.error(`このページ名は作成できません (${newPagePath})。ページが存在します。`));
|
|
|
- }).catch(function (err) {
|
|
|
-
|
|
|
- Page.findPageById(pageId)
|
|
|
- .then(function (pageData) {
|
|
|
- return Page.create(newPagePath, pageData.revision.body, req.user, { format: pageData.format, grant: pageData.grant, redirectTo: pageData.redirectTo });
|
|
|
-
|
|
|
- }).then(function (data) {
|
|
|
- if (!data) {
|
|
|
- throw new Error('Failed to create page.');
|
|
|
- }
|
|
|
- var result = { page: data.toObject() };
|
|
|
-
|
|
|
- result.page.lastUpdateUser = User.filterToPublicFields(data.lastUpdateUser);
|
|
|
- result.page.creator = User.filterToPublicFields(data.creator);
|
|
|
- return res.json(ApiResponse.success(result));
|
|
|
- }).catch(function (err) {
|
|
|
- return res.json(ApiResponse.error(err));
|
|
|
- });;
|
|
|
+ return api.create(req, res);
|
|
|
});
|
|
|
};
|
|
|
|