itizawa 6 лет назад
Родитель
Сommit
e8276fd0bf

+ 2 - 2
src/client/js/components/Admin/Notification/ManageGlobalNotification.jsx

@@ -80,8 +80,8 @@ class ManageGlobalNotification extends React.Component {
       await this.props.appContainer.apiv3.post('/notification-setting/global-notification', {
       await this.props.appContainer.apiv3.post('/notification-setting/global-notification', {
         triggerPath: this.state.triggerPath,
         triggerPath: this.state.triggerPath,
         notifyToType: this.state.notifyToType,
         notifyToType: this.state.notifyToType,
-        emailToSend: this.state.emailToSend,
-        slackChannelToSend: this.state.slackChannelToSend,
+        toEmail: this.state.emailToSend,
+        slackChannels: this.state.slackChannelToSend,
         triggerEvents: this.state.triggerEvents,
         triggerEvents: this.state.triggerEvents,
       });
       });
     }
     }

+ 28 - 19
src/server/routes/apiv3/notification-setting.js

@@ -66,6 +66,9 @@ module.exports = (crowi) => {
 
 
   const { ApiV3FormValidator } = crowi.middlewares;
   const { ApiV3FormValidator } = crowi.middlewares;
 
 
+  const GlobalNotificationMailSetting = crowi.models.GlobalNotificationMailSetting;
+  const GlobalNotificationSlackSetting = crowi.models.GlobalNotificationSlackSetting;
+
   /**
   /**
    * @swagger
    * @swagger
    *
    *
@@ -193,26 +196,32 @@ module.exports = (crowi) => {
   // TODO swagger
   // TODO swagger
   router.post('/global-notification', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
   router.post('/global-notification', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
 
 
-    // switch (form.notifyToType) {
-    //   case GlobalNotificationSetting.TYPE.MAIL:
-    //     setting = new GlobalNotificationMailSetting(crowi);
-    //     setting.toEmail = form.toEmail;
-    //     break;
-    //   case GlobalNotificationSetting.TYPE.SLACK:
-    //     setting = new GlobalNotificationSlackSetting(crowi);
-    //     setting.slackChannels = form.slackChannels;
-    //     break;
-    //   default:
-    //     logger.error('GlobalNotificationSetting Type Error: undefined type');
-    //     req.flash('errorMessage', 'Error occurred in creating a new global notification setting: undefined notification type');
-    //     return res.redirect('/admin/notification#global-notification');
-    // }
-
-    // setting.triggerPath = form.triggerPath;
-    // setting.triggerEvents = getNotificationEvents(form);
-    // setting.save();
-    return res.apiv3();
+    const {
+      notifyToType, toEmail, slackChannels, triggerPath, triggerEvents,
+    } = req.body;
+
+    let notification;
+
+    switch (notifyToType) {
+      case GlobalNotificationSetting.TYPE.MAIL:
+        notification = new GlobalNotificationMailSetting(crowi);
+        notification.toEmail = toEmail;
+        break;
+      case GlobalNotificationSetting.TYPE.SLACK:
+        notification = new GlobalNotificationSlackSetting(crowi);
+        notification.slackChannels = slackChannels;
+        break;
+      default:
+        logger.error('GlobalNotificationSetting Type Error: undefined type');
+        req.flash('errorMessage', 'Error occurred in creating a new global notification setting: undefined notification type');
+        return res.redirect('/admin/notification#global-notification');
+    }
 
 
+    notification.triggerPath = triggerPath;
+    notification.triggerEvents = triggerEvents;
+    notification.save();
+
+    return res.apiv3();
   });
   });
 
 
   /**
   /**