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

add isPrimary flag to SlackAppIntegration and set true against to the first document

Yuki Takei 4 лет назад
Родитель
Сommit
05975a1c6b

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

@@ -4,6 +4,7 @@ const mongoose = require('mongoose');
 const schema = new mongoose.Schema({
   tokenGtoP: { type: String, required: true, unique: true },
   tokenPtoG: { type: String, required: true, unique: true },
+  isPrimary: { type: Boolean, unique: true, sparse: true },
   supportedCommandsForBroadcastUse: { type: [String], default: [] },
   supportedCommandsForSingleUse: { type: [String], default: [] },
 });

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

@@ -357,8 +357,8 @@ 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 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);
@@ -369,6 +369,7 @@ module.exports = (crowi) => {
       const slackAppTokens = await SlackAppIntegration.create({
         tokenGtoP,
         tokenPtoG,
+        isPrimary: slackAppIntegrationRecordsNum === 0 ? true : undefined,
         supportedCommandsForBroadcastUse: defaultSupportedCommandsNameForBroadcastUse,
         supportedCommandsForSingleUse: defaultSupportedCommandsNameForSingleUse,
       });