itizawa 4 anni fa
parent
commit
9cd2500fc5

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

@@ -179,12 +179,15 @@ export class GrowiToSlackCtrl {
         tokenGtoP: order.tokenGtoP,
         tokenGtoP: order.tokenGtoP,
         tokenPtoG: order.tokenPtoG,
         tokenPtoG: order.tokenPtoG,
         growiUri: order.growiUrl,
         growiUri: order.growiUrl,
-        broadcastCommands: req.body.broadcastCommands,
-        singlePostCommands: req.body.singlePostCommands,
+        supportedCommandsForBroadcastUse: req.body.supportedCommandsForBroadcastUse,
+        supportedCommandsForSingleUse: req.body.supportedCommandsForSingleUse,
         expiredAtCommands,
         expiredAtCommands,
       })
       })
       // https://github.com/typeorm/typeorm/issues/1090#issuecomment-634391487
       // https://github.com/typeorm/typeorm/issues/1090#issuecomment-634391487
-      .orUpdate({ conflict_target: ['installation', 'growiUri'], overwrite: ['tokenGtoP', 'tokenPtoG', 'broadcastCommands', 'singlePostCommands'] })
+      .orUpdate({
+        conflict_target: ['installation', 'growiUri'],
+        overwrite: ['tokenGtoP', 'tokenPtoG', 'supportedCommandsForBroadcastUse', 'supportedCommandsForSingleUse'],
+      })
       .execute();
       .execute();
 
 
     // Find the generated relation
     // Find the generated relation

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

@@ -161,7 +161,7 @@ export class SlackCtrl {
 
 
     body.growiUrisForSinglePost = relations.filter((relation) => {
     body.growiUrisForSinglePost = relations.filter((relation) => {
       // TODO GW-6845 retrieve commands if it has expired
       // TODO GW-6845 retrieve commands if it has expired
-      return !relation.isExpiredCommands() && relation.singlePostCommands.includes(growiCommand.growiCommandType);
+      return !relation.isExpiredCommands() && relation.supportedCommandsForSingleUse.includes(growiCommand.growiCommandType);
     }).map(relation => relation.growiUri);
     }).map(relation => relation.growiUri);
 
 
 
 
@@ -171,7 +171,7 @@ export class SlackCtrl {
 
 
     const relationsForBroadcast = relations.filter((relation) => {
     const relationsForBroadcast = relations.filter((relation) => {
       // TODO GW-6845 retrieve commands if it has expired
       // TODO GW-6845 retrieve commands if it has expired
-      return !relation.isExpiredCommands() && relation.broadcastCommands.includes(growiCommand.growiCommandType);
+      return !relation.isExpiredCommands() && relation.supportedCommandsForBroadcastUse.includes(growiCommand.growiCommandType);
     });
     });
 
 
     /*
     /*

+ 2 - 2
packages/slackbot-proxy/src/entities/relation.ts

@@ -31,10 +31,10 @@ export class Relation {
   growiUri: string;
   growiUri: string;
 
 
   @Column('simple-array')
   @Column('simple-array')
-  broadcastCommands: string[];
+  supportedCommandsForBroadcastUse: string[];
 
 
   @Column('simple-array')
   @Column('simple-array')
-  singlePostCommands: string[];
+  supportedCommandsForSingleUse: string[];
 
 
   @CreateDateColumn()
   @CreateDateColumn()
   expiredAtCommands: Date;
   expiredAtCommands: Date;

+ 2 - 2
src/server/models/slack-app-integration.js

@@ -4,8 +4,8 @@ const mongoose = require('mongoose');
 const schema = new mongoose.Schema({
 const schema = new mongoose.Schema({
   tokenGtoP: { type: String, required: true, unique: true },
   tokenGtoP: { type: String, required: true, unique: true },
   tokenPtoG: { type: String, required: true, unique: true },
   tokenPtoG: { type: String, required: true, unique: true },
-  broadcastCommands: { type: [String], default: [] },
-  singlePostCommands: { type: [String], default: [] },
+  supportedCommandsForBroadcastUse: { type: [String], default: [] },
+  supportedCommandsForSingleUse: { type: [String], default: [] },
 });
 });
 
 
 class SlackAppIntegration {
 class SlackAppIntegration {

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

@@ -105,7 +105,7 @@ module.exports = (crowi) => {
     return result.data;
     return result.data;
   }
   }
 
 
-  async function postRelationTest(token, broadcastCommands, singlePostCommands) {
+  async function postRelationTest(token, supportedCommandsForBroadcastUse, supportedCommandsForSingleUse) {
     const proxyUri = crowi.configManager.getConfig('crowi', 'slackbot:proxyServerUri');
     const proxyUri = crowi.configManager.getConfig('crowi', 'slackbot:proxyServerUri');
     if (proxyUri == null) {
     if (proxyUri == null) {
       throw new Error('Proxy URL is not registered');
       throw new Error('Proxy URL is not registered');
@@ -115,7 +115,7 @@ module.exports = (crowi) => {
       'x-growi-gtop-tokens': token,
       'x-growi-gtop-tokens': token,
     };
     };
 
 
-    const result = await axios.post(urljoin(proxyUri, '/g2s/relation-test'), { broadcastCommands, singlePostCommands }, { headers });
+    const result = await axios.post(urljoin(proxyUri, '/g2s/relation-test'), { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse }, { headers });
 
 
     return result.data;
     return result.data;
   }
   }
@@ -400,12 +400,12 @@ module.exports = (crowi) => {
     }
     }
 
 
     const { tokenGtoP, tokenPtoG } = await SlackAppIntegration.generateUniqueAccessTokens();
     const { tokenGtoP, tokenPtoG } = await SlackAppIntegration.generateUniqueAccessTokens();
-    const broadcastCommands = ['search'];
-    const singlePostCommands = ['create'];
+    const supportedCommandsForBroadcastUse = ['search'];
+    const supportedCommandsForSingleUse = ['create'];
 
 
     try {
     try {
       const slackAppTokens = await SlackAppIntegration.create({
       const slackAppTokens = await SlackAppIntegration.create({
-        tokenGtoP, tokenPtoG, broadcastCommands, singlePostCommands,
+        tokenGtoP, tokenPtoG, supportedCommandsForBroadcastUse, supportedCommandsForSingleUse,
       });
       });
       return res.apiv3(slackAppTokens, 200);
       return res.apiv3(slackAppTokens, 200);
     }
     }
@@ -526,7 +526,9 @@ module.exports = (crowi) => {
         const msg = 'Could not find SlackAppIntegration by id';
         const msg = 'Could not find SlackAppIntegration by id';
         return res.apiv3Err(new ErrorV3(msg, 'find-slackAppIntegration-failed'), 400);
         return res.apiv3Err(new ErrorV3(msg, 'find-slackAppIntegration-failed'), 400);
       }
       }
-      const result = await postRelationTest(slackAppIntegration.tokenGtoP, slackAppIntegration.broadcastCommands, slackAppIntegration.singlePostCommands);
+      const result = await postRelationTest(
+        slackAppIntegration.tokenGtoP, slackAppIntegration.supportedCommandsForBroadcastUse, slackAppIntegration.supportedCommandsForSingleUse,
+      );
       slackBotToken = result.slackBotToken;
       slackBotToken = result.slackBotToken;
       if (slackBotToken == null) {
       if (slackBotToken == null) {
         const msg = 'Could not find slackBotToken by relation';
         const msg = 'Could not find slackBotToken by relation';