sou 7 лет назад
Родитель
Сommit
d32f65e640

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

@@ -2,4 +2,8 @@
 
 ----------------------
 
+{{ comment }}
+
+----------------------
+
 Growi: {{ appTitle }}

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

@@ -1,4 +1,4 @@
-A new page was created at {{ path }} by {{ username }}.
+{{ username }} created a new page under {{ path }}.
 
 ----------------------
 

+ 1 - 1
lib/models/page.js

@@ -1047,7 +1047,7 @@ module.exports = function(crowi) {
     var newRevision = await Revision.prepareRevision(pageData, body, user);
 
     const revision = await Page.pushRevision(pageData, newRevision, user);
-    const savedPage = await Page.findPageByPath(revision.path).populate('revision');
+    const savedPage = await Page.findPageByPath(revision.path).populate('revision').populate('creator');
     if (grant != null) {
       const grantData = await Page.updateGrant(savedPage, grant, user, grantUserGroupId);
       debug('Page grant update:', grantData);

+ 7 - 5
lib/routes/comment.js

@@ -7,7 +7,8 @@ module.exports = function(crowi, app) {
     , User = crowi.model('User')
     , Page = crowi.model('Page')
     , ApiResponse = require('../util/apiResponse')
-    , notification = require('../service/global-notification')
+    , globalNotification = require('../service/global-notification')
+    , notification = new globalNotification(crowi)
     , actions = {}
     , api = {};
 
@@ -80,10 +81,14 @@ module.exports = function(crowi, app) {
 
     res.json(ApiResponse.success({comment: createdComment}));
 
+    const path = page.path;
+
+    // global notification
+    notification.notifyComment(createdComment, path);
+
     // slack notification
     if (slackNotificationForm.isSlackEnabled) {
       const user = await User.findUserByUsername(req.user.username);
-      const path = page.path;
       const channels = slackNotificationForm.slackChannels;
 
       if (channels) {
@@ -101,9 +106,6 @@ module.exports = function(crowi, app) {
           });
       }
     }
-    // NOTIFICATION: send comment notification here
-    // notification.sendCommentNotification(comment, path);
-    notification.sendCommentNotification(comment, path);
   };
 
   /**

+ 11 - 11
lib/routes/page.js

@@ -1002,17 +1002,17 @@ module.exports = function(crowi, app) {
     Page.findPageByIdAndGrantedUser(id, req.user)
     .then(function(pageData) {
       return pageData.like(req.user);
-    }).then(function(data) {
-      var result = {page: data};
-      return res.json(ApiResponse.success(result));
+    }).then(function(page) {
+      var result = {page: page};
+      res.json(ApiResponse.success(result));
+      return page;
     }).catch(function(err) {
       debug('Like failed', err);
       return res.json(ApiResponse.error({}));
     })
     .then((page) => {
       // NOTIFICATION: send page like notification here
-      notification.notifyPageLike(page, req.user);
-      return page;
+      return notification.notifyPageLike(page, req.user);
     });
   };
 
@@ -1114,15 +1114,15 @@ module.exports = function(crowi, app) {
       var result = {};
       result.page = data;
 
-      return res.json(ApiResponse.success(result));
+      res.json(ApiResponse.success(result));
+      return data;
     }).catch(function(err) {
       debug('Error occured while get setting', err, err.stack);
       return res.json(ApiResponse.error('Failed to delete page.'));
     })
     .then((page) => {
       // NOTIFICATION: send page delete notification here
-      notification.notifyPageDelete(page);
-      return page;
+      return notification.notifyPageDelete(page);
     });
   };
 
@@ -1217,12 +1217,12 @@ module.exports = function(crowi, app) {
       .catch(function(err) {
         return res.json(ApiResponse.error('Failed to update page.'));
       })
-      .then((page) => {
+      .then(() => {
         // NOTIFICATION: send page move notification here
-        notification.notifyPageMove(page, req.user);
-        return page;
+        notification.notifyPageMove(page, req.body.path, req.user);
       });
     });
+
   };
 
   /**

+ 31 - 7
lib/service/global-notification.js

@@ -9,6 +9,7 @@ class GlobalNotificationService {
     this.config = crowi.getConfig();
     this.mailer = crowi.getMailer();
     this.GlobalNotification = crowi.model('GlobalNotificationSetting');
+    this.User = crowi.model('User');
     this.Config = crowi.model('Config');
     this.appTitle = this.Config.appTitle(this.config);
   }
@@ -68,7 +69,11 @@ class GlobalNotificationService {
       mail: {
         subject: `#pageEdit - ${page.creator.username} edited ${page.path}`,
         template: `../../locales/${lang}/notifications/pageEdit.txt`,
-        vars: {}
+        vars: {
+          appTitle: this.appTitle,
+          path: page.path,
+          username: page.creator.username,
+        }
       },
       slack: {},
     };
@@ -88,7 +93,11 @@ class GlobalNotificationService {
       mail: {
         subject: `#pageDelete - ${page.creator.username} deleted ${page.path}`,  //FIXME
         template: `../../locales/${lang}/notifications/pageDelete.txt`,
-        vars: {}
+        vars: {
+          appTitle: this.appTitle,
+          path: page.path,
+          username: page.creator.username,
+        }
       },
       slack: {},
     };
@@ -101,14 +110,19 @@ class GlobalNotificationService {
    * @memberof GlobalNotification
    * @param {obejct} page
    */
-  async notifyPageMove(page, user) {
+  async notifyPageMove(page, oldPagePath, user) {
     const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(page.path, 'pageMove');
     const lang = 'en-US'; //FIXME
     const option = {
       mail: {
         subject: `#pageMove - ${user.username} moved ${page.path} to ${page.path}`, //FIXME
         template: `../../locales/${lang}/notifications/pageMove.txt`,
-        vars: {}
+        vars: {
+          appTitle: this.appTitle,
+          oldPath: oldPagePath,
+          newPath: page.path,
+          username: user.username,
+        }
       },
       slack: {},
     };
@@ -128,7 +142,11 @@ class GlobalNotificationService {
       mail: {
         subject: `#pageLike - ${user.username} liked ${page.path}`,
         template: `../../locales/${lang}/notifications/pageLike.txt`,
-        vars: {}
+        vars: {
+          appTitle: this.appTitle,
+          path: page.path,
+          username: page.creator.username,
+        }
       },
       slack: {},
     };
@@ -145,11 +163,17 @@ class GlobalNotificationService {
   async notifyComment(comment, path) {
     const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(path, 'comment');
     const lang = 'en-US'; //FIXME
+    const user = await this.User.findOne({_id: comment.creator});
     const option = {
       mail: {
-        subject: `#comment - ${comment.creator.username} commented on ${path}`,
+        subject: `#comment - ${user.username} commented on ${path}`,
         template: `../../locales/${lang}/notifications/comment.txt`,
-        vars: {}
+        vars: {
+          appTitle: this.appTitle,
+          path: path,
+          username: user.username,
+          comment: comment.comment,
+        }
       },
       slack: {},
     };