Просмотр исходного кода

improve routing to `/trash` and `/trash/` when applying crowi-plus Simplified Behavior

Yuki Takei 8 лет назад
Родитель
Сommit
a8b86f4cc8
2 измененных файлов с 34 добавлено и 2 удалено
  1. 3 2
      lib/routes/index.js
  2. 31 0
      lib/routes/page.js

+ 3 - 2
lib/routes/index.js

@@ -139,8 +139,9 @@ module.exports = function(crowi, app) {
   //app.get('/_api/r/:revisionId'    , user.useUserData()         , page.api.get);
 
   app.post('/_/edit'                 , form.revision             , loginRequired(crowi, app) , csrf, page.pageEdit);
-  app.get('/trash/$'                 , loginRequired(crowi, app, false) , page.deletedPageListShow);
-  app.get('/trash/*/$'               , loginRequired(crowi, app, false) , page.deletedPageListShow);
+  app.get('/trash$'                  , loginRequired(crowi, app, false) , page.trashPageShowWrapper);
+  app.get('/trash/$'                 , loginRequired(crowi, app, false) , page.trashPageListShowWrapper);
+  app.get('/trash/*/$'               , loginRequired(crowi, app, false) , page.deletedPageListShowWrapper);
 
   app.get('/*/$'                   , loginRequired(crowi, app, false) , page.pageListShowWrapper);
   app.get('/*'                     , loginRequired(crowi, app, false) , page.pageShowWrapper);

+ 31 - 0
lib/routes/page.js

@@ -89,6 +89,37 @@ module.exports = function(crowi, app) {
       return actions.pageShow(req, res);
     }
   }
+  /**
+   * switch action by behaviorType
+   */
+  actions.trashPageListShowWrapper = function(req, res) {
+    const behaviorType = Config.behaviorType(config);
+
+    if ('crowi-plus' === behaviorType) {
+      // redirect to '/trash'
+      return res.redirect('/trash');
+    }
+    // official Crowi behavior for '/trash/*'
+    else {
+      return actions.deletedPageListShow(req, res);
+    }
+  }
+  /**
+   * switch action by behaviorType
+   */
+  actions.trashPageShowWrapper = function(req, res) {
+    const behaviorType = Config.behaviorType(config);
+
+    if ('crowi-plus' === behaviorType) {
+      // official Crowi behavior for '/trash/*'
+      return actions.deletedPageListShow(req, res);
+    }
+    else {
+      // redirect to '/trash/'
+      return res.redirect('/trash/');
+    }
+
+  }
   /**
    * switch action by behaviorType
    */