|
@@ -1,5 +1,5 @@
|
|
|
const debug = require('debug')('growi:service:GlobalNotification');
|
|
const debug = require('debug')('growi:service:GlobalNotification');
|
|
|
-const Notification = require('../models/global-notification-setting');
|
|
|
|
|
|
|
+const Notification = require('../models/GlobalNotificationSetting');
|
|
|
const mailer = require('../util/mailer');
|
|
const mailer = require('../util/mailer');
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -12,8 +12,23 @@ class GlobalNotification {
|
|
|
this.config = crowi.getConfig();
|
|
this.config = crowi.getConfig();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- mailNotify(notification, option) {
|
|
|
|
|
- mailer.send(Object.assign(option, {to: notification.notifyTo.toEmail}));
|
|
|
|
|
|
|
+ notifyByMail(notification, mailOption) {
|
|
|
|
|
+ mailer.send(Object.assign(mailOption, {to: notification.toEmail}));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ notifyBySlack(notification, slackOption) {
|
|
|
|
|
+ // send slack notification here
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sendNotification(notifications, option) {
|
|
|
|
|
+ notifications.forEach(notification => {
|
|
|
|
|
+ if (notification.__t === 'mail') {
|
|
|
|
|
+ this.notifyByMail(notification, option.mail);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (notification.__t === 'slack') {
|
|
|
|
|
+ this.notifyBySlack(notification, option.slack);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -21,17 +36,18 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
* @memberof GlobalNotification
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
*/
|
|
*/
|
|
|
- sendPageCreateNotification(page) {
|
|
|
|
|
|
|
+ notifyPageCreate(page) {
|
|
|
const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageCreate');
|
|
const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageCreate');
|
|
|
- const mailNotifications = notifications.filter(notification => notification.notifyTo.type === 'mail');
|
|
|
|
|
const option = {
|
|
const option = {
|
|
|
- subject: `#pageCreate - ${page.creator.username} created ${page.path}`,
|
|
|
|
|
- template: 'notification/pageCreate.txt',
|
|
|
|
|
- vars: {}
|
|
|
|
|
|
|
+ mail: {
|
|
|
|
|
+ subject: `#pageCreate - ${page.creator.username} created ${page.path}`,
|
|
|
|
|
+ template: 'notification/pageCreate.txt',
|
|
|
|
|
+ vars: {}
|
|
|
|
|
+ },
|
|
|
|
|
+ slack: {},
|
|
|
};
|
|
};
|
|
|
- mailNotifications.forEach(notification => {
|
|
|
|
|
- this.mailNotify(notification, option);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ this.sendNotification(notifications, option);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -39,17 +55,18 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
* @memberof GlobalNotification
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
*/
|
|
*/
|
|
|
- sendPageEditNotification(page) {
|
|
|
|
|
|
|
+ notifyPageEdit(page) {
|
|
|
const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageEdit');
|
|
const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageEdit');
|
|
|
- const mailNotifications = notifications.filter(notification => notification.notifyTo.type === 'mail');
|
|
|
|
|
const option = {
|
|
const option = {
|
|
|
- subject: `#pageEdit - ${page.creator.username} edited ${page.path}`,
|
|
|
|
|
- template: 'notification/pageEdit.txt',
|
|
|
|
|
- vars: {}
|
|
|
|
|
|
|
+ mail: {
|
|
|
|
|
+ subject: `#pageEdit - ${page.creator.username} edited ${page.path}`,
|
|
|
|
|
+ template: 'notification/pageEdit.txt',
|
|
|
|
|
+ vars: {}
|
|
|
|
|
+ },
|
|
|
|
|
+ slack: {},
|
|
|
};
|
|
};
|
|
|
- mailNotifications.forEach(notification => {
|
|
|
|
|
- this.mailNotify(notification, option);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ this.sendNotification(notifications, option);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -57,17 +74,18 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
* @memberof GlobalNotification
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
*/
|
|
*/
|
|
|
- sendPageDeleteNotification(page) {
|
|
|
|
|
|
|
+ notifyPageDelete(page) {
|
|
|
const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageDelete');
|
|
const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageDelete');
|
|
|
- const mailNotifications = notifications.filter(notification => notification.notifyTo.type === 'mail');
|
|
|
|
|
const option = {
|
|
const option = {
|
|
|
- subject: `#pageDelete - ${page.creator.username} deleted ${page.path}`, //FIXME
|
|
|
|
|
- template: 'notification/pageDelete.txt',
|
|
|
|
|
- vars: {}
|
|
|
|
|
|
|
+ mail: {
|
|
|
|
|
+ subject: `#pageDelete - ${page.creator.username} deleted ${page.path}`, //FIXME
|
|
|
|
|
+ template: 'notification/pageDelete.txt',
|
|
|
|
|
+ vars: {}
|
|
|
|
|
+ },
|
|
|
|
|
+ slack: {},
|
|
|
};
|
|
};
|
|
|
- mailNotifications.forEach(notification => {
|
|
|
|
|
- this.mailNotify(notification, option);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ this.sendNotification(notifications, option);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -75,17 +93,18 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
* @memberof GlobalNotification
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
*/
|
|
*/
|
|
|
- sendPageMoveNotification(page) {
|
|
|
|
|
|
|
+ notifyPageMove(page) {
|
|
|
const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageMove');
|
|
const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageMove');
|
|
|
- const mailNotifications = notifications.filter(notification => notification.notifyTo.type === 'mail');
|
|
|
|
|
const option = {
|
|
const option = {
|
|
|
- subject: `#pageMove - ${page.creator.username} moved ${page.path} to ${page.path}`, //FIXME
|
|
|
|
|
- template: 'notification/pageMove.txt',
|
|
|
|
|
- vars: {}
|
|
|
|
|
|
|
+ mail: {
|
|
|
|
|
+ subject: `#pageMove - ${page.creator.username} moved ${page.path} to ${page.path}`, //FIXME
|
|
|
|
|
+ template: 'notification/pageMove.txt',
|
|
|
|
|
+ vars: {}
|
|
|
|
|
+ },
|
|
|
|
|
+ slack: {},
|
|
|
};
|
|
};
|
|
|
- mailNotifications.forEach(notification => {
|
|
|
|
|
- this.mailNotify(notification, option);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ this.sendNotification(notifications, option);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -93,17 +112,18 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
* @memberof GlobalNotification
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
*/
|
|
*/
|
|
|
- sendPageLikeNotification(page) {
|
|
|
|
|
|
|
+ notifyPageLike(page) {
|
|
|
const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageLike');
|
|
const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageLike');
|
|
|
- const mailNotifications = notifications.filter(notification => notification.notifyTo.type === 'mail');
|
|
|
|
|
- mailNotifications.forEach(notification => {
|
|
|
|
|
- mailer.send({
|
|
|
|
|
- to: notification.notifyTo.toEmail,
|
|
|
|
|
|
|
+ const option = {
|
|
|
|
|
+ mail: {
|
|
|
subject: `#pageLike - ${page.creator.username} liked ${page.path}`,
|
|
subject: `#pageLike - ${page.creator.username} liked ${page.path}`,
|
|
|
template: 'notification/pageLike.txt',
|
|
template: 'notification/pageLike.txt',
|
|
|
vars: {}
|
|
vars: {}
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ slack: {},
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ this.sendNotification(notifications, option);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -112,17 +132,18 @@ class GlobalNotification {
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
* @param {obejct} comment
|
|
* @param {obejct} comment
|
|
|
*/
|
|
*/
|
|
|
- sendCommentNotification(comment, path) {
|
|
|
|
|
|
|
+ notifyComment(comment, path) {
|
|
|
const notifications = Notification.findSettingByPathAndEvent(path, 'comment');
|
|
const notifications = Notification.findSettingByPathAndEvent(path, 'comment');
|
|
|
- const mailNotifications = notifications.filter(notification => notification.notifyTo.type === 'mail');
|
|
|
|
|
- mailNotifications.forEach(notification => {
|
|
|
|
|
- mailer.send({
|
|
|
|
|
- to: notification.notifyTo.toEmail,
|
|
|
|
|
|
|
+ const option = {
|
|
|
|
|
+ mail: {
|
|
|
subject: `#comment - ${comment.creator.username} commented on ${path}`,
|
|
subject: `#comment - ${comment.creator.username} commented on ${path}`,
|
|
|
template: 'notification/comment.txt',
|
|
template: 'notification/comment.txt',
|
|
|
vars: {}
|
|
vars: {}
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ slack: {},
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ this.sendNotification(notifications, option);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|