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

+ 6 - 4
packages/slackbot-proxy/src/controllers/slack.ts

@@ -327,18 +327,20 @@ export class SlackCtrl {
         ],
       });
     }
+
     const allowedRelations:RelationMock[] = [];
     const disallowedGrowiUrls: Set<string> = new Set();
-    let commandName!:string;
+    let notAllowedCommandName!:string;
 
     await Promise.all(relations.map(async(relation) => {
       const permission = await this.relationsService.checkPermissionForInteractions(relation, channelName, callbackId, actionId);
-      const { isPermittedForInteractions, notAllowedCommandName } = permission;
+      const { isPermittedForInteractions, commandName } = permission;
 
       if (!isPermittedForInteractions) {
         disallowedGrowiUrls.add(relation.growiUri);
-        commandName = notAllowedCommandName;
+        notAllowedCommandName = commandName;
       }
+
       allowedRelations.push(relation);
     }));
 
@@ -359,7 +361,7 @@ export class SlackCtrl {
         user: body.user_id,
         blocks: [
           markdownSectionBlock('*None of GROWI permitted the command.*'),
-          markdownSectionBlock(`*'${commandName}'* command was not allowed.`),
+          markdownSectionBlock(`*'${notAllowedCommandName}'* command was not allowed.`),
           markdownSectionBlock(
             `To use this command, modify settings from following pages: ${linkUrlList}`,
           ),

+ 12 - 11
packages/slackbot-proxy/src/services/RelationsService.ts

@@ -110,36 +110,39 @@ export class RelationsService {
   async checkPermissionForInteractions(
       // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
       relation:RelationMock, channelName:string, callbackId:string, actionId:string,
-  ):Promise<{isPermittedForInteractions:boolean, notAllowedCommandName:string}> {
+  ):Promise<{isPermittedForInteractions:boolean, commandName:string}> {
 
     const baseDate = new Date();
     const syncedRelation = await this.syncRelation(relation, baseDate);
     let isPermittedForInteractions!:boolean;
-    let notAllowedCommandName!:string;
+    let commandName!:string;
 
     const singleUse = Object.keys(relation.permissionsForSingleUseCommands);
     const broadCastUse = Object.keys(relation.permissionsForBroadcastUseCommands);
     let permissionForInteractions:boolean|string[];
 
-    [...singleUse, ...broadCastUse].forEach(async(commandName) => {
+    [...singleUse, ...broadCastUse].forEach(async(tempCommandName) => {
 
       if (syncedRelation == null) {
-        return { isPermittedForInteractions: false, notAllowedCommandName: commandName };
+        return { isPermittedForInteractions: false, commandName: tempCommandName };
       }
+
       // ex. search OR search:handlerName
-      const commandRegExp = new RegExp(`(^${commandName}$)|(^${commandName}:\\w+)`);
+      const commandRegExp = new RegExp(`(^${tempCommandName}$)|(^${tempCommandName}:\\w+)`);
 
       // skip this forEach loop if the requested command is not in permissionsForBroadcastUseCommands and permissionsForSingleUseCommands
       if (!commandRegExp.test(actionId) && !commandRegExp.test(callbackId)) {
         return;
       }
 
+      commandName = tempCommandName;
+
       // case: singleUse
-      permissionForInteractions = relation.permissionsForSingleUseCommands[commandName];
+      permissionForInteractions = relation.permissionsForSingleUseCommands[tempCommandName];
 
       // case: broadcastUse
       if (permissionForInteractions == null) {
-        permissionForInteractions = relation.permissionsForBroadcastUseCommands[commandName];
+        permissionForInteractions = relation.permissionsForBroadcastUseCommands[tempCommandName];
       }
 
       if (permissionForInteractions === true) {
@@ -152,12 +155,10 @@ export class RelationsService {
         isPermittedForInteractions = true;
         return;
       }
-
-      notAllowedCommandName = commandName;
-
     });
 
-    return { isPermittedForInteractions, notAllowedCommandName };
+
+    return { isPermittedForInteractions, commandName };
   }
 
 }