|
|
@@ -54,7 +54,8 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
if (length < limit) {
|
|
|
next = null;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
next = offset + limit;
|
|
|
}
|
|
|
|
|
|
@@ -77,7 +78,7 @@ module.exports = function(crowi, app) {
|
|
|
else {
|
|
|
return actions.pageListShowForCrowiPlus(req, res);
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
/**
|
|
|
* switch action by behaviorType
|
|
|
*/
|
|
|
@@ -90,7 +91,7 @@ module.exports = function(crowi, app) {
|
|
|
else {
|
|
|
return actions.pageShowForCrowiPlus(req, res);
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
/**
|
|
|
* switch action by behaviorType
|
|
|
*/
|
|
|
@@ -105,7 +106,7 @@ module.exports = function(crowi, app) {
|
|
|
// redirect to '/trash'
|
|
|
return res.redirect('/trash');
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
/**
|
|
|
* switch action by behaviorType
|
|
|
*/
|
|
|
@@ -121,7 +122,7 @@ module.exports = function(crowi, app) {
|
|
|
return actions.deletedPageListShow(req, res);
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
+ };
|
|
|
/**
|
|
|
* switch action by behaviorType
|
|
|
*/
|
|
|
@@ -136,7 +137,7 @@ module.exports = function(crowi, app) {
|
|
|
const path = '/trash' + getPathFromRequest(req);
|
|
|
return res.redirect(path);
|
|
|
}
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
|
|
|
actions.pageListShow = function(req, res) {
|
|
|
@@ -151,11 +152,11 @@ module.exports = function(crowi, app) {
|
|
|
// index page
|
|
|
var pagerOptions = {
|
|
|
offset: offset,
|
|
|
- limit : limit
|
|
|
+ limit: limit
|
|
|
};
|
|
|
var queryOptions = {
|
|
|
offset: offset,
|
|
|
- limit : limit + 1,
|
|
|
+ limit: limit + 1,
|
|
|
isPopulateRevisionBody: Config.isEnabledTimeline(config),
|
|
|
};
|
|
|
|
|
|
@@ -175,7 +176,8 @@ module.exports = function(crowi, app) {
|
|
|
if (portalPage) {
|
|
|
renderVars.revision = portalPage.revision;
|
|
|
return Revision.findRevisionList(portalPage.path, {});
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return Promise.resolve([]);
|
|
|
}
|
|
|
}).then(function(tree) {
|
|
|
@@ -207,7 +209,7 @@ module.exports = function(crowi, app) {
|
|
|
path = path.replace((/\/$/), '');
|
|
|
// redirect
|
|
|
return res.redirect(path);
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
actions.pageShowForCrowiPlus = function(req, res) {
|
|
|
var path = getPathFromRequest(req);
|
|
|
@@ -219,11 +221,11 @@ module.exports = function(crowi, app) {
|
|
|
// index page
|
|
|
var pagerOptions = {
|
|
|
offset: offset,
|
|
|
- limit : limit
|
|
|
+ limit: limit
|
|
|
};
|
|
|
var queryOptions = {
|
|
|
offset: offset,
|
|
|
- limit : limit + 1,
|
|
|
+ limit: limit + 1,
|
|
|
isPopulateRevisionBody: Config.isEnabledTimeline(config),
|
|
|
includeDeletedPage: path.startsWith('/trash/'),
|
|
|
};
|
|
|
@@ -296,7 +298,8 @@ module.exports = function(crowi, app) {
|
|
|
return Promise.resolve();
|
|
|
}
|
|
|
});
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return Promise.resolve();
|
|
|
}
|
|
|
})
|
|
|
@@ -339,14 +342,14 @@ module.exports = function(crowi, app) {
|
|
|
})
|
|
|
.then(function() {
|
|
|
return UserGroupRelation.findAllRelationForUser(req.user);
|
|
|
- }).then(function (groupRelations) {
|
|
|
+ }).then(function(groupRelations) {
|
|
|
debug('findPage : relatedGroups ', groupRelations);
|
|
|
renderVars.userRelatedGroups = groupRelations.map(relation => relation.relatedGroup);
|
|
|
debug('findPage : groups ', renderVars.userRelatedGroups);
|
|
|
|
|
|
return Promise.resolve();
|
|
|
});
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
actions.deletedPageListShow = function(req, res) {
|
|
|
var path = '/trash' + getPathFromRequest(req);
|
|
|
@@ -356,11 +359,11 @@ module.exports = function(crowi, app) {
|
|
|
// index page
|
|
|
var pagerOptions = {
|
|
|
offset: offset,
|
|
|
- limit : limit
|
|
|
+ limit: limit
|
|
|
};
|
|
|
var queryOptions = {
|
|
|
offset: offset,
|
|
|
- limit : limit + 1,
|
|
|
+ limit: limit + 1,
|
|
|
includeDeletedPage: true,
|
|
|
};
|
|
|
|
|
|
@@ -466,7 +469,8 @@ module.exports = function(crowi, app) {
|
|
|
debug('Error on finding user related entities', err);
|
|
|
// pass
|
|
|
});
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return Promise.resolve();
|
|
|
}
|
|
|
}).then(function() {
|
|
|
@@ -531,11 +535,12 @@ module.exports = function(crowi, app) {
|
|
|
.then(function(page) {
|
|
|
if (page) {
|
|
|
return res.redirect(pagePathUtil.encodePagePath(path) + '/');
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
|
|
|
- var fixed = Page.fixToCreatableName(path)
|
|
|
+ var fixed = Page.fixToCreatableName(path);
|
|
|
if (fixed !== path) {
|
|
|
- debug('fixed page name', fixed)
|
|
|
+ debug('fixed page name', fixed);
|
|
|
res.redirect(pagePathUtil.encodePagePath(fixed));
|
|
|
return ;
|
|
|
}
|
|
|
@@ -562,7 +567,7 @@ module.exports = function(crowi, app) {
|
|
|
var currentRevision = pageForm.currentRevision;
|
|
|
var grant = pageForm.grant;
|
|
|
var path = pageForm.path;
|
|
|
- var grantUserGroupId = pageForm.grantUserGroupId
|
|
|
+ var grantUserGroupId = pageForm.grantUserGroupId;
|
|
|
|
|
|
// TODO: make it pluggable
|
|
|
var notify = pageForm.notify || {};
|
|
|
@@ -602,7 +607,8 @@ module.exports = function(crowi, app) {
|
|
|
if (data) {
|
|
|
previousRevision = data.revision;
|
|
|
return Page.updatePage(data, body, req.user, { grant: grant, grantUserGroupId: grantUserGroupId});
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
// new page
|
|
|
updateOrCreate = 'create';
|
|
|
return Page.create(path, body, req.user, { grant: grant, grantUserGroupId: grantUserGroupId});
|
|
|
@@ -616,7 +622,7 @@ module.exports = function(crowi, app) {
|
|
|
// TODO: move to events
|
|
|
if (notify.slack) {
|
|
|
if (notify.slack.on && notify.slack.channel) {
|
|
|
- data.updateSlackChannel(notify.slack.channel).then(function(){}).catch(function(){});
|
|
|
+ data.updateSlackChannel(notify.slack.channel).then(function() {}).catch(function() {});
|
|
|
|
|
|
if (crowi.slack) {
|
|
|
notify.slack.channel.split(',').map(function(chan) {
|
|
|
@@ -647,7 +653,7 @@ module.exports = function(crowi, app) {
|
|
|
/**
|
|
|
* redirector
|
|
|
*/
|
|
|
- api.redirector = function(req, res){
|
|
|
+ api.redirector = function(req, res) {
|
|
|
var id = req.params.id;
|
|
|
|
|
|
Page.findPageById(id)
|
|
|
@@ -680,8 +686,8 @@ module.exports = function(crowi, app) {
|
|
|
var limit = 50;
|
|
|
var offset = parseInt(req.query.offset) || 0;
|
|
|
|
|
|
- var pagerOptions = { offset: offset, limit : limit };
|
|
|
- var queryOptions = { offset: offset, limit : limit + 1};
|
|
|
+ var pagerOptions = { offset: offset, limit: limit };
|
|
|
+ var queryOptions = { offset: offset, limit: limit + 1};
|
|
|
|
|
|
// Accepts only one of these
|
|
|
if (username === null && path === null) {
|
|
|
@@ -700,7 +706,8 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
return Page.findListByCreator(user, queryOptions, req.user);
|
|
|
});
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
pageFetcher = Page.findListByStartWith(path, req.user, queryOptions);
|
|
|
}
|
|
|
|
|
|
@@ -728,7 +735,7 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} path
|
|
|
* @apiParam {String} grant
|
|
|
*/
|
|
|
- api.create = function(req, res){
|
|
|
+ api.create = function(req, res) {
|
|
|
var body = req.body.body || null;
|
|
|
var pagePath = req.body.path || null;
|
|
|
var grant = req.body.grant || null;
|
|
|
@@ -757,7 +764,7 @@ module.exports = function(crowi, app) {
|
|
|
return res.json(ApiResponse.success(result));
|
|
|
}).catch(function(err) {
|
|
|
return res.json(ApiResponse.error(err));
|
|
|
- });;
|
|
|
+ });
|
|
|
|
|
|
};
|
|
|
|
|
|
@@ -775,7 +782,7 @@ module.exports = function(crowi, app) {
|
|
|
* - If revision_id is specified => update the page,
|
|
|
* - If revision_id is not specified => force update by the new contents.
|
|
|
*/
|
|
|
- api.update = function(req, res){
|
|
|
+ api.update = function(req, res) {
|
|
|
var pageBody = req.body.body || null;
|
|
|
var pageId = req.body.page_id || null;
|
|
|
var revisionId = req.body.revision_id || null;
|
|
|
@@ -790,7 +797,7 @@ module.exports = function(crowi, app) {
|
|
|
.then(function(pageData) {
|
|
|
if (pageData && revisionId !== null && !pageData.isUpdatable(revisionId)) {
|
|
|
throw new Error('Revision error.');
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
var grantOption = {grant: pageData.grant};
|
|
|
if (grant !== null) {
|
|
|
@@ -821,7 +828,7 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} path
|
|
|
* @apiParam {String} revision_id
|
|
|
*/
|
|
|
- api.get = function(req, res){
|
|
|
+ api.get = function(req, res) {
|
|
|
const pagePath = req.query.path || null;
|
|
|
const pageId = req.query.page_id || null; // TODO: handling
|
|
|
const revisionId = req.query.revision_id || null;
|
|
|
@@ -833,7 +840,8 @@ module.exports = function(crowi, app) {
|
|
|
let pageFinder;
|
|
|
if (pageId) { // prioritized
|
|
|
pageFinder = Page.findPageByIdAndGrantedUser(pageId, req.user);
|
|
|
- } else if (pagePath) {
|
|
|
+ }
|
|
|
+ else if (pagePath) {
|
|
|
pageFinder = Page.findPage(pagePath, req.user, revisionId);
|
|
|
}
|
|
|
|
|
|
@@ -854,7 +862,7 @@ module.exports = function(crowi, app) {
|
|
|
*
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
*/
|
|
|
- api.seen = function(req, res){
|
|
|
+ api.seen = function(req, res) {
|
|
|
var pageId = req.body.page_id;
|
|
|
if (!pageId) {
|
|
|
return res.json(ApiResponse.error('page_id required'));
|
|
|
@@ -881,7 +889,7 @@ module.exports = function(crowi, app) {
|
|
|
*
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
*/
|
|
|
- api.like = function(req, res){
|
|
|
+ api.like = function(req, res) {
|
|
|
var id = req.body.page_id;
|
|
|
|
|
|
Page.findPageByIdAndGrantedUser(id, req.user)
|
|
|
@@ -903,7 +911,7 @@ module.exports = function(crowi, app) {
|
|
|
*
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
*/
|
|
|
- api.unlike = function(req, res){
|
|
|
+ api.unlike = function(req, res) {
|
|
|
var id = req.body.page_id;
|
|
|
|
|
|
Page.findPageByIdAndGrantedUser(id, req.user)
|
|
|
@@ -955,7 +963,7 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
* @apiParam {String} revision_id
|
|
|
*/
|
|
|
- api.remove = function(req, res){
|
|
|
+ api.remove = function(req, res) {
|
|
|
var pageId = req.body.page_id;
|
|
|
var previousRevision = req.body.revision_id || null;
|
|
|
|
|
|
@@ -1008,7 +1016,7 @@ module.exports = function(crowi, app) {
|
|
|
*
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
*/
|
|
|
- api.revertRemove = function(req, res){
|
|
|
+ api.revertRemove = function(req, res) {
|
|
|
var pageId = req.body.page_id;
|
|
|
|
|
|
// get recursively flag
|
|
|
@@ -1046,7 +1054,7 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} new_path
|
|
|
* @apiParam {Bool} create_redirect
|
|
|
*/
|
|
|
- api.rename = function(req, res){
|
|
|
+ api.rename = function(req, res) {
|
|
|
var pageId = req.body.page_id;
|
|
|
var previousRevision = req.body.revision_id || null;
|
|
|
var newPagePath = Page.normalizePath(req.body.new_path);
|
|
|
@@ -1100,13 +1108,12 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
* @apiParam {String} new_path
|
|
|
*/
|
|
|
- api.duplicate = function (req, res) {
|
|
|
+ api.duplicate = function(req, res) {
|
|
|
var pageId = req.body.page_id;
|
|
|
var newPagePath = Page.normalizePath(req.body.new_path);
|
|
|
- var page = {};
|
|
|
|
|
|
Page.findPageById(pageId)
|
|
|
- .then(function (pageData) {
|
|
|
+ .then(function(pageData) {
|
|
|
req.body.path = newPagePath;
|
|
|
req.body.body = pageData.revision.body;
|
|
|
req.body.grant = pageData.grant;
|
|
|
@@ -1123,7 +1130,7 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
* @apiParam {String} revision_id
|
|
|
*/
|
|
|
- api.unlink = function(req, res){
|
|
|
+ api.unlink = function(req, res) {
|
|
|
var pageId = req.body.page_id;
|
|
|
|
|
|
Page.findPageByIdAndGrantedUser(pageId, req.user)
|