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

Merge pull request #3731 from weseek/imprv/gw5898-saving-proxy-url-to-db

Imprv/gw5898 saving proxy uri to db
Yuki Takei 4 лет назад
Родитель
Сommit
daa3a828b8

+ 21 - 5
src/client/js/components/Admin/SlackIntegration/OfficialbotSettingsAccordion.jsx

@@ -1,20 +1,37 @@
-import React from 'react';
+import React, { useState } from 'react';
 import PropTypes from 'prop-types';
 import { useTranslation } from 'react-i18next';
 import { CopyToClipboard } from 'react-copy-to-clipboard';
+import loggerFactory from '@alias/logger';
 import Accordion from '../Common/Accordion';
 import AdminUpdateButtonRow from '../Common/AdminUpdateButtonRow';
-import { toastSuccess } from '../../../util/apiNotification';
+import { toastSuccess, toastError } from '../../../util/apiNotification';
 import { withUnstatedContainers } from '../../UnstatedUtils';
 import AppContainer from '../../../services/AppContainer';
 
+const logger = loggerFactory('growi:SlackBotSettings'); //
 
 const OfficialBotSettingsAccordion = (props) => {
   // TODO: apply i18n by GW-5878
   const { t } = useTranslation();
   const { appContainer } = props;
+  const [proxyUri, setProxyUri] = useState(null);
+
   const growiUrl = appContainer.config.crowi.url;
 
+  const updateProxyUri = async() => {
+    try {
+      await appContainer.apiv3.put('/slack-integration-settings/proxy-uri', {
+        proxyUri,
+      });
+      toastSuccess(t('toaster.update_successed', { target: t('Proxy URL') }));
+    }
+    catch (err) {
+      toastError(err);
+      logger.error(err);
+    }
+  };
+
   return (
     <div className="card border-0 rounded-lg shadow overflow-hidden">
       <Accordion
@@ -104,14 +121,13 @@ const OfficialBotSettingsAccordion = (props) => {
               <input
                 className="form-control"
                 type="text"
+                onChange={(e) => { setProxyUri(e.target.value) }}
               />
             </div>
           </div>
           <AdminUpdateButtonRow
             disabled={false}
-            // TODO: Add Proxy URL submit logic
-            // eslint-disable-next-line no-console
-            onClick={() => console.log('Update')}
+            onClick={() => updateProxyUri()}
           />
         </div>
       </Accordion>

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

@@ -292,5 +292,24 @@ module.exports = (crowi) => {
     }
   });
 
+  router.put('/proxy-uri', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+    const { proxyUri } = req.body;
+    console.log('proxyUri', proxyUri);
+
+    const requestParams = { 'slackbot:serverUri': proxyUri };
+
+    try {
+      await updateSlackBotSettings(requestParams);
+      crowi.slackBotService.publishUpdatedMessage();
+      return res.apiv3({});
+    }
+    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);
+    }
+
+  });
+
   return router;
 };

+ 6 - 0
src/server/service/config-loader.js

@@ -410,6 +410,12 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type:    TYPES.STRING,
     default: null,
   },
+  SERVER_URI: {
+    ns:      'crowi',
+    key:     'slackbot:serverUri',
+    type:    TYPES.STRING,
+    default: null,
+  },
   SLACK_BOT_TYPE: {
     ns:      'crowi',
     key:     'slackbot:currentBotType', // 'officialBot' || 'customBotWithoutProxy' || 'customBotWithProxy'