|
|
@@ -146,16 +146,12 @@ module.exports = function(crowi, app) {
|
|
|
const ApiResponse = require('../util/apiResponse');
|
|
|
const getToday = require('../util/getToday');
|
|
|
|
|
|
- const { configManager, slackNotificationService } = crowi;
|
|
|
+ const { slackNotificationService, configManager } = crowi;
|
|
|
const interceptorManager = crowi.getInterceptorManager();
|
|
|
const globalNotificationService = crowi.getGlobalNotificationService();
|
|
|
|
|
|
const actions = {};
|
|
|
|
|
|
- const PORTAL_STATUS_NOT_EXISTS = 0;
|
|
|
- const PORTAL_STATUS_EXISTS = 1;
|
|
|
- const PORTAL_STATUS_FORBIDDEN = 2;
|
|
|
-
|
|
|
// register page events
|
|
|
|
|
|
const pageEvent = crowi.event('page');
|
|
|
@@ -338,31 +334,22 @@ module.exports = function(crowi, app) {
|
|
|
return res.render('page_presentation', renderVars);
|
|
|
}
|
|
|
|
|
|
- async function showPageListForCrowiBehavior(req, res, next) {
|
|
|
- const portalPath = pathUtils.addTrailingSlash(getPathFromRequest(req));
|
|
|
+ async function showTopPage(req, res, next) {
|
|
|
+ const portalPath = req.path;
|
|
|
const revisionId = req.query.revision;
|
|
|
+ const layoutName = configManager.getConfig('crowi', 'customize:layout');
|
|
|
|
|
|
- // check whether this page has portal page
|
|
|
- const portalPageStatus = await getPortalPageState(portalPath, req.user);
|
|
|
-
|
|
|
- let view = 'customlayout-selector/page_list';
|
|
|
+ const view = `layout-${layoutName}/page_list`;
|
|
|
const renderVars = { path: portalPath };
|
|
|
|
|
|
- if (portalPageStatus === PORTAL_STATUS_FORBIDDEN) {
|
|
|
- // inject to req
|
|
|
- req.isForbidden = true;
|
|
|
- view = 'customlayout-selector/forbidden';
|
|
|
- }
|
|
|
- else if (portalPageStatus === PORTAL_STATUS_EXISTS) {
|
|
|
- let portalPage = await Page.findByPathAndViewer(portalPath, req.user);
|
|
|
- portalPage.initLatestRevisionField(revisionId);
|
|
|
+ let portalPage = await Page.findByPathAndViewer(portalPath, req.user);
|
|
|
+ portalPage.initLatestRevisionField(revisionId);
|
|
|
|
|
|
- // populate
|
|
|
- portalPage = await portalPage.populateDataToShowRevision();
|
|
|
+ // populate
|
|
|
+ portalPage = await portalPage.populateDataToShowRevision();
|
|
|
|
|
|
- addRendarVarsForPage(renderVars, portalPage);
|
|
|
- await addRenderVarsForSlack(renderVars, portalPage);
|
|
|
- }
|
|
|
+ addRendarVarsForPage(renderVars, portalPage);
|
|
|
+ await addRenderVarsForSlack(renderVars, portalPage);
|
|
|
|
|
|
const limit = 50;
|
|
|
const offset = parseInt(req.query.offset) || 0;
|
|
|
@@ -376,6 +363,7 @@ module.exports = function(crowi, app) {
|
|
|
async function showPageForGrowiBehavior(req, res, next) {
|
|
|
const path = getPathFromRequest(req);
|
|
|
const revisionId = req.query.revision;
|
|
|
+ const layoutName = configManager.getConfig('crowi', 'customize:layout');
|
|
|
|
|
|
let page = await Page.findByPathAndViewer(path, req.user);
|
|
|
|
|
|
@@ -395,7 +383,7 @@ module.exports = function(crowi, app) {
|
|
|
const offset = parseInt(req.query.offset) || 0;
|
|
|
const renderVars = {};
|
|
|
|
|
|
- let view = 'customlayout-selector/page';
|
|
|
+ let view = `layout-${layoutName}/page`;
|
|
|
|
|
|
page.initLatestRevisionField(revisionId);
|
|
|
|
|
|
@@ -409,7 +397,7 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
if (isUserPage(page.path)) {
|
|
|
// change template
|
|
|
- view = 'customlayout-selector/user_page';
|
|
|
+ view = `layout-${layoutName}/user_page`;
|
|
|
await addRenderVarsForUserPage(renderVars, page, req.user);
|
|
|
}
|
|
|
|
|
|
@@ -427,46 +415,16 @@ module.exports = function(crowi, app) {
|
|
|
return channels;
|
|
|
};
|
|
|
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param {string} path
|
|
|
- * @param {User} user
|
|
|
- * @returns {number} PORTAL_STATUS_NOT_EXISTS(0) or PORTAL_STATUS_EXISTS(1) or PORTAL_STATUS_FORBIDDEN(2)
|
|
|
- */
|
|
|
- async function getPortalPageState(path, user) {
|
|
|
- const portalPath = Page.addSlashOfEnd(path);
|
|
|
- const page = await Page.findByPathAndViewer(portalPath, user);
|
|
|
-
|
|
|
- if (page == null) {
|
|
|
- // check the page is forbidden or just does not exist.
|
|
|
- const isForbidden = await Page.count({ path: portalPath }) > 0;
|
|
|
- return isForbidden ? PORTAL_STATUS_FORBIDDEN : PORTAL_STATUS_NOT_EXISTS;
|
|
|
- }
|
|
|
- return PORTAL_STATUS_EXISTS;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
actions.showTopPage = function(req, res) {
|
|
|
- return showPageListForCrowiBehavior(req, res);
|
|
|
+ return showTopPage(req, res);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * switch action by behaviorType
|
|
|
+ * Redirect to the page without trailing slash
|
|
|
*/
|
|
|
- /* eslint-disable no-else-return */
|
|
|
actions.showPageWithEndOfSlash = function(req, res, next) {
|
|
|
- const behaviorType = configManager.getConfig('crowi', 'customize:behavior');
|
|
|
-
|
|
|
- if (behaviorType === 'crowi') {
|
|
|
- return showPageListForCrowiBehavior(req, res, next);
|
|
|
- }
|
|
|
- else {
|
|
|
- const path = getPathFromRequest(req); // end of slash should be omitted
|
|
|
- // redirect and showPage action will be triggered
|
|
|
- return res.redirect(path);
|
|
|
- }
|
|
|
+ return res.redirect(pathUtils.removeTrailingSlash(req.path));
|
|
|
};
|
|
|
- /* eslint-enable no-else-return */
|
|
|
|
|
|
/**
|
|
|
* switch action
|
|
|
@@ -478,20 +436,6 @@ module.exports = function(crowi, app) {
|
|
|
if (req.query.presentation) {
|
|
|
return showPageForPresentation(req, res, next);
|
|
|
}
|
|
|
-
|
|
|
- const behaviorType = configManager.getConfig('crowi', 'customize:behavior');
|
|
|
-
|
|
|
- // check whether this page has portal page
|
|
|
- if (behaviorType === 'crowi') {
|
|
|
- const portalPagePath = pathUtils.addTrailingSlash(getPathFromRequest(req));
|
|
|
- const hasPortalPage = await Page.count({ path: portalPagePath }) > 0;
|
|
|
-
|
|
|
- if (hasPortalPage) {
|
|
|
- logger.debug('The portal page is found', portalPagePath);
|
|
|
- return res.redirect(encodeURI(`${portalPagePath}?redirectFrom=${pathUtils.encodePagePath(req.path)}`));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// delegate to showPageForGrowiBehavior
|
|
|
return showPageForGrowiBehavior(req, res, next);
|
|
|
};
|
|
|
@@ -501,16 +445,8 @@ module.exports = function(crowi, app) {
|
|
|
*/
|
|
|
/* eslint-disable no-else-return */
|
|
|
actions.trashPageListShowWrapper = function(req, res) {
|
|
|
- const behaviorType = configManager.getConfig('crowi', 'customize:behavior');
|
|
|
-
|
|
|
- if (behaviorType === 'crowi') {
|
|
|
- // Crowi behavior for '/trash/*'
|
|
|
- return actions.deletedPageListShow(req, res);
|
|
|
- }
|
|
|
- else {
|
|
|
- // redirect to '/trash'
|
|
|
- return res.redirect('/trash');
|
|
|
- }
|
|
|
+ // redirect to '/trash'
|
|
|
+ return res.redirect('/trash');
|
|
|
};
|
|
|
/* eslint-enable no-else-return */
|
|
|
|
|
|
@@ -519,16 +455,8 @@ module.exports = function(crowi, app) {
|
|
|
*/
|
|
|
/* eslint-disable no-else-return */
|
|
|
actions.trashPageShowWrapper = function(req, res) {
|
|
|
- const behaviorType = configManager.getConfig('crowi', 'customize:behavior');
|
|
|
-
|
|
|
- if (behaviorType === 'crowi') {
|
|
|
- // redirect to '/trash/'
|
|
|
- return res.redirect('/trash/');
|
|
|
- }
|
|
|
- else {
|
|
|
- // Crowi behavior for '/trash/*'
|
|
|
- return actions.deletedPageListShow(req, res);
|
|
|
- }
|
|
|
+ // Crowi behavior for '/trash/*'
|
|
|
+ return actions.deletedPageListShow(req, res);
|
|
|
};
|
|
|
/* eslint-enable no-else-return */
|
|
|
|
|
|
@@ -537,16 +465,8 @@ module.exports = function(crowi, app) {
|
|
|
*/
|
|
|
/* eslint-disable no-else-return */
|
|
|
actions.deletedPageListShowWrapper = function(req, res) {
|
|
|
- const behaviorType = configManager.getConfig('crowi', 'customize:behavior');
|
|
|
-
|
|
|
- if (behaviorType === 'crowi') {
|
|
|
- // Crowi behavior for '/trash/*'
|
|
|
- return actions.deletedPageListShow(req, res);
|
|
|
- }
|
|
|
- else {
|
|
|
- const path = `/trash${getPathFromRequest(req)}`;
|
|
|
- return res.redirect(path);
|
|
|
- }
|
|
|
+ const path = `/trash${getPathFromRequest(req)}`;
|
|
|
+ return res.redirect(path);
|
|
|
};
|
|
|
/* eslint-enable no-else-return */
|
|
|
|
|
|
@@ -554,18 +474,19 @@ module.exports = function(crowi, app) {
|
|
|
const path = getPathFromRequest(req);
|
|
|
|
|
|
const isCreatable = Page.isCreatableName(path);
|
|
|
+ const layoutName = configManager.getConfig('crowi', 'customize:layout');
|
|
|
|
|
|
let view;
|
|
|
const renderVars = { path };
|
|
|
|
|
|
if (!isCreatable) {
|
|
|
- view = 'customlayout-selector/not_creatable';
|
|
|
+ view = `layout-${layoutName}/not_creatable`;
|
|
|
}
|
|
|
else if (req.isForbidden) {
|
|
|
- view = 'customlayout-selector/forbidden';
|
|
|
+ view = `layout-${layoutName}/forbidden`;
|
|
|
}
|
|
|
else {
|
|
|
- view = 'customlayout-selector/not_found';
|
|
|
+ view = `layout-${layoutName}/not_found`;
|
|
|
|
|
|
// retrieve templates
|
|
|
if (req.user != null) {
|
|
|
@@ -596,6 +517,7 @@ module.exports = function(crowi, app) {
|
|
|
actions.deletedPageListShow = async function(req, res) {
|
|
|
// normalizePath makes '/trash/' -> '/trash'
|
|
|
const path = pathUtils.normalizePath(`/trash${getPathFromRequest(req)}`);
|
|
|
+ const layoutName = configManager.getConfig('crowi', 'customize:layout');
|
|
|
|
|
|
const limit = 50;
|
|
|
const offset = parseInt(req.query.offset) || 0;
|
|
|
@@ -620,7 +542,7 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
renderVars.pager = generatePager(result.offset, result.limit, result.totalCount);
|
|
|
renderVars.pages = pathUtils.encodePagesPath(result.pages);
|
|
|
- res.render('customlayout-selector/page_list', renderVars);
|
|
|
+ res.render(`layout-${layoutName}/page_list`, renderVars);
|
|
|
};
|
|
|
|
|
|
/**
|