Просмотр исходного кода

Modified permittedChannelsForEachCommand schema

Taichi Masuyama 4 лет назад
Родитель
Сommit
46daa96049

+ 1 - 1
packages/app/src/server/models/slack-app-integration-mock.js

@@ -2,7 +2,7 @@ const crypto = require('crypto');
 const mongoose = require('mongoose');
 const mongoose = require('mongoose');
 
 
 const permittedChannelsForEachCommandSchema = new mongoose.Schema({
 const permittedChannelsForEachCommandSchema = new mongoose.Schema({
-  channelsObject: {},
+  channelsObject: Map,
 });
 });
 
 
 
 

+ 3 - 1
packages/app/src/server/routes/apiv3/slack-integration-settings.js

@@ -422,7 +422,9 @@ module.exports = (crowi) => {
         tokenPtoG,
         tokenPtoG,
         supportedCommandsForBroadcastUse: defaultSupportedCommandsNameForBroadcastUse,
         supportedCommandsForBroadcastUse: defaultSupportedCommandsNameForBroadcastUse,
         supportedCommandsForSingleUse: defaultSupportedCommandsNameForSingleUse,
         supportedCommandsForSingleUse: defaultSupportedCommandsNameForSingleUse,
-        permittedChannelsForEachCommand: {},
+        permittedChannelsForEachCommand: {
+          channelsObject: new Map(),
+        },
       });
       });
       // MOCK DATA DELETE THIS GW-6972 ---------------
       // MOCK DATA DELETE THIS GW-6972 ---------------
       return res.apiv3(slackAppTokens, 200);
       return res.apiv3(slackAppTokens, 200);

+ 4 - 6
packages/app/src/server/routes/apiv3/slack-integration.js

@@ -59,7 +59,7 @@ module.exports = (crowi) => {
     // MOCK DATA DELETE THIS GW-6972 ---------------
     // MOCK DATA DELETE THIS GW-6972 ---------------
     const SlackAppIntegrationMock = mongoose.model('SlackAppIntegrationMock');
     const SlackAppIntegrationMock = mongoose.model('SlackAppIntegrationMock');
     const slackAppIntegrationMock = await SlackAppIntegrationMock.findOne({ tokenPtoG });
     const slackAppIntegrationMock = await SlackAppIntegrationMock.findOne({ tokenPtoG });
-    const permittedChannelsForEachCommand = slackAppIntegrationMock.permittedChannelsForEachCommand._doc;
+    const channelsObject = slackAppIntegrationMock.permittedChannelsForEachCommand._doc.channelsObject;
     // MOCK DATA DELETE THIS GW-6972 ---------------
     // MOCK DATA DELETE THIS GW-6972 ---------------
     const { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse } = relation;
     const { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse } = relation;
     const supportedCommands = supportedCommandsForBroadcastUse.concat(supportedCommandsForSingleUse);
     const supportedCommands = supportedCommandsForBroadcastUse.concat(supportedCommandsForSingleUse);
@@ -82,10 +82,8 @@ module.exports = (crowi) => {
 
 
     // code below checks permission at channel level
     // code below checks permission at channel level
     const fromChannel = req.body.channel_name || payload.channel.name;
     const fromChannel = req.body.channel_name || payload.channel.name;
-    for (const commandName of Object.keys(permittedChannelsForEachCommand)) {
-      if (commandName === '_id') continue;
-
-      const permittedChannels = permittedChannelsForEachCommand[commandName];
+    [...channelsObject.keys()].forEach((commandName) => {
+      const permittedChannels = channelsObject.get(commandName);
       // ex. search OR search:hogehoge
       // ex. search OR search:hogehoge
       const commandRegExp = new RegExp(`(^${commandName}$)|(^${commandName}:\\w+)`);
       const commandRegExp = new RegExp(`(^${commandName}$)|(^${commandName}:\\w+)`);
 
 
@@ -94,7 +92,7 @@ module.exports = (crowi) => {
         // check if the channel is permitted
         // check if the channel is permitted
         if (permittedChannels.includes(fromChannel)) return next();
         if (permittedChannels.includes(fromChannel)) return next();
       }
       }
-    }
+    });
 
 
     // code below checks permission at command level
     // code below checks permission at command level
     let isActionSupported = false;
     let isActionSupported = false;