zahmis 4 лет назад
Родитель
Сommit
9d6087f3b7

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

@@ -49,9 +49,11 @@ module.exports = (crowi) => {
     const tokenPtoG = req.headers['x-growi-ptog-tokens'];
 
     const relation = await SlackAppIntegrationMock.findOne({ tokenPtoG });
-    const { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse, permittedChannelsForEachCommand } = relation;
+    const { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse } = relation;
+    const { permittedChannelsForEachCommand } = req.body;
+    const { create, search } = permittedChannelsForEachCommand;
+
     const supportedCommands = supportedCommandsForBroadcastUse.concat(supportedCommandsForSingleUse);
-    console.log(relation);
     const supportedGrowiActionsRegExps = getSupportedGrowiActionsRegExps(supportedCommands);
 
     // get command name from req.body
@@ -63,6 +65,8 @@ module.exports = (crowi) => {
       payload = JSON.parse(req.body.payload);
     }
 
+    console.log(req.body);
+
     if (req.body.text == null && !payload) { // when /relation-test
       return next();
     }
@@ -84,6 +88,10 @@ module.exports = (crowi) => {
       }
     });
 
+    if (create.includes(req.body.channel_name)) {
+      next();
+    }
+
     // validate
     if (command && !supportedCommands.includes(command)) {
       return res.status(403).send(`It is not allowed to run '${command}' command to this GROWI.`);
@@ -170,7 +178,6 @@ module.exports = (crowi) => {
 
   router.post('/proxied/commands', verifyAccessTokenFromProxy, checkCommandPermission, async(req, res) => {
     const { body } = req;
-
     // eslint-disable-next-line max-len
     // see: https://api.slack.com/apis/connections/events-api#the-events-api__subscribing-to-event-types__events-api-request-urls__request-url-configuration--verification
     if (body.type === 'url_verification') {

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

@@ -78,8 +78,6 @@ export class SlackCtrl {
     const promises = relations.map((relation: RelationMock) => {
       // generate API URL
       const url = new URL('/_api/v3/slack-integration/proxied/commands', relation.growiUri);
-      console.log('in sendcommand');
-      // console.log(relation);
       return axios.post(url.toString(), {
         ...body,
         growiCommand,
@@ -218,7 +216,8 @@ export class SlackCtrl {
       const canCreateArray = permittedChannelsForEachCommand?.create;
       const canSearchArray = permittedChannelsForEachCommand?.search;
 
-      if (canCreateArray == null || canSearchArray == null) {
+
+      if (canCreateArray?.length === 0 || canSearchArray?.length === 0) {
         return client.chat.postEphemeral({
           text: 'Error occured.',
           channel: body.channel_id,
@@ -229,15 +228,13 @@ export class SlackCtrl {
         });
       }
 
-      const isCreate = canCreateArray.includes(body.channel_name);
+      const isCreate = canCreateArray?.includes(body.channel_name);
       if (isCreate) {
         console.log('isCreate 内部');
-        console.log(relations[0]);
         const relationsForBroadcastUse:RelationMock[] = [];
         body.permittedChannelsForEachCommand = relations[0].permittedChannelsForEachCommand;
         relationsForBroadcastUse.push(relations[0]);
         console.log(relations[0].permittedChannelsForEachCommand);
-        console.log(body);
         return this.sendCommand(growiCommand, relationsForBroadcastUse, body);
       }
     }