| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- const debug = require('debug')('growi:service:GlobalNotification');
- const Notification = require('../models/global-notification-setting');
- const mailer = require('../util/mailer');
- /**
- * the service class of GlobalNotificationSetting
- */
- class GlobalNotification {
- constructor(crowi) {
- this.crowi = crowi;
- this.config = crowi.getConfig();
- }
- mailNotify(notification, option) {
- mailer.send(Object.assign(option, {to: notification.notifyTo.toEmail}));
- }
- /**
- * send notification at page creation
- * @memberof GlobalNotification
- * @param {obejct} page
- */
- sendPageCreateNotification(page) {
- const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageCreate');
- const mailNotifications = notifications.filter(notification => notification.notifyTo.type === 'mail');
- const option = {
- subject: `#pageCreate - ${page.creator.username} created ${page.path}`,
- template: 'notification/pageCreate.txt',
- vars: {}
- };
- mailNotifications.forEach(notification => {
- this.mailNotify(notification, option);
- });
- }
- /**
- * send notification at page edit
- * @memberof GlobalNotification
- * @param {obejct} page
- */
- sendPageEditNotification(page) {
- const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageEdit');
- const mailNotifications = notifications.filter(notification => notification.notifyTo.type === 'mail');
- const option = {
- subject: `#pageEdit - ${page.creator.username} edited ${page.path}`,
- template: 'notification/pageEdit.txt',
- vars: {}
- };
- mailNotifications.forEach(notification => {
- this.mailNotify(notification, option);
- });
- }
- /**
- * send notification at page deletion
- * @memberof GlobalNotification
- * @param {obejct} page
- */
- sendPageDeleteNotification(page) {
- const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageDelete');
- const mailNotifications = notifications.filter(notification => notification.notifyTo.type === 'mail');
- const option = {
- subject: `#pageDelete - ${page.creator.username} deleted ${page.path}`, //FIXME
- template: 'notification/pageDelete.txt',
- vars: {}
- };
- mailNotifications.forEach(notification => {
- this.mailNotify(notification, option);
- });
- }
- /**
- * send notification at page move
- * @memberof GlobalNotification
- * @param {obejct} page
- */
- sendPageMoveNotification(page) {
- const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageMove');
- const mailNotifications = notifications.filter(notification => notification.notifyTo.type === 'mail');
- const option = {
- subject: `#pageMove - ${page.creator.username} moved ${page.path} to ${page.path}`, //FIXME
- template: 'notification/pageMove.txt',
- vars: {}
- };
- mailNotifications.forEach(notification => {
- this.mailNotify(notification, option);
- });
- }
- /**
- * send notification at page like
- * @memberof GlobalNotification
- * @param {obejct} page
- */
- sendPageLikeNotification(page) {
- 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,
- subject: `#pageLike - ${page.creator.username} liked ${page.path}`,
- template: 'notification/pageLike.txt',
- vars: {}
- });
- });
- }
- /**
- * send notification at page comment
- * @memberof GlobalNotification
- * @param {obejct} page
- * @param {obejct} comment
- */
- sendCommentNotification(comment, path) {
- const notifications = Notification.findSettingByPathAndEvent(path, 'comment');
- const mailNotifications = notifications.filter(notification => notification.notifyTo.type === 'mail');
- mailNotifications.forEach(notification => {
- mailer.send({
- to: notification.notifyTo.toEmail,
- subject: `#comment - ${comment.creator.username} commented on ${path}`,
- template: 'notification/comment.txt',
- vars: {}
- });
- });
- }
- }
- module.exports = GlobalNotification;
|