Browse Source

FB move the restriction before generating tokens

kaori 4 years ago
parent
commit
e8bd41c598
1 changed files with 7 additions and 7 deletions
  1. 7 7
      src/server/routes/apiv3/slack-integration-settings.js

+ 7 - 7
src/server/routes/apiv3/slack-integration-settings.js

@@ -374,6 +374,13 @@ module.exports = (crowi) => {
    *            description: Succeeded to create slack app integration
    */
   router.put('/slack-app-integrations', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+    const SlackAppIntegrationRecordsNum = await SlackAppIntegration.countDocuments();
+    if (SlackAppIntegrationRecordsNum >= 10) {
+      const msg = 'Not be able to create more than 10 slack workspace integration settings';
+      logger.error('Error', msg);
+      return res.apiv3Err(new ErrorV3(msg, 'create-slackAppIntegeration-failed'), 500);
+    }
+
     let checkTokens;
     let tokenGtoP;
     let tokenPtoG;
@@ -386,13 +393,6 @@ module.exports = (crowi) => {
       checkTokens = await SlackAppIntegration.findOne({ $or: [{ tokenGtoP }, { tokenPtoG }] });
     } while (checkTokens != null);
     try {
-      const SlackAppIntegrationRecordsNum = await SlackAppIntegration.countDocuments();
-      if (SlackAppIntegrationRecordsNum >= 10) {
-        const msg = 'Not be able to create more than 10 slack workspace integration settings';
-        logger.error('Error', msg);
-        return res.apiv3Err(new ErrorV3(msg, 'create-slackAppIntegeration-failed'), 500);
-      }
-
       const slackAppTokens = await SlackAppIntegration.create({ tokenGtoP, tokenPtoG });
       return res.apiv3(slackAppTokens, 200);
     }