zahmis 4 лет назад
Родитель
Сommit
3889a62d0d
1 измененных файлов с 23 добавлено и 26 удалено
  1. 23 26
      packages/slackbot-proxy/src/controllers/slack.ts

+ 23 - 26
packages/slackbot-proxy/src/controllers/slack.ts

@@ -289,40 +289,37 @@ export class SlackCtrl {
       return;
       return;
     }
     }
 
 
-
-    // forward to GROWI server
-    if (callBackId === 'select_growi') {
-      const selectedGrowiInformation = await this.selectGrowiService.handleSelectInteraction(installation, payload);
-      return this.sendCommand(selectedGrowiInformation.growiCommand, [selectedGrowiInformation.relation], selectedGrowiInformation.sendCommandBody);
-    }
-
     // check permission at channel level
     // check permission at channel level
+    let actionId:string;
+    let fromChannel:string;
     if (payload?.actions != null) {
     if (payload?.actions != null) {
-      const actionId = payload?.actions[0].action_id;
-      const fromChannel = payload?.channel.name;
+      actionId = payload?.actions[0].action_id;
+      fromChannel = payload?.channel.name;
+    }
 
 
-      const relationMock = await this.relationMockRepository.findOne({
-        where: { installation },
-      });
+    const relationMock = await this.relationMockRepository.findOne({ where: { installation } });
+    const channelsObject = relationMock?.permittedChannelsForEachCommand.channelsObject;
+    if (channelsObject == null) return;
 
 
-      const channelsObject = relationMock?.permittedChannelsForEachCommand.channelsObject;
+    Object.keys(channelsObject).forEach((commandName) => {
+      const permittedChannels = channelsObject[commandName];
 
 
-      if (channelsObject == null) {
-        return;
+      const commandRegExp = new RegExp(`(^${commandName}$)|(^${commandName}:\\w+)`);
+      // RegExp check
+      if (commandRegExp.test(actionId) || commandRegExp.test(callBackId)) {
+        // check if the channel is permitted
+        const isPermittedChannel = permittedChannels.includes(fromChannel);
+        if (!isPermittedChannel) {
+          return res.status(403).send(`It is not allowed to run '${commandName}' command to this GROWI.`);
+        }
       }
       }
+    });
 
 
-      Object.keys(channelsObject).forEach((commandName) => {
-        const permittedChannels = channelsObject[commandName];
 
 
-        const commandRegExp = new RegExp(`(^${commandName}$)|(^${commandName}:\\w+)`);
-        // RegExp check
-        if (commandRegExp.test(actionId) || commandRegExp.test(callBackId)) {
-          // check if the channel is permitted
-          if (permittedChannels.includes(fromChannel) == null) {
-            return res.status(403).send(`It is not allowed to run '${commandName}' command to this GROWI.`);
-          }
-        }
-      });
+    // forward to GROWI server
+    if (callBackId === 'select_growi') {
+      const selectedGrowiInformation = await this.selectGrowiService.handleSelectInteraction(installation, payload);
+      return this.sendCommand(selectedGrowiInformation.growiCommand, [selectedGrowiInformation.relation], selectedGrowiInformation.sendCommandBody);
     }
     }
 
 
     /*
     /*