Răsfoiți Sursa

Merge branch 'feat/growi-bot' into imprv/add-test-log-every-test

zahmis 4 ani în urmă
părinte
comite
9a2d06207e

+ 13 - 3
packages/slackbot-proxy/src/controllers/slack.ts

@@ -83,9 +83,6 @@ export class SlackCtrl {
       return this.registerService.process(growiCommand, authorizeResult, body as {[key:string]:string});
     }
 
-    /*
-     * forward to GROWI server
-     */
     const installationId = authorizeResult.enterpriseId || authorizeResult.teamId;
     // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     const installation = await this.installationRepository.findByTeamIdOrEnterpriseId(installationId!);
@@ -100,10 +97,23 @@ export class SlackCtrl {
       });
     }
 
+    // status
+    if (growiCommand.growiCommandType === 'status') {
+      return res.json({
+        blocks: [
+          generateMarkdownSectionBlock('*Found Relations to GROWI.*'),
+          ...relations.map(relation => generateMarkdownSectionBlock(`GROWI url: ${relation.growiUri}.`)),
+        ],
+      });
+    }
+
     // Send response immediately to avoid opelation_timeout error
     // See https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events
     res.send();
 
+    /*
+     * forward to GROWI server
+     */
     const promises = relations.map((relation: Relation) => {
       // generate API URL
       const url = new URL('/_api/v3/slack-integration/proxied/commands', relation.growiUri);

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

@@ -301,7 +301,7 @@
     "reset": "Reset",
     "reset_all_settings": "Reset all settings",
     "delete_slackbot_settings": "Delete Slack Bot settings",
-    "slackbot_settings_notice": "Delete",
+    "slackbot_settings_notice": "The Slack workspace integration procedure will be deleted. <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": {
       "create_bot": "Create Bot",

+ 1 - 0
resource/locales/en_US/translation.json

@@ -438,6 +438,7 @@
     "initialize_successed": "Succeeded to initialize {{target}}",
     "give_user_admin": "Succeeded to give {{username}} admin",
     "remove_user_admin": "Succeeded to remove {{username}} admin",
+    "delete_slack_integration_procedure": "Succeeded to delete the slack integration procedure",
     "activate_user_success": "Succeeded to activating {{username}}",
     "deactivate_user_success": "Succeeded to deactivate {{username}}",
     "remove_user_success": "Succeeded to removing {{username}}",

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

@@ -298,7 +298,7 @@
     "reset": "リセット",
     "reset_all_settings": "全ての設定をリセット",
     "delete_slackbot_settings": "Slack Bot 設定を削除する",
-    "slackbot_settings_notice": "削除します",
+    "slackbot_settings_notice": "Slak ワークスペースの連携手順が削除されます。<br>よろしいですか?",
     "all_settings_of_the_bot_will_be_reset": "Botの全ての設定がリセットされます。<br>よろしいですか?",
     "accordion": {
       "create_bot": "Bot を作成する",

+ 1 - 0
resource/locales/ja_JP/translation.json

@@ -440,6 +440,7 @@
     "initialize_successed": "{{target}}を初期化しました",
     "give_user_admin": "{{username}}を管理者に設定しました",
     "remove_user_admin": "{{username}}を管理者から外しました",
+    "delete_slack_integration_procedure": "Slack 連携手順を削除しました",
     "activate_user_success": "{{username}}を有効化しました",
     "deactivate_user_success": "{{username}}を無効化しました",
     "remove_user_success": "{{username}}を削除しました",

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

@@ -308,7 +308,7 @@
     "reset":"重置",
     "reset_all_settings": "重置所有设置",
     "delete_slackbot_settings": "删除 Slack Bot 设置",
-    "slackbot_settings_notice": "删除",
+    "slackbot_settings_notice": "Slak 工作区集成过程已被删除。 <br> 你确定吗?",
     "all_settings_of_the_bot_will_be_reset": "bot的所有设置将被重置。<br>你确定吗?",
     "accordion": {
       "create_bot": "创建 Bot",

+ 2 - 1
resource/locales/zh_CN/translation.json

@@ -417,7 +417,8 @@
 		"update_successed": "Succeeded to update {{target}}",
     "initialize_successed": "Succeeded to initialize {{target}}",
 		"give_user_admin": "Succeeded to give {{username}} admin",
-		"remove_user_admin": "Succeeded to remove {{username}} admin ",
+    "remove_user_admin": "Succeeded to remove {{username}} admin ",
+    "delete_slack_integration_procedure": "删除了 Slack 集成程序",
 		"activate_user_success": "Succeeded to activating {{username}}",
 		"deactivate_user_success": "Succeeded to deactivate {{username}}",
 		"remove_user_success": "Succeeded to removing {{username}} ",

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

@@ -26,12 +26,6 @@ const CustomBotWithProxySettings = (props) => {
     }
   }, [proxyServerUri]);
 
-  const fetchSlackIntegrationData = () => {
-    if (props.fetchSlackIntegrationData != null) {
-      props.fetchSlackIntegrationData();
-    }
-  };
-
   const addSlackAppIntegrationHandler = async() => {
     if (onClickAddSlackWorkspaceBtn != null) {
       onClickAddSlackWorkspaceBtn();
@@ -40,10 +34,11 @@ const CustomBotWithProxySettings = (props) => {
 
   const deleteSlackAppIntegrationHandler = async() => {
     try {
-      // GW-6068 set new value after this
       await appContainer.apiv3.delete('/slack-integration-settings/slack-app-integration', { integrationIdToDelete });
-      fetchSlackIntegrationData();
-      toastSuccess(t('toaster.update_successed', { target: 'Token' }));
+      if (props.onDeleteSlackAppIntegration != null) {
+        props.onDeleteSlackAppIntegration();
+      }
+      toastSuccess(t('toaster.delete_slack_integration_procedure'));
     }
     catch (err) {
       toastError(err);
@@ -162,7 +157,7 @@ CustomBotWithProxySettings.propTypes = {
   slackAppIntegrations: PropTypes.array,
   proxyServerUri: PropTypes.string,
   onClickAddSlackWorkspaceBtn: PropTypes.func,
-  fetchSlackIntegrationData: PropTypes.func,
+  onDeleteSlackAppIntegration: PropTypes.func,
   connectionStatuses: PropTypes.object.isRequired,
 };
 

+ 8 - 9
src/client/js/components/Admin/SlackIntegration/DeleteSlackBotSettingsModal.jsx

@@ -51,17 +51,16 @@ const DeleteSlackBotSettingsModal = React.memo((props) => {
       </ModalHeader>
       <ModalBody>
         {props.isResetAll && (
-          <>
-            <span
-              // eslint-disable-next-line react/no-danger
-              dangerouslySetInnerHTML={{ __html: t('admin:slack_integration.all_settings_of_the_bot_will_be_reset') }}
-            />
-          </>
+          <span
+            // eslint-disable-next-line react/no-danger
+            dangerouslySetInnerHTML={{ __html: t('admin:slack_integration.all_settings_of_the_bot_will_be_reset') }}
+          />
         )}
         {!props.isResetAll && (
-          <>
-            {t('admin:slack_integration.slackbot_settings_notice')}
-          </>
+          <span
+            // eslint-disable-next-line react/no-danger
+            dangerouslySetInnerHTML={{ __html: t('admin:slack_integration.slackbot_settings_notice') }}
+          />
         )}
       </ModalBody>
       <ModalFooter>

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

@@ -16,7 +16,7 @@ const OfficialBotSettings = (props) => {
     appContainer, slackAppIntegrations, proxyServerUri, onClickAddSlackWorkspaceBtn, connectionStatuses,
   } = props;
   const [siteName, setSiteName] = useState('');
-  const [isDeleteConfirmModalShown, setIsDeleteConfirmModalShown] = useState(false);
+  const [integrationIdToDelete, setIntegrationIdToDelete] = useState(null);
   const { t } = useTranslation();
 
   const [newProxyServerUri, setNewProxyServerUri] = useState();
@@ -33,27 +33,17 @@ const OfficialBotSettings = (props) => {
     }
   };
 
-  /* commented out to ignore lint error -- 2021.05.31 Yuki Takei
-  const discardTokenHandler = async(tokenGtoP, tokenPtoG) => {
-    try {
-      // GW-6068 set new value after this
-      await appContainer.apiv3.delete('/slack-integration-settings/slack-app-integration', { tokenGtoP, tokenPtoG });
-    }
-    catch (err) {
-      toastError(err);
-      logger(err);
-    }
-  };
-  */
-
   const deleteSlackAppIntegrationHandler = async() => {
+    await appContainer.apiv3.delete('/slack-integration-settings/slack-app-integration', { integrationIdToDelete });
     try {
-      // TODO GW-5923 delete SlackAppIntegration
-      // await appContainer.apiv3.put('/slack-integration-settings/custom-bot-with-proxy');
-      toastSuccess('success');
+      if (props.onDeleteSlackAppIntegration != null) {
+        props.onDeleteSlackAppIntegration();
+      }
+      toastSuccess(t('toaster.delete_slack_integration_procedure'));
     }
     catch (err) {
       toastError(err);
+      logger.error(err);
     }
   };
 
@@ -117,7 +107,7 @@ const OfficialBotSettings = (props) => {
                 <button
                   className="btn btn-outline-danger"
                   type="button"
-                  onClick={() => setIsDeleteConfirmModalShown(true)}
+                  onClick={() => setIntegrationIdToDelete(slackAppIntegration._id)}
                 >
                   <i className="icon-trash mr-1" />
                   {t('admin:slack_integration.delete')}
@@ -144,8 +134,8 @@ const OfficialBotSettings = (props) => {
       </div>
       <DeleteSlackBotSettingsModal
         isResetAll={false}
-        isOpen={isDeleteConfirmModalShown}
-        onClose={() => setIsDeleteConfirmModalShown(false)}
+        isOpen={integrationIdToDelete != null}
+        onClose={() => setIntegrationIdToDelete(null)}
         onClickDeleteButton={deleteSlackAppIntegrationHandler}
       />
     </>
@@ -165,8 +155,8 @@ OfficialBotSettings.propTypes = {
   slackAppIntegrations: PropTypes.array,
   proxyServerUri: PropTypes.string,
   onClickAddSlackWorkspaceBtn: PropTypes.func,
+  onDeleteSlackAppIntegration: PropTypes.func,
   connectionStatuses: PropTypes.object.isRequired,
-
 };
 
 export default OfficialBotSettingsWrapper;

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

@@ -127,6 +127,7 @@ const SlackIntegration = (props) => {
           slackAppIntegrations={slackAppIntegrations}
           proxyServerUri={proxyServerUri}
           onClickAddSlackWorkspaceBtn={createSlackIntegrationData}
+          onDeleteSlackAppIntegration={fetchSlackIntegrationData}
           connectionStatuses={connectionStatuses}
         />
       );
@@ -151,7 +152,7 @@ const SlackIntegration = (props) => {
           slackAppIntegrations={slackAppIntegrations}
           proxyServerUri={proxyServerUri}
           onClickAddSlackWorkspaceBtn={createSlackIntegrationData}
-          fetchSlackIntegrationData={fetchSlackIntegrationData}
+          onDeleteSlackAppIntegration={fetchSlackIntegrationData}
           connectionStatuses={connectionStatuses}
         />
       );

+ 23 - 12
src/client/js/components/Admin/SlackIntegration/WithProxyAccordions.jsx

@@ -177,22 +177,23 @@ const GeneratingTokensAndRegisteringProxyServiceProcess = withUnstatedContainers
 const TestProcess = ({ apiv3Post, slackAppIntegrationId }) => {
   const { t } = useTranslation();
   const [testChannel, setTestChannel] = useState('');
-  const [connectionError, setConnectionError] = useState(null);
+  const [latestConnectionMessage, setLatestConnectionMessage] = useState(null);
+  const [isLatestConnectionSuccess, setIsLatestConnectionSuccess] = useState(false);
 
-  let value = '';
-  if (connectionError != null) {
-    value = [connectionError.code, connectionError.message];
+  let logsValue = null;
+  if (latestConnectionMessage != null) {
+    logsValue = [latestConnectionMessage.code, latestConnectionMessage.message];
   }
 
   const submitForm = async(e) => {
     e.preventDefault();
-    setConnectionError(null);
-
     try {
       await apiv3Post('/slack-integration-settings/with-proxy/relation-test', { slackAppIntegrationId, channel: testChannel });
+      setIsLatestConnectionSuccess(true);
     }
     catch (error) {
-      setConnectionError(error[0]);
+      setIsLatestConnectionSuccess(false);
+      setLatestConnectionMessage(error[0]);
       logger.error(error);
     }
   };
@@ -223,10 +224,7 @@ const TestProcess = ({ apiv3Post, slackAppIntegrationId }) => {
           </button>
         </form>
       </div>
-      {connectionError == null
-        ? <p className="text-info text-center my-4">{t('admin:slack_integration.accordion.send_message_to_slack_work_space')}</p>
-        : <p className="text-danger text-center my-4">{t('admin:slack_integration.accordion.error_check_logs_below')}</p>
-      }
+      <MessageBasedOnConnection isLatestConnectionSuccess={isLatestConnectionSuccess} latestConnectionMessage={latestConnectionMessage} />
       <form>
         <div className="row my-3 justify-content-center">
           <div className="form-group slack-connection-log col-md-4">
@@ -234,7 +232,7 @@ const TestProcess = ({ apiv3Post, slackAppIntegrationId }) => {
             <textarea
               className="form-control card border-info slack-connection-log-body rounded-lg"
               rows="5"
-              value={value}
+              value={logsValue}
               readOnly
             />
           </div>
@@ -244,6 +242,19 @@ const TestProcess = ({ apiv3Post, slackAppIntegrationId }) => {
   );
 };
 
+const MessageBasedOnConnection = (props) => {
+  const { isLatestConnectionSuccess, latestConnectionMessage } = props;
+  const { t } = useTranslation();
+  if (isLatestConnectionSuccess) {
+    return <p className="text-info text-center my-4">{t('admin:slack_integration.accordion.send_message_to_slack_work_space')}</p>;
+  }
+
+  if (latestConnectionMessage == null) {
+    return <p></p>;
+  }
+
+  return <p className="text-danger text-center my-4">{t('admin:slack_integration.accordion.error_check_logs_below')}</p>;
+};
 
 const WithProxyAccordions = (props) => {
   const { t } = useTranslation();

+ 13 - 5
src/client/js/components/Admin/SlackIntegration/slak-integration-util.js

@@ -1,9 +1,17 @@
-const addLogs = (log, connectionMessage, setConnectionMessage) => {
-  const newLog = `${new Date()} - ${log.code}, ${log.message}\n\n`;
-  if (connectionMessage == null) {
-    return setConnectionMessage(newLog);
+const addLogs = (log, newLogMessage, newLogCode = undefined) => {
+
+  let newLog;
+  if (newLogCode == null) {
+    newLog = `${new Date()} - ${newLogMessage}\n\n`;
+  }
+  else {
+    newLog = `${new Date()} - ${newLogCode}, ${newLogMessage}\n\n`;
+  }
+
+  if (log == null) {
+    return newLog;
   }
-  return setConnectionMessage(`${newLog}${connectionMessage}`);
+  return `${newLog}${log}`;
 };
 
 export {

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

@@ -533,6 +533,7 @@ module.exports = (crowi) => {
     catch (error) {
       return res.apiv3Err(new ErrorV3(`Error occured while sending message. Cause: ${error.message}`, 'send-message-failed', error.stack));
     }
+    return res.apiv3();
 
   });