|
|
@@ -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;
|