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

complete pageCreate mail sent and other templates

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

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

@@ -1 +1,5 @@
-comment
+{{ username }} commented on {{ path }}.
+
+----------------------
+
+Growi: {{ appTitle }}

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

@@ -1 +1,5 @@
-create
+A new page was created at {{ path }} by {{ username }}.
+
+----------------------
+
+Growi: {{ appTitle }}

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

@@ -1 +1,5 @@
-delete
+{{ username }} deleted the page  {{ path }}.
+
+----------------------
+
+Growi: {{ appTitle }}

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

@@ -1 +1,5 @@
-edit
+{{ username }} edited the page {{ path }}.
+
+----------------------
+
+Growi: {{ appTitle }}

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

@@ -1 +1,5 @@
-like
+{{ username }} liked the page {{ path }}.
+
+----------------------
+
+Growi: {{ appTitle }}

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

@@ -1 +1,5 @@
-move
+{{ username }} renamed the page {{ oldPath }} to {{ newPath }}.
+
+----------------------
+
+Growi: {{ appTitle }}

+ 1 - 1
lib/routes/page.js

@@ -1121,7 +1121,7 @@ module.exports = function(crowi, app) {
     })
     .then((page) => {
       // NOTIFICATION: send page delete notification here
-      notification.notifyPageCreate(page);
+      notification.notifyPageDelete(page);
       return page;
     });
   };

+ 24 - 55
lib/service/global-notification.js

@@ -1,49 +1,20 @@
 const debug = require('debug')('growi:service:GlobalNotification');
-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
  */
-class GlobalNotification {
+class GlobalNotificationService {
 
   constructor(crowi) {
     this.crowi = crowi;
     this.config = crowi.getConfig();
+    this.mailer = crowi.getMailer();
+    this.GlobalNotification = crowi.model('GlobalNotificationSetting');
+    this.Config = crowi.model('Config');
+    this.appTitle = this.Config.appTitle(this.config);
   }
 
   notifyByMail(notification, mailOption) {
-    const crowi = this.crowi;
-    const mailer = crowi.getMailer();
-
-    mailer.send(Object.assign(mailOption, {to: notification.toEmail}),
-      function(err, s) {
-        debug('completed to send email: ', err, s);
-        next();
-      }
-    );
+    this.mailer.send(Object.assign(mailOption, {to: notification.toEmail}));
   }
 
   notifyBySlack(notification, slackOption) {
@@ -66,15 +37,18 @@ class GlobalNotification {
    * @memberof GlobalNotification
    * @param {obejct} page
    */
-  notifyPageCreate(page) {
-    // const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageCreate');
-    const notifications = testNotifyData;
+  async notifyPageCreate(page) {
+    const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(page.path, 'pageCreate');
     const lang = 'en-US'; //FIXME
     const option = {
       mail: {
         subject: `#pageCreate - ${page.creator.username} created ${page.path}`,
         template: `../../locales/${lang}/notifications/pageCreate.txt`,
-        vars: {}
+        vars: {
+          appTitle: this.appTitle,
+          path: page.path,
+          username: page.creator.username,
+        }
       },
       slack: {},
     };
@@ -87,9 +61,8 @@ class GlobalNotification {
    * @memberof GlobalNotification
    * @param {obejct} page
    */
-  notifyPageEdit(page) {
-    // const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageEdit');
-    const notifications = testNotifyData;
+  async notifyPageEdit(page) {
+    const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(page.path, 'pageEdit');
     const lang = 'en-US'; //FIXME
     const option = {
       mail: {
@@ -108,9 +81,8 @@ class GlobalNotification {
    * @memberof GlobalNotification
    * @param {obejct} page
    */
-  notifyPageDelete(page) {
-    // const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageDelete');
-    const notifications = testNotifyData;
+  async notifyPageDelete(page) {
+    const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(page.path, 'pageDelete');
     const lang = 'en-US'; //FIXME
     const option = {
       mail: {
@@ -129,9 +101,8 @@ class GlobalNotification {
    * @memberof GlobalNotification
    * @param {obejct} page
    */
-  notifyPageMove(page, user) {
-    // const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageMove');
-    const notifications = testNotifyData;
+  async notifyPageMove(page, user) {
+    const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(page.path, 'pageMove');
     const lang = 'en-US'; //FIXME
     const option = {
       mail: {
@@ -150,9 +121,8 @@ class GlobalNotification {
    * @memberof GlobalNotification
    * @param {obejct} page
    */
-  notifyPageLike(page, user) {
-    // const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageLike');
-    const notifications = testNotifyData;
+  async notifyPageLike(page, user) {
+    const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(page.path, 'pageLike');
     const lang = 'en-US'; //FIXME
     const option = {
       mail: {
@@ -172,9 +142,8 @@ class GlobalNotification {
    * @param {obejct} page
    * @param {obejct} comment
    */
-  notifyComment(comment, path) {
-    // const notifications = Notification.findSettingByPathAndEvent(path, 'comment');
-    const notifications = testNotifyData;
+  async notifyComment(comment, path) {
+    const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(path, 'comment');
     const lang = 'en-US'; //FIXME
     const option = {
       mail: {
@@ -189,4 +158,4 @@ class GlobalNotification {
   }
 }
 
-module.exports = GlobalNotification;
+module.exports = GlobalNotificationService;