Explorar o código

Merge pull request #3754 from weseek/feat/create-endpoint-without-proxy-relation-test

Feat/create endpoint without proxy relation test
Sizma yosimaz %!s(int64=4) %!d(string=hai) anos
pai
achega
338e23fb18

+ 1 - 1
src/client/js/components/Admin/SlackIntegration/CustomBotWithoutProxySettingsAccordion.jsx

@@ -71,7 +71,7 @@ const CustomBotWithoutProxySettingsAccordion = ({
     try {
       // eslint-disable-next-line no-console
       console.log('Test');
-      // const res = await appContainer.apiv3.post('/slack-integration-settings/notification-test-to-slack-work-space', {
+      // const res = await appContainer.apiv3.post('/slack-integration-settings//without-proxy/test', {
       //   channel: testChannel,
       // });
       // setConnectionSuccessMessage(res.data.message);

+ 44 - 5
src/server/routes/apiv3/slack-integration-settings.js

@@ -5,7 +5,7 @@ const axios = require('axios');
 const urljoin = require('url-join');
 const loggerFactory = require('@alias/logger');
 
-const { getConnectionStatuses } = require('@growi/slack');
+const { getConnectionStatuses, relationTestToSlack } = require('@growi/slack');
 
 const ErrorV3 = require('../../models/vo/error-apiv3');
 
@@ -55,10 +55,6 @@ module.exports = (crowi) => {
       body('currentBotType')
         .isIn(['officialBot', 'customBotWithoutProxy', 'customBotWithProxy']),
     ],
-    NotificationTestToSlackWorkSpace: [
-      body('channel').trim().not().isEmpty()
-        .isString(),
-    ],
     AccessTokens: [
       body('tokenGtoP').trim().not().isEmpty()
         .isString()
@@ -70,6 +66,10 @@ module.exports = (crowi) => {
     RelationTest: [
       body('slackappintegrationsId').isMongoId(),
     ],
+    SlackChannel: [
+      body('channel').trim().not().isEmpty()
+        .isString(),
+    ],
   };
 
   async function resetAllBotSettings() {
@@ -479,5 +479,44 @@ module.exports = (crowi) => {
     }
   });
 
+  /**
+   * @swagger
+   *
+   *    /slack-integration-settings/without-proxy/test:
+   *      post:
+   *        tags: [botType]
+   *        operationId: postTest
+   *        summary: test the connection
+   *        description: Test the connection with slack work space.
+   *        requestBody:
+   *          content:
+   *            application/json:
+   *              schema:
+   *                properties:
+   *                  testChannel:
+   *                    type: string
+   *        responses:
+   *           200:
+   *             description: Succeeded to connect to slack work space.
+   */
+  router.post('/without-proxy/test', loginRequiredStrictly, adminRequired, csrf, validator.SlackChannel, apiV3FormValidator, async(req, res) => {
+    const currentBotType = crowi.configManager.getConfig('crowi', 'slackbot:currentBotType');
+    if (currentBotType !== 'customBotWithoutProxy') {
+      const msg = 'Select Without Proxy Type';
+      return res.apiv3Err(new ErrorV3(msg, 'select-not-proxy-type'), 400);
+    }
+    // TODO impl req.body at GW-5998
+    // const { channel } = req.body;
+    const slackBotToken = crowi.configManager.getConfig('crowi', 'slackbot:token');
+    try {
+      await relationTestToSlack(slackBotToken);
+      // TODO impl return response after imple 5996, 6002
+    }
+    catch (error) {
+      logger.error('Error', error);
+      return res.apiv3Err(new ErrorV3(`Error occured while testing. Cause: ${error.message}`, 'test-failed', error.stack));
+    }
+  });
+
   return router;
 };