Browse Source

Merge branch 'feat/growi-bot' into imprv/gw6068-updating-tokens

# Conflicts:
#	src/server/routes/apiv3/slack-integration-settings.js
kaori 4 years ago
parent
commit
7b2d2a8f69

+ 3 - 2
packages/slackbot-proxy/src/controllers/growi-to-slack.ts

@@ -201,9 +201,10 @@ export class GrowiToSlackCtrl {
       return res.status(400).send({ message: `failed to send to slack. err: ${err.message}` });
     }
 
-    logger.debug('postMessage is success');
+    logger.debug('send to slack is success');
 
-    return res.end();
+    // required to return ok for apiCall
+    return res.send({ ok: true });
   }
 
 }

+ 2 - 2
packages/slackbot-proxy/src/controllers/slack.ts

@@ -153,11 +153,11 @@ export class SlackCtrl {
     const installation = await this.installationRepository.findByTeamIdOrEnterpriseId(installationId!);
 
     const payload = JSON.parse(body.payload);
-    const { type } = payload;
+    const callBackId = payload?.view?.callback_id;
 
     // register
     // response_urls is an array but the element included is only one.
-    if (type === 'view_submission') {
+    if (callBackId === 'register') {
       await this.registerService.upsertOrderRecord(this.orderRepository, installation, payload);
       await this.registerService.notifyServerUriToSlack(authorizeResult, payload);
       return;

+ 1 - 0
packages/slackbot-proxy/src/services/RegisterService.ts

@@ -19,6 +19,7 @@ export class RegisterService implements GrowiCommandProcessor {
       trigger_id: body.trigger_id,
       view: {
         type: 'modal',
+        callback_id: 'register',
         title: {
           type: 'plain_text',
           text: 'Register Credentials',

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

@@ -8,7 +8,7 @@ const CustomBotWithoutProxyConnectionStatus = (props) => {
   const connectionStatusValues = Object.values(connectionStatuses); // type: ConnectionStatus[]
 
   const totalCount = connectionStatusValues.length;
-  const errorCount = connectionStatusValues.filter(connectionStatus => connectionStatusValues.error != null).length;
+  const errorCount = connectionStatusValues.filter(connectionStatus => connectionStatus.error != null).length;
 
   let workspaceName;
   if (totalCount > 0) {
@@ -20,7 +20,7 @@ const CustomBotWithoutProxyConnectionStatus = (props) => {
       <div className="card rounded shadow border-0 w-50 admin-bot-card mb-0">
         <h5 className="card-title font-weight-bold mt-3 ml-4">Slack</h5>
         <div className="card-body p-2 w-50 mx-auto">
-          {totalCount > 0 ? '' : (
+          {totalCount > 0 ? (
             <div className="card slack-work-space-name-card">
               <div className="m-2 text-center">
                 <h5 className="font-weight-bold">
@@ -29,7 +29,7 @@ const CustomBotWithoutProxyConnectionStatus = (props) => {
                 <img width={20} height={20} src="/images/slack-integration/growi-bot-kun-icon.png" />
               </div>
             </div>
-         )}
+         ) : ''}
         </div>
       </div>
 

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

@@ -27,8 +27,6 @@ const CustomBotWithoutProxySettings = (props) => {
   };
 
   const testConnection = async() => {
-    setConnectionErrorCode(null);
-    setConnectionMessage(null);
     try {
       await appContainer.apiv3.post('/slack-integration-settings/without-proxy/test', { channel: testChannel });
       setConnectionMessage('Send the message to slack work space.');

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

@@ -376,11 +376,18 @@ module.exports = (crowi) => {
    *            description: Succeeded to create slack app integration
    */
   router.put('/slack-app-integrations', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
-    // TODO: refactering generateAccessTokens by GW-6100
+    const SlackAppIntegrationRecordsNum = await SlackAppIntegration.countDocuments();
+    if (SlackAppIntegrationRecordsNum >= 10) {
+      const msg = 'Not be able to create more than 10 slack workspace integration settings';
+      logger.error('Error', msg);
+      return res.apiv3Err(new ErrorV3(msg, 'create-slackAppIntegeration-failed'), 500);
+    }
+
     let checkTokens;
     let tokenGtoP;
     let tokenPtoG;
     let generateTokens;
+    // TODO: refactering generateAccessTokens by GW-6100
     do {
       generateTokens = SlackAppIntegration.generateAccessToken();
       tokenGtoP = generateTokens[0];

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

@@ -157,12 +157,12 @@ module.exports = (crowi) => {
     }
   };
 
-  const handleViewSubmission = async(payload) => {
+  const handleViewSubmission = async(client, payload) => {
     const { callback_id: callbackId } = payload.view;
 
     switch (callbackId) {
       case 'createPage':
-        await crowi.slackBotService.createPageInGrowi(payload);
+        await crowi.slackBotService.createPageInGrowi(client, payload);
         break;
       default:
         break;

+ 6 - 0
src/server/service/slackbot.js

@@ -67,6 +67,7 @@ class SlackBotService extends S2sMessageHandlable {
     client.chat.postEphemeral({
       channel: body.channel_id,
       user: body.user_id,
+      text: 'No command',
       blocks: [
         this.generateMarkdownSectionBlock('*No command.*\n Hint\n `/growi [command] [keyword]`'),
       ],
@@ -86,6 +87,7 @@ class SlackBotService extends S2sMessageHandlable {
       client.chat.postEphemeral({
         channel: body.channel_id,
         user: body.user_id,
+        text: 'Input keywords',
         blocks: [
           this.generateMarkdownSectionBlock('*Input keywords.*\n Hint\n `/growi search [keyword]`'),
         ],
@@ -106,6 +108,7 @@ class SlackBotService extends S2sMessageHandlable {
       client.chat.postEphemeral({
         channel: body.channel_id,
         user: body.user_id,
+        text: `No page found with "${keywords}"`,
         blocks: [
           this.generateMarkdownSectionBlock(`*No page that matches your keyword(s) "${keywords}".*`),
           this.generateMarkdownSectionBlock(':mag: *Help: Searching*'),
@@ -215,6 +218,7 @@ class SlackBotService extends S2sMessageHandlable {
       await client.chat.postEphemeral({
         channel: body.channel_id,
         user: body.user_id,
+        text: 'Successed To Search',
         blocks: [
           this.generateMarkdownSectionBlock(keywordsAndDesc),
           this.generateMarkdownSectionBlock(`${urls.join('\n')}`),
@@ -227,6 +231,7 @@ class SlackBotService extends S2sMessageHandlable {
       await client.chat.postEphemeral({
         channel: body.channel_id,
         user: body.user_id,
+        text: 'Failed To Search',
         blocks: [
           this.generateMarkdownSectionBlock('*Failed to search.*\n Hint\n `/growi search [keyword]`'),
         ],
@@ -268,6 +273,7 @@ class SlackBotService extends S2sMessageHandlable {
       await client.chat.postEphemeral({
         channel: body.channel_id,
         user: body.user_id,
+        text: 'Failed To Create',
         blocks: [
           this.generateMarkdownSectionBlock(`*Failed to create new page.*\n ${err}`),
         ],