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

Merge branch 'master' into feat/sidebar-RecentChanges

Yuki Takei 4 лет назад
Родитель
Сommit
6848928a53

+ 51 - 4
packages/app/src/server/routes/apiv3/pages.js

@@ -23,6 +23,36 @@ const LIMIT_FOR_LIST = 10;
  *    name: Pages
  */
 
+/**
+ * @swagger
+ *
+ *  components:
+ *    schemas:
+ *      Tags:
+ *        description: Tags
+ *        type: array
+ *        items:
+ *          $ref: '#/components/schemas/Tag/properties/name'
+ *        example: ['daily', 'report', 'tips']
+ *
+ *      Tag:
+ *        description: Tag
+ *        type: object
+ *        properties:
+ *          _id:
+ *            type: string
+ *            description: tag ID
+ *            example: 5e2d6aede35da4004ef7e0b7
+ *          name:
+ *            type: string
+ *            description: tag name
+ *            example: daily
+ *          count:
+ *            type: number
+ *            description: Count of tagged pages
+ *            example: 3
+ */
+
 /**
  * @swagger
  *
@@ -77,7 +107,7 @@ const LIMIT_FOR_LIST = 10;
  *          path:
  *            type: string
  *            description: page path
- *            example: /
+ *            example: /Sandbox/Math
  *          redirectTo:
  *            type: string
  *            description: redirect path
@@ -177,7 +207,7 @@ module.exports = (crowi) => {
   /**
    * @swagger
    *
-   *    /pages/create:
+   *    /pages:
    *      post:
    *        tags: [Pages]
    *        operationId: createPage
@@ -194,6 +224,14 @@ module.exports = (crowi) => {
    *                    $ref: '#/components/schemas/Page/properties/path'
    *                  grant:
    *                    $ref: '#/components/schemas/Page/properties/grant'
+   *                  grantUserGroupId:
+   *                    type: string
+   *                    description: UserGroup ID
+   *                    example: 5ae5fccfc5577b0004dbd8ab
+   *                  pageTags:
+   *                    type: array
+   *                    items:
+   *                      $ref: '#/components/schemas/Tag'
    *                required:
    *                  - body
    *                  - path
@@ -204,8 +242,17 @@ module.exports = (crowi) => {
    *              application/json:
    *                schema:
    *                  properties:
-   *                    page:
-   *                      $ref: '#/components/schemas/Page'
+   *                    data:
+   *                      type: object
+   *                      properties:
+   *                        page:
+   *                          $ref: '#/components/schemas/Page'
+   *                        tags:
+   *                          type: array
+   *                          items:
+   *                            $ref: '#/components/schemas/Tags'
+   *                        revision:
+   *                          $ref: '#/components/schemas/Revision'
    *          409:
    *            description: page path is already existed
    */

+ 21 - 20
packages/slackbot-proxy/src/middlewares/slack-to-growi/authorizer.ts

@@ -1,21 +1,25 @@
 import { AuthorizeResult, InstallationQuery } from '@slack/oauth';
 import {
-  IMiddleware, Inject, Middleware, Req, Res,
+  IMiddleware, Inject, Middleware, Next, Req, Res,
 } from '@tsed/common';
 
 import Logger from 'bunyan';
 
+import createError from 'http-errors';
+
 import { SlackOauthReq } from '~/interfaces/slack-to-growi/slack-oauth-req';
 import { InstallerService } from '~/services/InstallerService';
 import loggerFactory from '~/utils/logger';
 
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
+const logger = loggerFactory('@growi/slackbot-proxy:middlewares:authorizer');
+
 
 const getCommonMiddleware = (query:InstallationQuery<boolean>, installerService:InstallerService, logger:Logger) => {
-  return async(req: SlackOauthReq, res: Res): Promise<void|Res> => {
+  return async(req: SlackOauthReq, res: Res, next: Next): Promise<void|Res> => {
 
     if (query.teamId == null && query.enterpriseId == null) {
-      res.writeHead(400, 'No installation found');
-      return res.end();
+      return next(createError(400, 'No installation found'));
     }
 
     let result: AuthorizeResult;
@@ -23,19 +27,18 @@ const getCommonMiddleware = (query:InstallationQuery<boolean>, installerService:
       result = await installerService.installer.authorize(query);
 
       if (result.botToken == null) {
-        res.writeHead(403, `The installation for the team(${query.teamId || query.enterpriseId}) has no botToken`);
-        return res.end();
+        return next(createError(403, `The installation for the team(${query.teamId || query.enterpriseId}) has no botToken`));
       }
     }
     catch (e) {
       logger.error(e.message);
 
-      res.writeHead(500, e.message);
-      return res.end();
+      return next(createError(500, e.message));
     }
 
     // set authorized data
     req.authorizeResult = result;
+    next();
   };
 };
 @Middleware()
@@ -50,7 +53,7 @@ export class AuthorizeCommandMiddleware implements IMiddleware {
   @Inject()
   installerService: InstallerService;
 
-  async use(@Req() req: SlackOauthReq, @Res() res: Res): Promise<void|Res> {
+  async use(@Req() req: SlackOauthReq, @Res() res: Res, @Next() next: Next): Promise<void|Res> {
     const { body } = req;
     const teamId = body.team_id;
     const enterpriseId = body.enterprise_id;
@@ -62,7 +65,7 @@ export class AuthorizeCommandMiddleware implements IMiddleware {
     };
 
     const commonMiddleware = getCommonMiddleware(query, this.installerService, this.logger);
-    await commonMiddleware(req, res);
+    await commonMiddleware(req, res, next);
   }
 
 }
@@ -79,9 +82,13 @@ export class AuthorizeInteractionMiddleware implements IMiddleware {
     @Inject()
     installerService: InstallerService;
 
-    async use(@Req() req: SlackOauthReq, @Res() res:Res): Promise<void|Res> {
+    async use(@Req() req: SlackOauthReq, @Res() res:Res, @Next() next: Next): Promise<void|Res> {
       const { body } = req;
 
+      if (body.payload == null) {
+        return next(createError(400, 'The request has no payload.'));
+      }
+
       const payload = JSON.parse(body.payload);
 
       // extract id from body.payload
@@ -89,12 +96,6 @@ export class AuthorizeInteractionMiddleware implements IMiddleware {
       const enterpriseId = payload.enterprise?.id;
       const isEnterpriseInstall = payload.is_enterprise_install === 'true';
 
-      if (body.payload == null) {
-      // do nothing
-        this.logger.info('body does not have payload');
-        return;
-      }
-
       const query: InstallationQuery<boolean> = {
         teamId,
         enterpriseId,
@@ -102,7 +103,7 @@ export class AuthorizeInteractionMiddleware implements IMiddleware {
       };
 
       const commonMiddleware = getCommonMiddleware(query, this.installerService, this.logger);
-      await commonMiddleware(req, res);
+      await commonMiddleware(req, res, next);
     }
 
 }
@@ -118,7 +119,7 @@ export class AuthorizeEventsMiddleware implements IMiddleware {
   @Inject()
   installerService: InstallerService;
 
-  async use(@Req() req: SlackOauthReq, @Res() res: Res): Promise<void|Res> {
+  async use(@Req() req: SlackOauthReq, @Res() res: Res, @Next() next: Next): Promise<void|Res> {
     const { body } = req;
     const teamId = body.team_id;
     const enterpriseId = body.enterprise_id;
@@ -130,7 +131,7 @@ export class AuthorizeEventsMiddleware implements IMiddleware {
     };
 
     const commonMiddleware = getCommonMiddleware(query, this.installerService, this.logger);
-    await commonMiddleware(req, res);
+    await commonMiddleware(req, res, next);
   }
 
 }