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

Merge branch 'support/share-link-for-outside-for-merge' into imprv/descard-link

ryohek 5 лет назад
Родитель
Сommit
cd9888d561

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

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

+ 1 - 0
src/server/routes/apiv3/index.js

@@ -39,6 +39,7 @@ module.exports = (crowi) => {
 
   router.use('/page', require('./page')(crowi));
   router.use('/pages', require('./pages')(crowi));
+  router.use('/share-links', require('./share-links')(crowi));
 
   router.use('/bookmarks', require('./bookmarks')(crowi));
 

+ 47 - 0
src/server/routes/apiv3/share-links.js

@@ -0,0 +1,47 @@
+// TODO remove this setting after implemented all
+/* eslint-disable no-unused-vars */
+// const loggerFactory = require('@alias/logger');
+
+// const logger = loggerFactory('growi:routes:apiv3:share-links');
+
+const express = require('express');
+
+const router = express.Router();
+
+/**
+ * @swagger
+ *  tags:
+ *    name: ShareLinks
+ */
+
+module.exports = (crowi) => {
+  const loginRequired = require('../../middleware/login-required')(crowi);
+
+  // TDOO write swagger
+  router.get('/', loginRequired, async(req, res) => {
+    const { pageId } = req.query;
+    // TODO GW-2616 get all share links associated with the page
+  });
+
+
+  // TDOO write swagger
+  router.post('/', loginRequired, async(req, res) => {
+    const { pageId } = req.body;
+    // TODO GW-2609 publish the share link
+  });
+
+  // TDOO write swagger
+  router.delete('/all', loginRequired, async(req, res) => {
+    const { pageId } = req.body;
+    // TODO GW-2694 Delete all share links
+  });
+
+  // TDOO write swagger
+  router.delete('/:id', loginRequired, async(req, res) => {
+    const { pageId } = req.body;
+    // TODO GW-2610 Remove specific share link
+  });
+
+
+  return router;
+};

+ 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.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.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 UpdatePost = crowi.model('UpdatePost');
   const GlobalNotificationSetting = crowi.model('GlobalNotificationSetting');
+  const ShareLink = crowi.model('ShareLink');
 
   const ApiResponse = require('../util/apiResponse');
   const getToday = require('../util/getToday');
@@ -439,6 +440,30 @@ module.exports = function(crowi, app) {
     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
    */