Sfoglia il codice sorgente

move client position

zahmis 4 anni fa
parent
commit
c63d3dc8f2
1 ha cambiato i file con 7 aggiunte e 14 eliminazioni
  1. 7 14
      packages/slackbot-proxy/src/controllers/slack.ts

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

@@ -202,22 +202,11 @@ export class SlackCtrl {
     }
     }
 
 
     if (!isCommandPermitted) {
     if (!isCommandPermitted) {
-      const botToken = relations[0].installation?.data.bot?.token;
-
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      const client = generateWebClient(botToken!);
-
-      const relationMock = await this.relationMockRepository.findOne({
-        where: { installation },
-      });
-
+      // check permission at channel level
+      const relationMock = await this.relationMockRepository.findOne({ where: { installation } });
       const channelsObject = relationMock?.permittedChannelsForEachCommand.channelsObject;
       const channelsObject = relationMock?.permittedChannelsForEachCommand.channelsObject;
+      if (channelsObject == null) return;
 
 
-      if (channelsObject == null) {
-        return;
-      }
-
-      // check permission at channel level
       Object.keys(channelsObject).forEach((commandName) => {
       Object.keys(channelsObject).forEach((commandName) => {
         const permittedChannels = channelsObject[commandName];
         const permittedChannels = channelsObject[commandName];
         const fromChannel = body.channel_name;
         const fromChannel = body.channel_name;
@@ -230,6 +219,10 @@ export class SlackCtrl {
           return this.sendCommand(growiCommand, relationsForSingleUse, body);
           return this.sendCommand(growiCommand, relationsForSingleUse, body);
         }
         }
 
 
+        const botToken = relations[0].installation?.data.bot?.token;
+
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        const client = generateWebClient(botToken!);
         return client.chat.postEphemeral({
         return client.chat.postEphemeral({
           text: 'Error occured.',
           text: 'Error occured.',
           channel: body.channel_id,
           channel: body.channel_id,