فهرست منبع

update relation

itizawa 4 سال پیش
والد
کامیت
830b91a184

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

@@ -26,9 +26,6 @@ import { SectionBlockPayloadDelegator } from '~/services/growi-uri-injector/Sect
 
 const logger = loggerFactory('slackbot-proxy:controllers:growi-to-slack');
 
-// temporarily save for selection to growi
-const temporarySinglePostCommands = ['create'];
-
 @Controller('/g2s')
 export class GrowiToSlackCtrl {
 
@@ -170,6 +167,10 @@ export class GrowiToSlackCtrl {
 
     logger.debug('relation test is success', order);
 
+    // temporary cache for 48 hours
+    const now = new Date();
+    const expiredAtCommands = new Date(now.setHours(now.getHours() + 48));
+
     // Transaction is not considered because it is used infrequently,
     const response = await this.relationRepository.createQueryBuilder('relation')
       .insert()
@@ -178,10 +179,12 @@ export class GrowiToSlackCtrl {
         tokenGtoP: order.tokenGtoP,
         tokenPtoG: order.tokenPtoG,
         growiUri: order.growiUrl,
-        siglePostCommands: temporarySinglePostCommands,
+        broadcastCommands: req.body.broadcastCommands,
+        singlePostCommands: req.body.singlePostCommands,
+        expiredAtCommands,
       })
       // https://github.com/typeorm/typeorm/issues/1090#issuecomment-634391487
-      .orUpdate({ conflict_target: ['installation', 'growiUri'], overwrite: ['tokenGtoP', 'tokenPtoG', 'siglePostCommands'] })
+      .orUpdate({ conflict_target: ['installation', 'growiUri'], overwrite: ['tokenGtoP', 'tokenPtoG', 'broadcastCommands', 'singlePostCommands'] })
       .execute();
 
     // Find the generated relation

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

@@ -161,7 +161,7 @@ export class SlackCtrl {
 
     body.growiUris = [];
     relations.forEach((relation) => {
-      if (relation.siglePostCommands.includes(growiCommand.growiCommandType)) {
+      if (relation.singlePostCommands.includes(growiCommand.growiCommandType)) {
         body.growiUris.push(relation.growiUri);
       }
     });

+ 7 - 1
packages/slackbot-proxy/src/entities/relation.ts

@@ -31,6 +31,12 @@ export class Relation {
   growiUri: string;
 
   @Column('simple-array')
-  siglePostCommands: string[];
+  broadcastCommands: string[];
+
+  @Column('simple-array')
+  singlePostCommands: string[];
+
+  @CreateDateColumn()
+  expiredAtCommands: Date;
 
 }

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

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