zahmis 4 лет назад
Родитель
Сommit
2518915e5d

+ 7 - 12
packages/slackbot-proxy/src/controllers/slack.ts

@@ -328,22 +328,15 @@ export class SlackCtrl {
       });
     }
 
-    const allowedRelations:RelationMock[] = [];
-    const disallowedGrowiUrls: Set<string> = new Set();
-    let notAllowedCommandName!:string;
-    const actionId:string = payload?.actions?.[0].action_id;
 
+    const actionId:string = payload?.actions?.[0].action_id;
     await Promise.all(relations.map(async(relation) => {
-      const permission = await this.relationsService.checkPermissionForInteractions(relation, channelName, callbackId, actionId);
-      const { isPermittedForInteractions, commandName } = permission;
+      await this.relationsService.checkPermissionForInteractions(relation, channelName, callbackId, actionId);
+    }));
 
-      if (!isPermittedForInteractions) {
-        disallowedGrowiUrls.add(relation.growiUri);
-        notAllowedCommandName = commandName;
-      }
 
-      allowedRelations.push(relation);
-    }));
+    const disallowedGrowiUrls = this.relationsService.getDisallowedGrowiUrls();
+    const notAllowedCommandName = this.relationsService.getCommandName();
 
     if (relations.length === disallowedGrowiUrls.size) {
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -376,6 +369,8 @@ export class SlackCtrl {
     /*
      * forward to GROWI server
      */
+
+    const allowedRelations = this.relationsService.getAllowedRelations();
     allowedRelations.map(async(relation) => {
       try {
         // generate API URL

+ 26 - 5
packages/slackbot-proxy/src/services/RelationsService.ts

@@ -107,17 +107,35 @@ export class RelationsService {
   }
 
 
+  allowedRelations:RelationMock[] = [];
+
+  getAllowedRelations():RelationMock[] {
+    return this.allowedRelations;
+  }
+
+  disallowedGrowiUrls: Set<string> = new Set();
+
+  getDisallowedGrowiUrls():Set<string> {
+    return this.disallowedGrowiUrls;
+  }
+
+  commandName:string;
+
+  getCommandName():string {
+    return this.commandName;
+  }
+
+
   async checkPermissionForInteractions(
       // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
       relation:RelationMock, channelName:string, callbackId:string, actionId:string,
-  ):Promise<{isPermittedForInteractions:boolean, commandName:string}> {
+  ):Promise<void>/* Promise<{isPermittedForInteractions:boolean, commandName:string, allowedRelations:RelationMock[], disallowedGrowiUrls:Set<string>}> */ {
 
-    let isPermittedForInteractions!:boolean;
-    let commandName!:string;
 
     const singleUse = Object.keys(relation.permissionsForSingleUseCommands);
     const broadCastUse = Object.keys(relation.permissionsForBroadcastUseCommands);
     let permissionForInteractions:boolean|string[];
+    let isPermittedForInteractions!:boolean;
 
     [...singleUse, ...broadCastUse].forEach(async(tempCommandName) => {
 
@@ -129,7 +147,7 @@ export class RelationsService {
         return;
       }
 
-      commandName = tempCommandName;
+      this.commandName = tempCommandName;
 
       // case: singleUse
       permissionForInteractions = relation.permissionsForSingleUseCommands[tempCommandName];
@@ -151,8 +169,11 @@ export class RelationsService {
       }
     });
 
+    if (!isPermittedForInteractions) {
+      this.disallowedGrowiUrls.add(relation.growiUri);
+    }
 
-    return { isPermittedForInteractions, commandName };
+    this.allowedRelations.push(relation);
   }
 
 }