itizawa 6 лет назад
Родитель
Сommit
f5304bbef4
1 измененных файлов с 14 добавлено и 2 удалено
  1. 14 2
      src/server/routes/apiv3/notification-setting.js

+ 14 - 2
src/server/routes/apiv3/notification-setting.js

@@ -21,6 +21,18 @@ const validator = {
     body('pathPattern').isString().trim(),
     body('channel').isString().trim(),
   ],
+  globalNotification: [
+    body('triggerPath').isString().trim().not()
+      .isEmpty(),
+    body('notifyToType').isString().trim().not()
+      .isEmpty(),
+    body('toEmail').trim().custom((value, { req }) => {
+      return (req.body.notifyToType === 'mail') ? (!!value && value.match(/.+@.+\..+/)) : true;
+    }),
+    body('slackChannels').trim().custom((value, { req }) => {
+      return (req.body.notifyToType === 'slack') ? !!value : true;
+    }),
+  ],
 };
 
 /**
@@ -194,7 +206,7 @@ module.exports = (crowi) => {
   });
 
   // TODO swagger
-  router.post('/global-notification', loginRequiredStrictly, adminRequired, csrf, async(req, res) => {
+  router.post('/global-notification', loginRequiredStrictly, adminRequired, csrf, validator.globalNotification, ApiV3FormValidator, async(req, res) => {
 
     const {
       notifyToType, toEmail, slackChannels, triggerPath, triggerEvents,
@@ -216,7 +228,7 @@ module.exports = (crowi) => {
     }
 
     notification.triggerPath = triggerPath;
-    notification.triggerEvents = triggerEvents;
+    notification.triggerEvents = triggerEvents || [];
     notification.save();
 
     return res.apiv3();