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

mail notification with six trigger

yusuketk 7 лет назад
Родитель
Сommit
9ff65ce733

+ 1 - 0
lib/locales/en-US/notifications/comment.txt

@@ -0,0 +1 @@
+comment

+ 1 - 0
lib/locales/en-US/notifications/pageCreate.txt

@@ -0,0 +1 @@
+create

+ 1 - 0
lib/locales/en-US/notifications/pageDelete.txt

@@ -0,0 +1 @@
+delete

+ 1 - 0
lib/locales/en-US/notifications/pageEdit.txt

@@ -0,0 +1 @@
+edit

+ 1 - 0
lib/locales/en-US/notifications/pageLike.txt

@@ -0,0 +1 @@
+like

+ 1 - 0
lib/locales/en-US/notifications/pageMove.txt

@@ -0,0 +1 @@
+move

+ 1 - 0
lib/routes/comment.js

@@ -103,6 +103,7 @@ module.exports = function(crowi, app) {
     }
     }
     // NOTIFICATION: send comment notification here
     // NOTIFICATION: send comment notification here
     // notification.sendCommentNotification(comment, path);
     // notification.sendCommentNotification(comment, path);
+    notification.sendCommentNotification(comment, path);
   };
   };
 
 
   /**
   /**

+ 21 - 17
lib/routes/page.js

@@ -715,11 +715,12 @@ module.exports = function(crowi, app) {
       else {
       else {
         // new page
         // new page
         updateOrCreate = 'create';
         updateOrCreate = 'create';
-        return Page.create(path, body, req.user, { grant, grantUserGroupId });
-        // .then((page) => {
-        //   // NOTIFICATION: send page create notification here
-        //   notification.notifyPageCreate(page);
-        // })
+        return Page.create(path, body, req.user, { grant, grantUserGroupId })
+        .then((page) => {
+          // NOTIFICATION: send page create notification here
+          notification.notifyPageCreate(page);
+          return page;
+        });
       }
       }
     }).then(function(data) {
     }).then(function(data) {
       // data is a saved page data with revision.
       // data is a saved page data with revision.
@@ -1007,11 +1008,12 @@ module.exports = function(crowi, app) {
     }).catch(function(err) {
     }).catch(function(err) {
       debug('Like failed', err);
       debug('Like failed', err);
       return res.json(ApiResponse.error({}));
       return res.json(ApiResponse.error({}));
+    })
+    .then((page) => {
+      // NOTIFICATION: send page like notification here
+      notification.notifyPageLike(page, req.user);
+      return page;
     });
     });
-    // .then(() => {
-    //   // NOTIFICATION: send page like notification here
-    //   notification.sendPageLikeNotification(page);
-    // })
   };
   };
 
 
   /**
   /**
@@ -1116,11 +1118,12 @@ module.exports = function(crowi, app) {
     }).catch(function(err) {
     }).catch(function(err) {
       debug('Error occured while get setting', err, err.stack);
       debug('Error occured while get setting', err, err.stack);
       return res.json(ApiResponse.error('Failed to delete page.'));
       return res.json(ApiResponse.error('Failed to delete page.'));
+    })
+    .then((page) => {
+      // NOTIFICATION: send page delete notification here
+      notification.notifyPageCreate(page);
+      return page;
     });
     });
-    // .then(() => {
-    //   // NOTIFICATION: send page delete notification here
-    //   notification.sendPageDeleteNotification(page);
-    // })
   };
   };
 
 
   /**
   /**
@@ -1213,11 +1216,12 @@ module.exports = function(crowi, app) {
       })
       })
       .catch(function(err) {
       .catch(function(err) {
         return res.json(ApiResponse.error('Failed to update page.'));
         return res.json(ApiResponse.error('Failed to update page.'));
+      })
+      .then((page) => {
+        // NOTIFICATION: send page move notification here
+        notification.notifyPageMove(page, req.user);
+        return page;
       });
       });
-      // .then(() => {
-      //   // NOTIFICATION: send page move notification here
-      //   notification.sendPageMoveNotification(page);
-      // })
     });
     });
   };
   };
 
 

+ 20 - 15
lib/service/global-notification.js

@@ -10,7 +10,7 @@ const testNotifyData = [
     "triggerEvents": ["comment, pageCreate"],
     "triggerEvents": ["comment, pageCreate"],
     "__t": "mail",
     "__t": "mail",
     "triggerPath": "/*",
     "triggerPath": "/*",
-    "toEmail": "email@email.com",
+    "toEmail": "takky.yunama71@gmail.com",
     "__v": 0
     "__v": 0
   },
   },
   {
   {
@@ -67,12 +67,13 @@ class GlobalNotification {
    * @param {obejct} page
    * @param {obejct} page
    */
    */
   notifyPageCreate(page) {
   notifyPageCreate(page) {
-    const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageCreate');
+    // const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageCreate');
+    const notifications = testNotifyData;
     const lang = 'en-US'; //FIXME
     const lang = 'en-US'; //FIXME
     const option = {
     const option = {
       mail: {
       mail: {
         subject: `#pageCreate - ${page.creator.username} created ${page.path}`,
         subject: `#pageCreate - ${page.creator.username} created ${page.path}`,
-        template: path.join(this.crowi.localeDir, lang, 'notifications/pageCreate.txt'),
+        template: `../../locales/${lang}/notifications/pageCreate.txt`,
         vars: {}
         vars: {}
       },
       },
       slack: {},
       slack: {},
@@ -108,12 +109,13 @@ class GlobalNotification {
    * @param {obejct} page
    * @param {obejct} page
    */
    */
   notifyPageDelete(page) {
   notifyPageDelete(page) {
-    const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageDelete');
+    // const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageDelete');
+    const notifications = testNotifyData;
     const lang = 'en-US'; //FIXME
     const lang = 'en-US'; //FIXME
     const option = {
     const option = {
       mail: {
       mail: {
         subject: `#pageDelete - ${page.creator.username} deleted ${page.path}`,  //FIXME
         subject: `#pageDelete - ${page.creator.username} deleted ${page.path}`,  //FIXME
-        template: path.join(this.crowi.localeDir, lang, 'notifications/pageDelete.txt'),
+        template: `../../locales/${lang}/notifications/pageDelete.txt`,
         vars: {}
         vars: {}
       },
       },
       slack: {},
       slack: {},
@@ -127,13 +129,14 @@ class GlobalNotification {
    * @memberof GlobalNotification
    * @memberof GlobalNotification
    * @param {obejct} page
    * @param {obejct} page
    */
    */
-  notifyPageMove(page) {
-    const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageMove');
+  notifyPageMove(page, user) {
+    // const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageMove');
+    const notifications = testNotifyData;
     const lang = 'en-US'; //FIXME
     const lang = 'en-US'; //FIXME
     const option = {
     const option = {
       mail: {
       mail: {
-        subject: `#pageMove - ${page.creator.username} moved ${page.path} to ${page.path}`, //FIXME
-        template: path.join(this.crowi.localeDir, lang, 'notifications/pageMove.txt'),
+        subject: `#pageMove - ${user.username} moved ${page.path} to ${page.path}`, //FIXME
+        template: `../../locales/${lang}/notifications/pageMove.txt`,
         vars: {}
         vars: {}
       },
       },
       slack: {},
       slack: {},
@@ -147,13 +150,14 @@ class GlobalNotification {
    * @memberof GlobalNotification
    * @memberof GlobalNotification
    * @param {obejct} page
    * @param {obejct} page
    */
    */
-  notifyPageLike(page) {
-    const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageLike');
+  notifyPageLike(page, user) {
+    // const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageLike');
+    const notifications = testNotifyData;
     const lang = 'en-US'; //FIXME
     const lang = 'en-US'; //FIXME
     const option = {
     const option = {
       mail: {
       mail: {
-        subject: `#pageLike - ${page.creator.username} liked ${page.path}`,
-        template: path.join(this.crowi.localeDir, lang, 'notifications/pageLike.txt'),
+        subject: `#pageLike - ${user.username} liked ${page.path}`,
+        template: `../../locales/${lang}/notifications/pageLike.txt`,
         vars: {}
         vars: {}
       },
       },
       slack: {},
       slack: {},
@@ -169,12 +173,13 @@ class GlobalNotification {
    * @param {obejct} comment
    * @param {obejct} comment
    */
    */
   notifyComment(comment, path) {
   notifyComment(comment, path) {
-    const notifications = Notification.findSettingByPathAndEvent(path, 'comment');
+    // const notifications = Notification.findSettingByPathAndEvent(path, 'comment');
+    const notifications = testNotifyData;
     const lang = 'en-US'; //FIXME
     const lang = 'en-US'; //FIXME
     const option = {
     const option = {
       mail: {
       mail: {
         subject: `#comment - ${comment.creator.username} commented on ${path}`,
         subject: `#comment - ${comment.creator.username} commented on ${path}`,
-        template: path.join(this.crowi.localeDir, lang, 'notifications/comment.txt'),
+        template: `../../locales/${lang}/notifications/comment.txt`,
         vars: {}
         vars: {}
       },
       },
       slack: {},
       slack: {},