Parcourir la source

Merge pull request #2329 from weseek/feat/create-route-for-share-access-page

Feat/create route for share access page
Yuki Takei il y a 5 ans
Parent
commit
bc5596b7ff
3 fichiers modifiés avec 28 ajouts et 3 suppressions
  1. 1 3
      src/server/models/share-link.js
  2. 2 0
      src/server/routes/index.js
  3. 25 0
      src/server/routes/page.js

+ 1 - 3
src/server/models/share-link.js

@@ -17,9 +17,7 @@ const schema = new mongoose.Schema({
     index: true,
     index: true,
   },
   },
   expiration: { type: Date },
   expiration: { type: Date },
-  description: {
-    type: String,
-  },
+  description: { type: String },
   createdAt: { type: Date, default: Date.now, required: true },
   createdAt: { type: Date, default: Date.now, required: true },
 });
 });
 
 

+ 2 - 0
src/server/routes/index.js

@@ -180,6 +180,8 @@ module.exports = function(crowi, app) {
   app.post('/_api/hackmd.discard'        , accessTokenParser , loginRequiredStrictly , csrf, hackmd.validateForApi, hackmd.discard);
   app.post('/_api/hackmd.discard'        , accessTokenParser , loginRequiredStrictly , csrf, hackmd.validateForApi, hackmd.discard);
   app.post('/_api/hackmd.saveOnHackmd'   , accessTokenParser , loginRequiredStrictly , csrf, hackmd.validateForApi, hackmd.saveOnHackmd);
   app.post('/_api/hackmd.saveOnHackmd'   , accessTokenParser , loginRequiredStrictly , csrf, hackmd.validateForApi, hackmd.saveOnHackmd);
 
 
+  app.get('/share/:linkId', page.showSharePage, page.notFound);
+
   app.get('/*/$'                   , loginRequired , page.showPageWithEndOfSlash, page.notFound);
   app.get('/*/$'                   , loginRequired , page.showPageWithEndOfSlash, page.notFound);
   app.get('/*'                     , loginRequired , page.showPage, page.notFound);
   app.get('/*'                     , loginRequired , page.showPage, page.notFound);
 
 

+ 25 - 0
src/server/routes/page.js

@@ -142,6 +142,7 @@ module.exports = function(crowi, app) {
   const PageTagRelation = crowi.model('PageTagRelation');
   const PageTagRelation = crowi.model('PageTagRelation');
   const UpdatePost = crowi.model('UpdatePost');
   const UpdatePost = crowi.model('UpdatePost');
   const GlobalNotificationSetting = crowi.model('GlobalNotificationSetting');
   const GlobalNotificationSetting = crowi.model('GlobalNotificationSetting');
+  const ShareLink = crowi.model('ShareLink');
 
 
   const ApiResponse = require('../util/apiResponse');
   const ApiResponse = require('../util/apiResponse');
   const getToday = require('../util/getToday');
   const getToday = require('../util/getToday');
@@ -439,6 +440,30 @@ module.exports = function(crowi, app) {
     return showPageForGrowiBehavior(req, res, next);
     return showPageForGrowiBehavior(req, res, next);
   };
   };
 
 
+  actions.showSharePage = async function(req, res, next) {
+    const { linkId } = req.params;
+
+    const layoutName = configManager.getConfig('crowi', 'customize:layout');
+    // TODO Consider the layout for share
+    const view = `layout-${layoutName}/page`;
+
+    const shareLink = await ShareLink.find({ _id: linkId }).populate('Page');
+    const page = shareLink.relatedPage;
+
+    if (page == null) {
+      // page is not found
+      return next();
+    }
+
+    const renderVars = {};
+
+    addRendarVarsForPage(renderVars, page);
+    addRendarVarsForScope(renderVars, page);
+
+    await interceptorManager.process('beforeRenderPage', req, res, renderVars);
+    return res.render(view, renderVars);
+  };
+
   /**
   /**
    * switch action by behaviorType
    * switch action by behaviorType
    */
    */