Просмотр исходного кода

Fixed conditions for permission checking

Taichi Masuyama 4 лет назад
Родитель
Сommit
2e64cb4da3
1 измененных файлов с 9 добавлено и 16 удалено
  1. 9 16
      packages/slackbot-proxy/src/controllers/slack.ts

+ 9 - 16
packages/slackbot-proxy/src/controllers/slack.ts

@@ -182,25 +182,18 @@ export class SlackCtrl {
     const baseDate = new Date();
 
     const allowedRelationsForSingleUse:Relation[] = [];
+    const allowedRelationsForBroadcastUse:Relation[] = [];
     const disallowedGrowiUrls: Set<string> = new Set();
 
-    // check permission for single use
+    // check permission
     await Promise.all(relations.map(async(relation) => {
-      const isSupported = await this.relationsService.isSupportedGrowiCommandForSingleUse(relation, growiCommand.growiCommandType, baseDate);
-      if (isSupported) {
+      const isSupportedForSingleUse = await this.relationsService.isSupportedGrowiCommandForSingleUse(relation, growiCommand.growiCommandType, baseDate);
+      const isSupportedForBroadcastUse = await this.relationsService.isSupportedGrowiCommandForBroadcastUse(relation, growiCommand.growiCommandType, baseDate);
+      if (isSupportedForSingleUse) {
         allowedRelationsForSingleUse.push(relation);
       }
-      else {
-        disallowedGrowiUrls.add(relation.growiUri);
-      }
-    }));
-
-    // check permission for broadcast use
-    const relationsForBroadcastUse:Relation[] = [];
-    await Promise.all(relations.map(async(relation) => {
-      const isSupported = await this.relationsService.isSupportedGrowiCommandForBroadcastUse(relation, growiCommand.growiCommandType, baseDate);
-      if (isSupported) {
-        relationsForBroadcastUse.push(relation);
+      else if (isSupportedForBroadcastUse) {
+        allowedRelationsForBroadcastUse.push(relation);
       }
       else {
         disallowedGrowiUrls.add(relation.growiUri);
@@ -243,8 +236,8 @@ export class SlackCtrl {
     }
 
     // forward to GROWI server
-    if (relationsForBroadcastUse.length > 0) {
-      return this.sendCommand(growiCommand, relationsForBroadcastUse, body);
+    if (allowedRelationsForBroadcastUse.length > 0) {
+      return this.sendCommand(growiCommand, allowedRelationsForBroadcastUse, body);
     }
   }