|
|
@@ -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
|
|
|
*/
|
|
|
@@ -14,7 +35,15 @@ class GlobalNotification {
|
|
|
}
|
|
|
|
|
|
notifyByMail(notification, mailOption) {
|
|
|
- mailer.send(Object.assign(mailOption, {to: notification.toEmail}));
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
notifyBySlack(notification, slackOption) {
|
|
|
@@ -38,12 +67,13 @@ class GlobalNotification {
|
|
|
* @param {obejct} 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 option = {
|
|
|
mail: {
|
|
|
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: {}
|
|
|
},
|
|
|
slack: {},
|
|
|
@@ -58,12 +88,13 @@ 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: {
|
|
|
subject: `#pageEdit - ${page.creator.username} edited ${page.path}`,
|
|
|
- template: path.join(this.crowi.localeDir, lang, 'notifications/pageEdit.txt'),
|
|
|
+ template: `../../locales/${lang}/notifications/pageEdit.txt`,
|
|
|
vars: {}
|
|
|
},
|
|
|
slack: {},
|
|
|
@@ -78,12 +109,13 @@ class GlobalNotification {
|
|
|
* @param {obejct} 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 option = {
|
|
|
mail: {
|
|
|
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: {}
|
|
|
},
|
|
|
slack: {},
|
|
|
@@ -97,13 +129,14 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
|
* @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 option = {
|
|
|
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: {}
|
|
|
},
|
|
|
slack: {},
|
|
|
@@ -117,13 +150,14 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
|
* @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 option = {
|
|
|
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: {}
|
|
|
},
|
|
|
slack: {},
|
|
|
@@ -139,12 +173,13 @@ class GlobalNotification {
|
|
|
* @param {obejct} comment
|
|
|
*/
|
|
|
notifyComment(comment, path) {
|
|
|
- const notifications = Notification.findSettingByPathAndEvent(path, 'comment');
|
|
|
+ // const notifications = Notification.findSettingByPathAndEvent(path, 'comment');
|
|
|
+ const notifications = testNotifyData;
|
|
|
const lang = 'en-US'; //FIXME
|
|
|
const option = {
|
|
|
mail: {
|
|
|
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: {}
|
|
|
},
|
|
|
slack: {},
|