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

Merge remote-tracking branch 'origin/feat/growi-bot' into imprv/yellow-condition-if-some-ws-got-error

zahmis 4 лет назад
Родитель
Сommit
2612680a96

+ 8 - 0
.github/workflows/release-slackbot-proxy.yml

@@ -33,6 +33,12 @@ jobs:
         username: wsmoogle
         username: wsmoogle
         password: ${{ secrets.DOCKER_REGISTRY_ON_GITHUB_PASSWORD }}
         password: ${{ secrets.DOCKER_REGISTRY_ON_GITHUB_PASSWORD }}
 
 
+    - name: Setup gcloud
+      uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
+      with:
+        service_account_key: ${{ secrets.GCP_SA_KEY_SLACKBOT_PROXY }}
+        export_default_credentials: true
+
     - name: Build and push
     - name: Build and push
       uses: docker/build-push-action@v2
       uses: docker/build-push-action@v2
       working-directory: ./packages/slackbot-proxy
       working-directory: ./packages/slackbot-proxy
@@ -46,6 +52,8 @@ jobs:
           weseek/growi-slackbot-proxy:${{ env.RELEASE_VERSION }}
           weseek/growi-slackbot-proxy:${{ env.RELEASE_VERSION }}
           ghcr.io/weseek/growi-slackbot-proxy:latest
           ghcr.io/weseek/growi-slackbot-proxy:latest
           ghcr.io/weseek/growi-slackbot-proxy:${{ env.RELEASE_VERSION }}
           ghcr.io/weseek/growi-slackbot-proxy:${{ env.RELEASE_VERSION }}
+          asia.gcr.io/${{ env.GCP_PRJ_ID_SLACKBOT_PROXY }}/growi-slackbot-proxy:latest
+          asia.gcr.io/${{ env.GCP_PRJ_ID_SLACKBOT_PROXY }}/growi-slackbot-proxy:${{ env.RELEASE_VERSION }}
 
 
     - name: Update Docker Hub Description
     - name: Update Docker Hub Description
       uses: peter-evans/dockerhub-description@v2
       uses: peter-evans/dockerhub-description@v2

+ 1 - 1
packages/slackbot-proxy/package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "@growi/slackbot-proxy",
   "name": "@growi/slackbot-proxy",
-  "version": "0.9.0-RC",
+  "version": "0.9.1-RC",
   "license": "MIT",
   "license": "MIT",
   "scripts": {
   "scripts": {
     "build": "yarn tsc && tsc-alias -p tsconfig.build.json",
     "build": "yarn tsc && tsc-alias -p tsconfig.build.json",

+ 7 - 8
packages/slackbot-proxy/src/controllers/growi-to-slack.ts

@@ -1,5 +1,5 @@
 import {
 import {
-  Controller, Get, Post, Inject, Req, Res, UseBefore,
+  Controller, Get, Post, Inject, Req, Res, UseBefore, PathParams,
 } from '@tsed/common';
 } from '@tsed/common';
 import axios from 'axios';
 import axios from 'axios';
 
 
@@ -163,9 +163,9 @@ export class GrowiToSlackCtrl {
     return res.send({ relation: createdRelation, slackBotToken: token });
     return res.send({ relation: createdRelation, slackBotToken: token });
   }
   }
 
 
-  @Post('/*')
+  @Post('/:method')
   @UseBefore(verifyGrowiToSlackRequest)
   @UseBefore(verifyGrowiToSlackRequest)
-  async postResult(@Req() req: GrowiReq, @Res() res: Res): Promise<void|string|Res|WebAPICallResult> {
+  async postResult(@PathParams('method') method: string, @Req() req: GrowiReq, @Res() res: Res): Promise<void|string|Res|WebAPICallResult> {
     const { tokenGtoPs } = req;
     const { tokenGtoPs } = req;
 
 
     if (tokenGtoPs.length !== 1) {
     if (tokenGtoPs.length !== 1) {
@@ -192,14 +192,13 @@ export class GrowiToSlackCtrl {
     const client = generateWebClient(token);
     const client = generateWebClient(token);
 
 
     try {
     try {
-      // TODO: GW-6133
       const opt = req.body as WebAPICallOptions;
       const opt = req.body as WebAPICallOptions;
-      await client.apiCall('put', opt);
+      opt.headers = req.headers;
+      await client.apiCall(method, opt);
     }
     }
     catch (err) {
     catch (err) {
-      // TODO: GW-6133
-      // logger.error()
-      return res.status(500).send({ message: err.message });
+      logger.error(err);
+      return res.status(400).send({ message: `failed to send to slack. err: ${err.message}` });
     }
     }
 
 
     logger.debug('postMessage is success');
     logger.debug('postMessage is success');

+ 2 - 2
resource/locales/en_US/admin/admin.json

@@ -301,8 +301,8 @@
     "official_bot_settings": "Official bot Settings",
     "official_bot_settings": "Official bot Settings",
     "reset": "Reset",
     "reset": "Reset",
     "reset_all_settings": "Reset all settings",
     "reset_all_settings": "Reset all settings",
-    "delete_slackbot_settings": "Reset Slack Bot settings",
-    "slackbot_settings_notice": "Reset",
+    "delete_slackbot_settings": "Delete Slack Bot settings",
+    "slackbot_settings_notice": "Delete",
     "all_settings_of_the_bot_will_be_reset": "All settings of the Bot will be reset.<br>Are you sure?",
     "all_settings_of_the_bot_will_be_reset": "All settings of the Bot will be reset.<br>Are you sure?",
     "accordion": {
     "accordion": {
       "create_bot": "Create Bot",
       "create_bot": "Create Bot",

+ 2 - 2
resource/locales/ja_JP/admin/admin.json

@@ -298,8 +298,8 @@
     "integration_failed":"連携に失敗しました",
     "integration_failed":"連携に失敗しました",
     "reset": "リセット",
     "reset": "リセット",
     "reset_all_settings": "全ての設定をリセット",
     "reset_all_settings": "全ての設定をリセット",
-    "delete_slackbot_settings": "Slack Bot 設定をリセットする",
-    "slackbot_settings_notice": "リセットします",
+    "delete_slackbot_settings": "Slack Bot 設定を削除する",
+    "slackbot_settings_notice": "削除します",
     "all_settings_of_the_bot_will_be_reset": "Botの全ての設定がリセットされます。<br>よろしいですか?",
     "all_settings_of_the_bot_will_be_reset": "Botの全ての設定がリセットされます。<br>よろしいですか?",
     "accordion": {
     "accordion": {
       "create_bot": "Bot を作成する",
       "create_bot": "Bot を作成する",

+ 2 - 2
resource/locales/zh_CN/admin/admin.json

@@ -308,8 +308,8 @@
     "integration_failed":"联动失败",
     "integration_failed":"联动失败",
     "reset":"重置",
     "reset":"重置",
     "reset_all_settings": "重置所有设置",
     "reset_all_settings": "重置所有设置",
-    "delete_slackbot_settings": "重置 Slack Bot 设置",
-    "slackbot_settings_notice": "重置",
+    "delete_slackbot_settings": "删除 Slack Bot 设置",
+    "slackbot_settings_notice": "删除",
     "all_settings_of_the_bot_will_be_reset": "bot的所有设置将被重置。<br>你确定吗?",
     "all_settings_of_the_bot_will_be_reset": "bot的所有设置将被重置。<br>你确定吗?",
     "accordion": {
     "accordion": {
       "create_bot": "创建 Bot",
       "create_bot": "创建 Bot",

+ 5 - 14
src/client/js/components/Admin/SlackIntegration/CustomBotWithProxyIntegrationCard.jsx

@@ -24,7 +24,7 @@ const CustomBotWithProxyIntegrationCard = (props) => {
         </div>
         </div>
       </div>
       </div>
 
 
-      <div className="text-center w-25 mt-5">
+      <div className="text-center w-25 mt-3">
         <IntegrationStatus workspaceNames={workspaceNames} />
         <IntegrationStatus workspaceNames={workspaceNames} />
       </div>
       </div>
 
 
@@ -35,18 +35,9 @@ const CustomBotWithProxyIntegrationCard = (props) => {
             <a className="icon-fw fa fa-repeat fa-2x"></a>
             <a className="icon-fw fa fa-repeat fa-2x"></a>
           </div>
           </div>
         </div>
         </div>
-        <div className="card-body p-4 mb-5 text-center">
-          <div className="btn-group-vertical w-50">
-            {props.growiApps.map((growiApp) => {
-              return (
-                <button
-                  type="button"
-                  key={growiApp.name}
-                  className={growiApp.active ? 'btn btn-primary mb-3' : 'btn btn-outline-primary mb-3'}
-                >{growiApp.name}
-                </button>
-              );
-            })}
+        <div className="card-body text-center">
+          <div className="mt-5 border p-2 mx-3 bg-primary text-light">
+            {props.siteName}
           </div>
           </div>
         </div>
         </div>
       </div>
       </div>
@@ -55,7 +46,7 @@ const CustomBotWithProxyIntegrationCard = (props) => {
 };
 };
 
 
 CustomBotWithProxyIntegrationCard.propTypes = {
 CustomBotWithProxyIntegrationCard.propTypes = {
-  growiApps: PropTypes.array.isRequired,
+  siteName: PropTypes.string.isRequired,
   slackWorkSpaces: PropTypes.array,
   slackWorkSpaces: PropTypes.array,
   isSlackScopeSet: PropTypes.bool,
   isSlackScopeSet: PropTypes.bool,
   workspaceNames: PropTypes.array.isRequired,
   workspaceNames: PropTypes.array.isRequired,

+ 7 - 7
src/client/js/components/Admin/SlackIntegration/CustomBotWithProxySettings.jsx

@@ -17,6 +17,7 @@ const CustomBotWithProxySettings = (props) => {
   } = props;
   } = props;
   const [newProxyServerUri, setNewProxyServerUri] = useState();
   const [newProxyServerUri, setNewProxyServerUri] = useState();
   const [integrationIdToDelete, setIntegrationIdToDelete] = useState(null);
   const [integrationIdToDelete, setIntegrationIdToDelete] = useState(null);
+  const [siteName, setSiteName] = useState('');
   const { t } = useTranslation();
   const { t } = useTranslation();
 
 
   const workspaceNameObjects = Object.values(connectionStatuses);
   const workspaceNameObjects = Object.values(connectionStatuses);
@@ -78,19 +79,18 @@ const CustomBotWithProxySettings = (props) => {
     }
     }
   };
   };
 
 
+  useEffect(() => {
+    const siteName = appContainer.config.crowi.title;
+    setSiteName(siteName);
+  }, [appContainer]);
+
   return (
   return (
     <>
     <>
       <h2 className="admin-setting-header mb-2">{t('admin:slack_integration.custom_bot_with_proxy_integration')}</h2>
       <h2 className="admin-setting-header mb-2">{t('admin:slack_integration.custom_bot_with_proxy_integration')}</h2>
 
 
       {/* TODO delete tmp props */}
       {/* TODO delete tmp props */}
       <CustomBotWithProxyIntegrationCard
       <CustomBotWithProxyIntegrationCard
-        growiApps={
-          [
-            { name: 'siteName1', active: true },
-            { name: 'siteName2', active: false },
-            { name: 'siteName3', active: false },
-          ]
-        }
+        siteName={siteName}
         slackWorkSpaces={
         slackWorkSpaces={
           [
           [
             { name: 'wsName1', active: true },
             { name: 'wsName1', active: true },

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

@@ -85,7 +85,9 @@ const CustomBotWithoutProxyIntegrationCard = (props) => {
       <div className="card rounded-lg shadow border-0 w-50 admin-bot-card mb-0">
       <div className="card rounded-lg shadow border-0 w-50 admin-bot-card mb-0">
         <h5 className="card-title font-weight-bold mt-3 ml-4">GROWI App</h5>
         <h5 className="card-title font-weight-bold mt-3 ml-4">GROWI App</h5>
         <div className="card-body p-4 mb-5 text-center">
         <div className="card-body p-4 mb-5 text-center">
-          <div className="btn btn-primary">{ props.siteName }</div>
+          <div className="border p-2 bg-primary text-light mx-5">
+            {props.siteName}
+          </div>
         </div>
         </div>
       </div>
       </div>
     </div>
     </div>

+ 14 - 3
src/client/js/components/Admin/SlackIntegration/DeleteSlackBotSettingsModal.jsx

@@ -35,14 +35,15 @@ const DeleteSlackBotSettingsModal = React.memo((props) => {
     <Modal isOpen={props.isOpen} toggle={closeButtonHandler} className="page-comment-delete-modal">
     <Modal isOpen={props.isOpen} toggle={closeButtonHandler} className="page-comment-delete-modal">
       <ModalHeader tag="h4" toggle={closeButtonHandler} className="bg-danger text-light">
       <ModalHeader tag="h4" toggle={closeButtonHandler} className="bg-danger text-light">
         <span>
         <span>
-          <i className="icon-fw icon-fire"></i>
           {props.isResetAll && (
           {props.isResetAll && (
             <>
             <>
+              <i className="icon-fw icon-fire" />
               {t('admin:slack_integration.reset_all_settings')}
               {t('admin:slack_integration.reset_all_settings')}
             </>
             </>
           )}
           )}
           {!props.isResetAll && (
           {!props.isResetAll && (
             <>
             <>
+              <i className="icon-trash mr-1" />
               {t('admin:slack_integration.delete_slackbot_settings')}
               {t('admin:slack_integration.delete_slackbot_settings')}
             </>
             </>
           )}
           )}
@@ -66,8 +67,18 @@ const DeleteSlackBotSettingsModal = React.memo((props) => {
       <ModalFooter>
       <ModalFooter>
         <Button onClick={closeButtonHandler}>{t('Cancel')}</Button>
         <Button onClick={closeButtonHandler}>{t('Cancel')}</Button>
         <Button color="danger" onClick={deleteSlackCredentialsHandler}>
         <Button color="danger" onClick={deleteSlackCredentialsHandler}>
-          <i className="icon icon-fire"></i>
-          {t('admin:slack_integration.reset')}
+          {props.isResetAll && (
+            <>
+              <i className="icon icon-fire"></i>
+              {t('admin:slack_integration.reset')}
+            </>
+          )}
+          {!props.isResetAll && (
+            <>
+              <i className="icon-trash mr-1" />
+              {t('admin:slack_integration.delete')}
+            </>
+          )}
         </Button>
         </Button>
       </ModalFooter>
       </ModalFooter>
     </Modal>
     </Modal>

+ 7 - 7
src/client/js/components/Admin/SlackIntegration/OfficialBotSettings.jsx

@@ -15,6 +15,7 @@ const OfficialBotSettings = (props) => {
   const {
   const {
     appContainer, slackAppIntegrations, proxyServerUri, onClickAddSlackWorkspaceBtn,
     appContainer, slackAppIntegrations, proxyServerUri, onClickAddSlackWorkspaceBtn,
   } = props;
   } = props;
+  const [siteName, setSiteName] = useState('');
   const [isDeleteConfirmModalShown, setIsDeleteConfirmModalShown] = useState(false);
   const [isDeleteConfirmModalShown, setIsDeleteConfirmModalShown] = useState(false);
   const { t } = useTranslation();
   const { t } = useTranslation();
 
 
@@ -77,18 +78,17 @@ const OfficialBotSettings = (props) => {
     }
     }
   };
   };
 
 
+  useEffect(() => {
+    const siteName = appContainer.config.crowi.title;
+    setSiteName(siteName);
+  }, [appContainer]);
+
   return (
   return (
     <>
     <>
       <h2 className="admin-setting-header">{t('admin:slack_integration.official_bot_integration')}</h2>
       <h2 className="admin-setting-header">{t('admin:slack_integration.official_bot_integration')}</h2>
       {/* TODO delete tmp props */}
       {/* TODO delete tmp props */}
       <CustomBotWithProxyIntegrationCard
       <CustomBotWithProxyIntegrationCard
-        growiApps={
-          [
-            { name: 'siteName1', active: true },
-            { name: 'siteName2', active: false },
-            { name: 'siteName3', active: false },
-          ]
-        }
+        siteName={siteName}
         slackWorkSpaces={
         slackWorkSpaces={
           [
           [
             { name: 'wsName1', active: true },
             { name: 'wsName1', active: true },

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

@@ -73,6 +73,8 @@ module.exports = (crowi) => {
   };
   };
 
 
   async function resetAllBotSettings() {
   async function resetAllBotSettings() {
+    await SlackAppIntegration.deleteMany();
+
     const params = {
     const params = {
       'slackbot:currentBotType': null,
       'slackbot:currentBotType': null,
       'slackbot:signingSecret': null,
       'slackbot:signingSecret': null,