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

(wip) trigger method for notification

yusuketk 7 лет назад
Родитель
Сommit
c44842d7fa
2 измененных файлов с 34 добавлено и 8 удалено
  1. 11 7
      lib/routes/page.js
  2. 23 1
      lib/service/global-notification.js

+ 11 - 7
lib/routes/page.js

@@ -16,7 +16,8 @@ module.exports = function(crowi, app) {
     , pagePathUtil = require('../util/pagePathUtil')
     , swig = require('swig-templates')
     , getToday = require('../util/getToday')
-    , notification = require('../service/global-notification')
+    , globalNotification = require('../service/global-notification')
+    , notification = new globalNotification(crowi)
 
     , actions = {};
 
@@ -704,11 +705,14 @@ module.exports = function(crowi, app) {
 
       if (data) {
         previousRevision = data.revision;
-        return Page.updatePage(data, body, req.user, { grant, grantUserGroupId });
-        // .then(() => {
-        //   // NOTIFICATION: send page edit notification here
-        //   notification.sendPageEditNotification(page);
-        // })
+        return Page.updatePage(data, body, req.user, { grant, grantUserGroupId })
+        .then((page) => {
+          // NOTIFICATION: send page edit notification here
+          notification.notifyPageEdit(page);
+        })
+        .catch((err) => {
+          console.log('error');
+        });
       }
       else {
         // new page
@@ -716,7 +720,7 @@ module.exports = function(crowi, app) {
         return Page.create(path, body, req.user, { grant, grantUserGroupId });
         // .then((page) => {
         //   // NOTIFICATION: send page create notification here
-        //   notification.sendPageCreateNotification(page);
+        //   notification.notifyPageCreate(page);
         // })
       }
     }).then(function(data) {

+ 23 - 1
lib/service/global-notification.js

@@ -3,6 +3,27 @@ const path = require('path');
 const Notification = require('../models/GlobalNotificationSetting');
 const mailer = require('../util/mailer');
 
+const testNotifyData = [
+  {
+    "_id": "5b45ab384a702f4484010066",
+    "isEnabled": true,
+    "triggerEvents": ["comment, pageCreate"],
+    "__t": "mail",
+    "triggerPath": "/*",
+    "toEmail": "email@email.com",
+    "__v": 0
+  },
+  {
+    "_id": "5b45ab384a702f4484010067",
+    "isEnabled": true,
+    "triggerEvents": ["comment, pageCreate"],
+    "__t": "slack",
+    "triggerPath": "/*",
+    "slackChannels": "general, random",
+    "__v": 0
+  }
+];
+
 /**
  * the service class of GlobalNotificationSetting
  */
@@ -58,7 +79,8 @@ class GlobalNotification {
    * @param {obejct} page
    */
   notifyPageEdit(page) {
-    const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageEdit');
+    // const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageEdit');
+    const notifications = testNotifyData;
     const lang = 'en-US'; //FIXME
     const option = {
       mail: {