|
|
@@ -189,36 +189,6 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- actions.search = function(req, res) {
|
|
|
- // spec: ?q=query&sort=sort_order&author=author_filter
|
|
|
- var query = req.query.q;
|
|
|
- var search = require('../util/search')(crowi);
|
|
|
-
|
|
|
- search.searchPageByKeyword(query)
|
|
|
- .then(function(pages) {
|
|
|
- debug('pages', pages);
|
|
|
-
|
|
|
- if (pages.hits.total <= 0) {
|
|
|
- return Promise.resolve([]);
|
|
|
- }
|
|
|
-
|
|
|
- var ids = pages.hits.hits.map(function(page) {
|
|
|
- return page._id;
|
|
|
- });
|
|
|
-
|
|
|
- return Page.findListByPageIds(ids);
|
|
|
- }).then(function(pages) {
|
|
|
-
|
|
|
- res.render('page_list', {
|
|
|
- path: '/',
|
|
|
- pages: pages,
|
|
|
- pager: generatePager({offset: 0, limit: 50})
|
|
|
- });
|
|
|
- }).catch(function(err) {
|
|
|
- debug('search error', err);
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
function renderPage(pageData, req, res) {
|
|
|
// create page
|
|
|
if (!pageData) {
|
|
|
@@ -229,7 +199,7 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
if (pageData.redirectTo) {
|
|
|
- return res.redirect(encodeURI(pageData.redirectTo + '?renamed=' + pageData.path));
|
|
|
+ return res.redirect(encodeURI(pageData.redirectTo + '?redirectFrom=' + pageData.path));
|
|
|
}
|
|
|
|
|
|
var renderVars = {
|
|
|
@@ -307,6 +277,11 @@ module.exports = function(crowi, app) {
|
|
|
return renderPage(page, req, res);
|
|
|
}).catch(function(err) {
|
|
|
|
|
|
+ const normalizedPath = Page.normalizePath(path);
|
|
|
+ if (normalizedPath !== path) {
|
|
|
+ return res.redirect(normalizedPath);
|
|
|
+ }
|
|
|
+
|
|
|
// pageShow は /* にマッチしてる最後の砦なので、creatableName でない routing は
|
|
|
// これ以前に定義されているはずなので、こうしてしまって問題ない。
|
|
|
if (!Page.isCreatableName(path)) {
|
|
|
@@ -384,7 +359,7 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
if (data && !data.isUpdatable(currentRevision)) {
|
|
|
debug('Conflict occured');
|
|
|
- req.form.errors.push('すでに他の人がこのページを編集していたため保存できませんでした。ページを再読み込み後、自分の編集箇所のみ再度編集してください。');
|
|
|
+ req.form.errors.push('page_edit.notice.conflict');
|
|
|
throw new Error('Conflict.');
|
|
|
}
|
|
|
|
|
|
@@ -804,10 +779,19 @@ module.exports = function(crowi, app) {
|
|
|
var pageId = req.body.page_id;
|
|
|
var previousRevision = req.body.revision_id || null;
|
|
|
|
|
|
+ // get completely flag
|
|
|
+ const isCompletely = (req.body.completely !== undefined);
|
|
|
+
|
|
|
Page.findPageByIdAndGrantedUser(pageId, req.user)
|
|
|
.then(function(pageData) {
|
|
|
debug('Delete page', pageData._id, pageData.path);
|
|
|
|
|
|
+ if (isCompletely) {
|
|
|
+ return Page.completelyDeletePage(pageData, req.user);
|
|
|
+ }
|
|
|
+
|
|
|
+ // else
|
|
|
+
|
|
|
if (!pageData.isUpdatable(previousRevision)) {
|
|
|
throw new Error('Someone could update this page, so couldn\'t delete.');
|
|
|
}
|
|
|
@@ -901,5 +885,34 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * @api {post} /pages.unlink Remove the redirecting page
|
|
|
+ * @apiName UnlinkPage
|
|
|
+ * @apiGroup Page
|
|
|
+ *
|
|
|
+ * @apiParam {String} page_id Page Id.
|
|
|
+ * @apiParam {String} revision_id
|
|
|
+ */
|
|
|
+ api.unlink = function(req, res){
|
|
|
+ var pageId = req.body.page_id;
|
|
|
+
|
|
|
+ Page.findPageByIdAndGrantedUser(pageId, req.user)
|
|
|
+ .then(function(pageData) {
|
|
|
+ debug('Unlink page', pageData._id, pageData.path);
|
|
|
+
|
|
|
+ return Page.removeRedirectOriginPageByPath(pageData.path)
|
|
|
+ .then(() => pageData);
|
|
|
+ }).then(function(data) {
|
|
|
+ debug('Redirect Page deleted', data.path);
|
|
|
+ var result = {};
|
|
|
+ result.page = data;
|
|
|
+
|
|
|
+ return res.json(ApiResponse.success(result));
|
|
|
+ }).catch(function(err) {
|
|
|
+ debug('Error occured while get setting', err, err.stack);
|
|
|
+ return res.json(ApiResponse.error('Failed to delete redirect page.'));
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
return actions;
|
|
|
};
|