zahmis 4 سال پیش
والد
کامیت
4b39ea0c4d
2فایلهای تغییر یافته به همراه36 افزوده شده و 20 حذف شده
  1. 3 7
      packages/slackbot-proxy/src/controllers/slack.ts
  2. 33 13
      packages/slackbot-proxy/src/services/RelationsService.ts

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

@@ -169,15 +169,13 @@ export class SlackCtrl {
     const baseDate = new Date();
 
     const relationsForSingleUse:RelationMock[] = [];
-
     await Promise.all(relations.map(async(relation) => {
-      const isSupported = await this.relationsService.isSupportedGrowiCommandForSingleUse(relation, growiCommand.growiCommandType, body.channel_name, baseDate);
+      const isSupported = await this.relationsService.checkPermissionForCommands(relation, growiCommand.growiCommandType, body.channel_name, baseDate);
       if (isSupported) {
         return relationsForSingleUse.push(relation);
       }
     }));
 
-
     if (relationsForSingleUse.length > 0) {
       body.growiUrisForSingleUse = relationsForSingleUse.map(v => v.growiUri);
       return this.selectGrowiService.process(growiCommand, authorizeResult, body);
@@ -185,15 +183,13 @@ export class SlackCtrl {
 
     const relationsForBroadcastUse:RelationMock[] = [];
     await Promise.all(relations.map(async(relation) => {
-      const isSupported = await this.relationsService.isSupportedGrowiCommandForBroadcastUse(
-        relation, growiCommand.growiCommandType, body.channel_name, baseDate,
-      );
+      const isSupported = await this.relationsService.checkPermissionForCommands(relation, growiCommand.growiCommandType, body.channel_name, baseDate);
 
       if (isSupported) {
         return relationsForBroadcastUse.push(relation);
       }
 
-      this.relationsService.postNotPermissionMessage(relations, growiCommand.growiCommandType, body);
+      this.relationsService.postNotAllowedMessage(relations, growiCommand.growiCommandType, body);
     }));
 
     /*

+ 33 - 13
packages/slackbot-proxy/src/services/RelationsService.ts

@@ -120,8 +120,28 @@ export class RelationsService {
     return permission;
   }
 
+
+  async checkPermissionForCommands(relation:RelationMock, growiCommandType:string, channelName:string, baseDate:Date):Promise<boolean> {
+    const syncedRelation = await this.syncRelation(relation, baseDate);
+    if (syncedRelation == null) {
+      return false;
+    }
+
+    const permission = relation.supportedCommandsForBroadcastUse[growiCommandType];
+
+    if (permission == null) {
+      return false;
+    }
+
+    if (Array.isArray(permission)) {
+      return permission.includes(channelName);
+    }
+
+    return permission;
+  }
+
   // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-  postNotPermissionMessage(relations:RelationMock[], commandName:string, body:any):Promise<ChatPostEphemeralResponse> {
+  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!);
@@ -136,9 +156,9 @@ export class RelationsService {
     });
   }
 
-  isPermitted = false;
+  isPermittedForInteractions = false;
 
-  permission:boolean|string[];
+  permissionForInteractions:boolean|string[];
 
   async checkPermissionForInteractions(
       // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
@@ -149,27 +169,27 @@ export class RelationsService {
     const syncedRelation = await this.syncRelation(relation, baseDate);
 
     if (syncedRelation == null) {
-      this.isPermitted = false;
+      this.isPermittedForInteractions = false;
       return;
     }
     const singleUse = Object.keys(relation.supportedCommandsForSingleUse);
     const broadCastUse = Object.keys(relation.supportedCommandsForBroadcastUse);
 
     [...singleUse, ...broadCastUse].forEach(async(commandName) => {
-      this.permission = relation.supportedCommandsForSingleUse[commandName];
+      this.permissionForInteractions = relation.supportedCommandsForSingleUse[commandName];
 
-      if (this.permission == null) {
-        this.permission = relation.supportedCommandsForBroadcastUse[commandName];
+      if (this.permissionForInteractions == null) {
+        this.permissionForInteractions = relation.supportedCommandsForBroadcastUse[commandName];
       }
 
       // permission check
-      if (this.permission === true) {
-        this.isPermitted = true;
+      if (this.permissionForInteractions === true) {
+        this.isPermittedForInteractions = true;
         return;
       }
 
-      if (Array.isArray(this.permission)) {
-        this.isPermitted = this.permission.includes(channelName);
+      if (Array.isArray(this.permissionForInteractions)) {
+        this.isPermittedForInteractions = this.permissionForInteractions.includes(channelName);
         return;
       }
 
@@ -181,8 +201,8 @@ export class RelationsService {
         return;
       }
 
-      if (!this.isPermitted) {
-        this.postNotPermissionMessage(relations, commandName, body);
+      if (!this.isPermittedForInteractions) {
+        this.postNotAllowedMessage(relations, commandName, body);
       }
     });
   }