Sfoglia il codice sorgente

Merge branch 'master' into feat/4836-6675-implement-meta-description

itizawa 4 anni fa
parent
commit
ba07c97f25

+ 32 - 24
packages/slackbot-proxy/src/services/RegisterService.ts

@@ -1,5 +1,5 @@
 import { Inject, Service } from '@tsed/di';
-import { WebClient, LogLevel } from '@slack/web-api';
+import { WebClient, LogLevel, Block } from '@slack/web-api';
 import { generateInputSectionBlock, GrowiCommand, generateMarkdownSectionBlock } from '@growi/slack';
 import { AuthorizeResult } from '@slack/oauth';
 import { GrowiCommandProcessor } from '~/interfaces/slack-to-growi/growi-command-processor';
@@ -8,6 +8,7 @@ import { Installation } from '~/entities/installation';
 import { InvalidUrlError } from '../models/errors';
 
 const isProduction = process.env.NODE_ENV === 'production';
+const isOfficialMode = process.env.OFFICIAL_MODE === 'true';
 
 @Service()
 export class RegisterService implements GrowiCommandProcessor {
@@ -47,6 +48,18 @@ export class RegisterService implements GrowiCommandProcessor {
     });
   }
 
+  async replyToSlack(client: WebClient, channel: string, user: string, text: string, blocks: Array<Block>): Promise<void> {
+    await client.chat.postEphemeral({
+      channel,
+      user,
+      // Recommended including 'text' to provide a fallback when using blocks
+      // refer to https://api.slack.com/methods/chat.postEphemeral#text_usage
+      text,
+      blocks,
+    });
+    return;
+  }
+
   async insertOrderRecord(
       installation: Installation | undefined,
       // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
@@ -67,18 +80,10 @@ export class RegisterService implements GrowiCommandProcessor {
     }
     catch (error) {
       const invalidErrorMsg = 'Please enter a valid URL';
-
-      await client.chat.postEphemeral({
-        channel,
-        user: payload.user.id,
-        // Recommended including 'text' to provide a fallback when using blocks
-        // refer to https://api.slack.com/methods/chat.postEphemeral#text_usage
-        text: 'Invalid URL',
-        blocks: [
-          generateMarkdownSectionBlock(invalidErrorMsg),
-        ],
-      });
-
+      const blocks = [
+        generateMarkdownSectionBlock(invalidErrorMsg),
+      ];
+      await this.replyToSlack(client, channel, payload.user.id, 'Invalid URL', blocks);
       throw new InvalidUrlError(growiUrl);
     }
 
@@ -98,17 +103,20 @@ export class RegisterService implements GrowiCommandProcessor {
 
     const client = new WebClient(botToken, { logLevel: isProduction ? LogLevel.DEBUG : LogLevel.INFO });
 
-    await client.chat.postEphemeral({
-      channel,
-      user: payload.user.id,
-      // Recommended including 'text' to provide a fallback when using blocks
-      // refer to https://api.slack.com/methods/chat.postEphemeral#text_usage
-      text: 'Proxy URL',
-      blocks: [
-        generateMarkdownSectionBlock('Please enter and update the following Proxy URL to slack bot setting form in your GROWI'),
-        generateMarkdownSectionBlock(`Proxy URL: ${serverUri}`),
-      ],
-    });
+    if (isOfficialMode) {
+      const blocks = [
+        generateMarkdownSectionBlock('Successfully registered with the proxy! Please check test connection in your GROWI'),
+      ];
+      await this.replyToSlack(client, channel, payload.user.id, 'Proxy URL', blocks);
+      return;
+
+    }
+
+    const blocks = [
+      generateMarkdownSectionBlock('Please enter and update the following Proxy URL to slack bot setting form in your GROWI'),
+      generateMarkdownSectionBlock(`Proxy URL: ${serverUri}`),
+    ];
+    await this.replyToSlack(client, channel, payload.user.id, 'Proxy URL', blocks);
     return;
   }
 

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

@@ -13,19 +13,12 @@ const logger = loggerFactory('growi:SlackBotSettings');
 
 const OfficialBotSettings = (props) => {
   const {
-    appContainer, slackAppIntegrations, proxyServerUri, onClickAddSlackWorkspaceBtn, connectionStatuses, onUpdateTokens, onSubmitForm,
+    appContainer, slackAppIntegrations, onClickAddSlackWorkspaceBtn, connectionStatuses, onUpdateTokens, onSubmitForm,
   } = props;
   const [siteName, setSiteName] = useState('');
   const [integrationIdToDelete, setIntegrationIdToDelete] = useState(null);
   const { t } = useTranslation();
 
-  const [newProxyServerUri, setNewProxyServerUri] = useState();
-
-  // componentDidUpdate
-  useEffect(() => {
-    setNewProxyServerUri(proxyServerUri);
-  }, [proxyServerUri, slackAppIntegrations]);
-
   const addSlackAppIntegrationHandler = async() => {
     if (onClickAddSlackWorkspaceBtn != null) {
       onClickAddSlackWorkspaceBtn();
@@ -46,19 +39,6 @@ const OfficialBotSettings = (props) => {
     }
   };
 
-  const updateProxyUri = async() => {
-    try {
-      await appContainer.apiv3.put('/slack-integration-settings/proxy-uri', {
-        proxyUri: newProxyServerUri,
-      });
-      toastSuccess(t('toaster.update_successed', { target: t('Proxy URL') }));
-    }
-    catch (err) {
-      toastError(err);
-      logger.error(err);
-    }
-  };
-
   useEffect(() => {
     const siteName = appContainer.config.crowi.title;
     setSiteName(siteName);
@@ -78,22 +58,6 @@ const OfficialBotSettings = (props) => {
             connectionStatuses={connectionStatuses}
           />
 
-          <div className="form-group row my-4">
-            <label className="text-left text-md-right col-md-3 col-form-label mt-3">Proxy URL</label>
-            <div className="col-md-6 mt-3">
-              <input
-                className="form-control"
-                type="text"
-                name="settingForm[proxyUrl]"
-                defaultValue={newProxyServerUri}
-                onChange={(e) => { setNewProxyServerUri(e.target.value) }}
-              />
-            </div>
-            <div className="col-md-2 mt-3 text-center text-md-left">
-              <button type="button" className="btn btn-primary" onClick={updateProxyUri}>{ t('Update') }</button>
-            </div>
-          </div>
-
           <h2 className="admin-setting-header">{t('admin:slack_integration.integration_procedure')}</h2>
         </>
       )}
@@ -159,7 +123,6 @@ OfficialBotSettings.propTypes = {
   appContainer: PropTypes.instanceOf(AppContainer).isRequired,
 
   slackAppIntegrations: PropTypes.array,
-  proxyServerUri: PropTypes.string,
   onClickAddSlackWorkspaceBtn: PropTypes.func,
   onDeleteSlackAppIntegration: PropTypes.func,
   connectionStatuses: PropTypes.object.isRequired,

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

@@ -15,6 +15,7 @@ import DeleteSlackBotSettingsModal from './DeleteSlackBotSettingsModal';
 const botTypes = ['officialBot', 'customBotWithoutProxy', 'customBotWithProxy'];
 
 const SlackIntegration = (props) => {
+
   const { appContainer } = props;
   const { t } = useTranslation();
   const [currentBotType, setCurrentBotType] = useState(null);
@@ -124,7 +125,6 @@ const SlackIntegration = (props) => {
       settingsComponent = (
         <OfficialBotSettings
           slackAppIntegrations={slackAppIntegrations}
-          proxyServerUri={proxyServerUri}
           onClickAddSlackWorkspaceBtn={createSlackIntegrationData}
           onDeleteSlackAppIntegration={fetchSlackIntegrationData}
           connectionStatuses={connectionStatuses}

+ 0 - 4
src/client/js/components/Admin/SlackIntegration/WithProxyAccordions.jsx

@@ -303,10 +303,6 @@ const WithProxyAccordions = (props) => {
       />,
     },
     '③': {
-      title: 'set_proxy_url_on_growi',
-      content: <RegisteringProxyUrlProcess />,
-    },
-    '④': {
       title: 'test_connection',
       content: <TestProcess
         apiv3Post={props.appContainer.apiv3.post}

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

@@ -276,6 +276,10 @@ module.exports = (crowi) => {
     await resetAllBotSettings();
     const requestParams = { 'slackbot:currentBotType': currentBotType };
 
+    if (currentBotType === 'officialBot') {
+      requestParams['slackbot:proxyServerUri'] = 'https://slackbot-proxy.growi.org';
+    }
+
     try {
       await updateSlackBotSettings(requestParams);
       crowi.slackBotService.publishUpdatedMessage();