Quellcode durchsuchen

impl put action: command permission

zahmis vor 4 Jahren
Ursprung
Commit
ff7fa0b30e
1 geänderte Dateien mit 24 neuen und 13 gelöschten Zeilen
  1. 24 13
      packages/app/src/server/routes/apiv3/slack-integration-settings.js

+ 24 - 13
packages/app/src/server/routes/apiv3/slack-integration-settings.js

@@ -54,8 +54,7 @@ module.exports = (crowi) => {
   const adminRequired = require('../../middlewares/admin-required')(crowi);
   const adminRequired = require('../../middlewares/admin-required')(crowi);
   const csrf = require('../../middlewares/csrf')(crowi);
   const csrf = require('../../middlewares/csrf')(crowi);
   const apiV3FormValidator = require('../../middlewares/apiv3-form-validator')(crowi);
   const apiV3FormValidator = require('../../middlewares/apiv3-form-validator')(crowi);
-
-  const SlackAppIntegration = mongoose.model('SlackAppIntegration');
+  const SlackAppIntegration = crowi.model('SlackAppIntegration');
 
 
   const validator = {
   const validator = {
     botType: [
     botType: [
@@ -389,6 +388,13 @@ module.exports = (crowi) => {
       const initialSupportedCommandsForBroadcastUse = new Map();
       const initialSupportedCommandsForBroadcastUse = new Map();
       const initialSupportedCommandsForSingleUse = new Map();
       const initialSupportedCommandsForSingleUse = new Map();
 
 
+      defaultSupportedCommandsNameForBroadcastUse.forEach((commandName) => {
+        initialSupportedCommandsForBroadcastUse.set(commandName, true);
+      });
+      defaultSupportedCommandsNameForSingleUse.forEach((commandName) => {
+        initialSupportedCommandsForSingleUse.set(commandName, true);
+      });
+
       const slackAppTokens = await SlackAppIntegration.create({
       const slackAppTokens = await SlackAppIntegration.create({
         tokenGtoP,
         tokenGtoP,
         tokenPtoG,
         tokenPtoG,
@@ -418,7 +424,6 @@ module.exports = (crowi) => {
    *            description: Succeeded to delete access tokens for slack
    *            description: Succeeded to delete access tokens for slack
    */
    */
   router.delete('/slack-app-integrations/:id', validator.deleteIntegration, apiV3FormValidator, async(req, res) => {
   router.delete('/slack-app-integrations/:id', validator.deleteIntegration, apiV3FormValidator, async(req, res) => {
-    const SlackAppIntegration = mongoose.model('SlackAppIntegration');
     const { id } = req.params;
     const { id } = req.params;
 
 
     try {
     try {
@@ -547,21 +552,25 @@ module.exports = (crowi) => {
    *            description: Succeeded to update supported commands
    *            description: Succeeded to update supported commands
    */
    */
   // eslint-disable-next-line max-len
   // eslint-disable-next-line max-len
-  router.put('/slack-app-integrations/:id/supported-commands', loginRequiredStrictly, adminRequired, csrf, validator.updateSupportedCommands, apiV3FormValidator, async(req, res) => {
-    const { supportedCommandsForBroadcastUse, supportedCommandsForSingleUse } = req.body;
+  router.put('/:id/supported-commands', loginRequiredStrictly, adminRequired, csrf, validator.updateSupportedCommands, apiV3FormValidator, async(req, res) => {
+    const { permissionsForBroadcastUseCommands, permissionsForSingleUseCommands } = req.body;
     const { id } = req.params;
     const { id } = req.params;
 
 
+    console.log(permissionsForBroadcastUseCommands);
+
     const updatePermissionsForBroadcastUseCommands = new Map();
     const updatePermissionsForBroadcastUseCommands = new Map();
     const updatePermissionsForSingleUseCommands = new Map();
     const updatePermissionsForSingleUseCommands = new Map();
-    supportedCommandsForBroadcastUse.forEach((commandName) => {
-      updatePermissionsForBroadcastUseCommands.set(commandName, true);
-    });
-    supportedCommandsForSingleUse.forEach((commandName) => {
-      updatePermissionsForSingleUseCommands.set(commandName, true);
-    });
+    // console.log(updatePermissionsForBroadcastUseCommands, 566);
 
 
-    try {
+    for (const [key, value] of Object.entries(permissionsForBroadcastUseCommands)) {
+      updatePermissionsForBroadcastUseCommands.set(key, value);
+    }
+
+    for (const [key, value] of Object.entries(permissionsForSingleUseCommands)) {
+      updatePermissionsForSingleUseCommands.set(key, value);
+    }
 
 
+    try {
       const slackAppIntegration = await SlackAppIntegration.findByIdAndUpdate(
       const slackAppIntegration = await SlackAppIntegration.findByIdAndUpdate(
         id,
         id,
         {
         {
@@ -571,6 +580,8 @@ module.exports = (crowi) => {
         { new: true },
         { new: true },
       );
       );
 
 
+      console.log(slackAppIntegration, 596);
+
       await requestToProxyServer(
       await requestToProxyServer(
         slackAppIntegration.tokenGtoP,
         slackAppIntegration.tokenGtoP,
         'put',
         'put',
@@ -581,7 +592,7 @@ module.exports = (crowi) => {
         },
         },
       );
       );
 
 
-      return res.apiv3({ slackAppIntegration });
+      return res.apiv3({});
     }
     }
     catch (error) {
     catch (error) {
       const msg = `Error occured in updating settings. Cause: ${error.message}`;
       const msg = `Error occured in updating settings. Cause: ${error.message}`;