Explorar o código

added resetAll function and improved '/bot-type' endpoint

kaori %!s(int64=4) %!d(string=hai) anos
pai
achega
a0af0820b2
Modificáronse 1 ficheiros con 13 adicións e 6 borrados
  1. 13 6
      src/server/routes/apiv3/slack-integration-settings.js

+ 13 - 6
src/server/routes/apiv3/slack-integration-settings.js

@@ -62,12 +62,22 @@ module.exports = (crowi) => {
     ],
   };
 
-  async function updateSlackBotSettings(params) {
+  async function resetAllBotSettings() {
+    const params = {
+      'slackbot:currentBotType': '',
+      'slackbot:signingSecret': '',
+      'slackbot:token': '',
+    };
     const { configManager } = crowi;
     // update config without publishing S2sMessage
     return configManager.updateConfigsInTheSameNamespace('crowi', params, true);
   }
 
+  async function updateSlackBotSettings(params) {
+    const { configManager } = crowi;
+    // update config without publishing S2sMessage
+    return configManager.updateConfigsInTheSameNamespace('crowi', params, true);
+  }
 
   function generateAccessToken(user) {
     const hasher = crypto.createHash('sha512');
@@ -179,13 +189,10 @@ module.exports = (crowi) => {
    */
   router.put('/bot-type',
     accessTokenParser, loginRequiredStrictly, adminRequired, csrf, validator.CustomBotWithoutProxy, apiV3FormValidator, async(req, res) => {
-      const { slackSigningSecret, slackBotToken, currentBotType } = req.body;
+      const { currentBotType } = req.body;
 
+      await resetAllBotSettings();
       const requestParams = { 'slackbot:currentBotType': currentBotType };
-      if (currentBotType === 'customBotWithoutProxy') {
-        requestParams['slackbot:signingSecret'] = slackSigningSecret;
-        requestParams['slackbot:token'] = slackBotToken;
-      }
 
       try {
         await updateSlackBotSettings(requestParams);