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

Merge pull request #3732 from weseek/fix/restore-to-update-endpoint

Fix/restore to update endpoint
Yuki Takei 4 лет назад
Родитель
Сommit
3863b1db94

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

@@ -34,7 +34,7 @@ const CustomBotWithoutProxySettingsAccordion = ({
 
   const updateSecretTokenHandler = async() => {
     try {
-      await appContainer.apiv3.put('/slack-integration-settings/bot-type', {
+      await appContainer.apiv3.put('/slack-integration-settings/without-proxy/update-settings', {
         slackSigningSecret,
         slackBotToken,
         currentBotType,

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

@@ -258,6 +258,50 @@ module.exports = (crowi) => {
       }
     });
 
+  /**
+   * @swagger
+   *
+   *    /slack-integration/without-proxy/update-settings/:
+   *      put:
+   *        tags: [UpdateWithoutProxySettings]
+   *        operationId: putWithoutProxySettings
+   *        summary: update customBotWithoutProxy settings
+   *        description: Update customBotWithoutProxy setting.
+   *        responses:
+   *           200:
+   *             description: Succeeded to put CustomBotWithoutProxy setting.
+   */
+  router.put('/without-proxy/update-settings', async(req, res) => {
+    const currentBotType = crowi.configManager.getConfig('crowi', 'slackbot:currentBotType');
+    if (currentBotType !== 'customBotWithoutProxy') {
+      const msg = 'Not CustomBotWithoutProxy';
+      return res.apiv3Err(new ErrorV3(msg, 'not-customBotWithoutProxy'), 400);
+    }
+    const { slackSigningSecret, slackBotToken } = req.body;
+    const requestParams = {
+      'slackbot:signingSecret': slackSigningSecret,
+      'slackbot:token': slackBotToken,
+    };
+    try {
+      await updateSlackBotSettings(requestParams);
+      crowi.slackBotService.publishUpdatedMessage();
+
+      const customBotWithoutProxySettingParams = {
+        slackSigningSecret: crowi.configManager.getConfig('crowi', 'slackbot:signingSecret'),
+        slackBotToken: crowi.configManager.getConfig('crowi', 'slackbot:token'),
+      };
+      return res.apiv3({ customBotWithoutProxySettingParams });
+    }
+    catch (error) {
+      const msg = 'Error occured in updating Custom bot setting';
+      logger.error('Error', error);
+      return res.apiv3Err(new ErrorV3(msg, 'update-CustomBotSetting-failed'), 500);
+    }
+
+
+  });
+
+
   /**
    * @swagger
    *