zahmis %!s(int64=4) %!d(string=hai) anos
pai
achega
d951e2ffcf

+ 5 - 5
packages/slackbot-proxy/src/controllers/slack.ts

@@ -327,9 +327,9 @@ export class SlackCtrl {
         ],
       });
     }
-    const allowedRelation:RelationMock[] = [];
+    const allowedRelations:RelationMock[] = [];
     const disallowedGrowiUrls: Set<string> = new Set();
-    let commandName!:string| null;
+    let commandName!:string;
 
     await Promise.all(relations.map(async(relation) => {
       const permission = await this.relationsService.checkPermissionForInteractions(relation, channelName, callbackId, actionId);
@@ -339,7 +339,7 @@ export class SlackCtrl {
         disallowedGrowiUrls.add(relation.growiUri);
         commandName = notAllowedCommandName;
       }
-      allowedRelation.push(relation);
+      allowedRelations.push(relation);
     }));
 
     if (relations.length === disallowedGrowiUrls.size) {
@@ -359,7 +359,7 @@ export class SlackCtrl {
         user: body.user_id,
         blocks: [
           markdownSectionBlock('*None of GROWI permitted the command.*'),
-          markdownSectionBlock(`*'${commandName!}'* command was not allowed.`),
+          markdownSectionBlock(`*'${commandName}'* command was not allowed.`),
           markdownSectionBlock(
             `To use this command, modify settings from following pages: ${linkUrlList}`,
           ),
@@ -372,7 +372,7 @@ export class SlackCtrl {
     /*
      * forward to GROWI server
      */
-    allowedRelation.map(async(relation) => {
+    allowedRelations.map(async(relation) => {
       try {
         // generate API URL
         const url = new URL('/_api/v3/slack-integration/proxied/interactions', relation.growiUri);

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

@@ -106,37 +106,16 @@ export class RelationsService {
     return permission;
   }
 
-  // // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-  // postNotAllowedMessage(relations:RelationMock[], commandName:string, body:any):Promise<ChatPostEphemeralResponse> {
-  //   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({
-  //     text: 'Error occured.',
-  //     channel: body.channel_id,
-  //     user: body.user_id,
-  //     blocks: [
-  //       markdownSectionBlock(`It is not allowed to run *'${commandName}'* command to this GROWI.`),
-  //     ],
-  //   });
-  // }
-
 
   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|null}> {
+  ):Promise<{isPermittedForInteractions:boolean, notAllowedCommandName:string}> {
 
     const baseDate = new Date();
     const syncedRelation = await this.syncRelation(relation, baseDate);
-
     let isPermittedForInteractions!:boolean;
-    let notAllowedCommandName!:null|string;
-
-    if (syncedRelation == null) {
-      return { isPermittedForInteractions: false, notAllowedCommandName: null };
-    }
+    let notAllowedCommandName!:string;
 
     const singleUse = Object.keys(relation.permissionsForSingleUseCommands);
     const broadCastUse = Object.keys(relation.permissionsForBroadcastUseCommands);
@@ -144,6 +123,9 @@ export class RelationsService {
 
     [...singleUse, ...broadCastUse].forEach(async(commandName) => {
 
+      if (syncedRelation == null) {
+        return { isPermittedForInteractions: false, notAllowedCommandName: commandName };
+      }
       // ex. search OR search:handlerName
       const commandRegExp = new RegExp(`(^${commandName}$)|(^${commandName}:\\w+)`);