|
@@ -1,20 +1,21 @@
|
|
|
const debug = require('debug')('growi:service:GlobalNotification');
|
|
const debug = require('debug')('growi:service:GlobalNotification');
|
|
|
-const path = require('path');
|
|
|
|
|
-const Notification = require('../models/GlobalNotificationSetting');
|
|
|
|
|
-const mailer = require('../util/mailer');
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* the service class of GlobalNotificationSetting
|
|
* the service class of GlobalNotificationSetting
|
|
|
*/
|
|
*/
|
|
|
-class GlobalNotification {
|
|
|
|
|
|
|
+class GlobalNotificationService {
|
|
|
|
|
|
|
|
constructor(crowi) {
|
|
constructor(crowi) {
|
|
|
this.crowi = crowi;
|
|
this.crowi = crowi;
|
|
|
this.config = crowi.getConfig();
|
|
this.config = crowi.getConfig();
|
|
|
|
|
+ this.mailer = crowi.getMailer();
|
|
|
|
|
+ this.GlobalNotification = crowi.model('GlobalNotificationSetting');
|
|
|
|
|
+ this.User = crowi.model('User');
|
|
|
|
|
+ this.Config = crowi.model('Config');
|
|
|
|
|
+ this.appTitle = this.Config.appTitle(this.config);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
notifyByMail(notification, mailOption) {
|
|
notifyByMail(notification, mailOption) {
|
|
|
- mailer.send(Object.assign(mailOption, {to: notification.toEmail}));
|
|
|
|
|
|
|
+ this.mailer.send(Object.assign(mailOption, {to: notification.toEmail}));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
notifyBySlack(notification, slackOption) {
|
|
notifyBySlack(notification, slackOption) {
|
|
@@ -37,14 +38,18 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
* @memberof GlobalNotification
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
*/
|
|
*/
|
|
|
- notifyPageCreate(page) {
|
|
|
|
|
- const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageCreate');
|
|
|
|
|
|
|
+ async notifyPageCreate(page) {
|
|
|
|
|
+ const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(page.path, 'pageCreate');
|
|
|
const lang = 'en-US'; //FIXME
|
|
const lang = 'en-US'; //FIXME
|
|
|
const option = {
|
|
const option = {
|
|
|
mail: {
|
|
mail: {
|
|
|
subject: `#pageCreate - ${page.creator.username} created ${page.path}`,
|
|
subject: `#pageCreate - ${page.creator.username} created ${page.path}`,
|
|
|
- template: path.join(this.crowi.localeDir, lang, 'notifications/pageCreate.txt'),
|
|
|
|
|
- vars: {}
|
|
|
|
|
|
|
+ template: `../../locales/${lang}/notifications/pageCreate.txt`,
|
|
|
|
|
+ vars: {
|
|
|
|
|
+ appTitle: this.appTitle,
|
|
|
|
|
+ path: page.path,
|
|
|
|
|
+ username: page.creator.username,
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
slack: {},
|
|
slack: {},
|
|
|
};
|
|
};
|
|
@@ -57,14 +62,18 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
* @memberof GlobalNotification
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
*/
|
|
*/
|
|
|
- notifyPageEdit(page) {
|
|
|
|
|
- const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageEdit');
|
|
|
|
|
|
|
+ async notifyPageEdit(page) {
|
|
|
|
|
+ const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(page.path, 'pageEdit');
|
|
|
const lang = 'en-US'; //FIXME
|
|
const lang = 'en-US'; //FIXME
|
|
|
const option = {
|
|
const option = {
|
|
|
mail: {
|
|
mail: {
|
|
|
subject: `#pageEdit - ${page.creator.username} edited ${page.path}`,
|
|
subject: `#pageEdit - ${page.creator.username} edited ${page.path}`,
|
|
|
- template: path.join(this.crowi.localeDir, lang, 'notifications/pageEdit.txt'),
|
|
|
|
|
- vars: {}
|
|
|
|
|
|
|
+ template: `../../locales/${lang}/notifications/pageEdit.txt`,
|
|
|
|
|
+ vars: {
|
|
|
|
|
+ appTitle: this.appTitle,
|
|
|
|
|
+ path: page.path,
|
|
|
|
|
+ username: page.creator.username,
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
slack: {},
|
|
slack: {},
|
|
|
};
|
|
};
|
|
@@ -77,14 +86,18 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
* @memberof GlobalNotification
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
*/
|
|
*/
|
|
|
- notifyPageDelete(page) {
|
|
|
|
|
- const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageDelete');
|
|
|
|
|
|
|
+ async notifyPageDelete(page) {
|
|
|
|
|
+ const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(page.path, 'pageDelete');
|
|
|
const lang = 'en-US'; //FIXME
|
|
const lang = 'en-US'; //FIXME
|
|
|
const option = {
|
|
const option = {
|
|
|
mail: {
|
|
mail: {
|
|
|
subject: `#pageDelete - ${page.creator.username} deleted ${page.path}`, //FIXME
|
|
subject: `#pageDelete - ${page.creator.username} deleted ${page.path}`, //FIXME
|
|
|
- template: path.join(this.crowi.localeDir, lang, 'notifications/pageDelete.txt'),
|
|
|
|
|
- vars: {}
|
|
|
|
|
|
|
+ template: `../../locales/${lang}/notifications/pageDelete.txt`,
|
|
|
|
|
+ vars: {
|
|
|
|
|
+ appTitle: this.appTitle,
|
|
|
|
|
+ path: page.path,
|
|
|
|
|
+ username: page.creator.username,
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
slack: {},
|
|
slack: {},
|
|
|
};
|
|
};
|
|
@@ -97,14 +110,19 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
* @memberof GlobalNotification
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
*/
|
|
*/
|
|
|
- notifyPageMove(page) {
|
|
|
|
|
- const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageMove');
|
|
|
|
|
|
|
+ async notifyPageMove(page, oldPagePath, user) {
|
|
|
|
|
+ const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(page.path, 'pageMove');
|
|
|
const lang = 'en-US'; //FIXME
|
|
const lang = 'en-US'; //FIXME
|
|
|
const option = {
|
|
const option = {
|
|
|
mail: {
|
|
mail: {
|
|
|
- subject: `#pageMove - ${page.creator.username} moved ${page.path} to ${page.path}`, //FIXME
|
|
|
|
|
- template: path.join(this.crowi.localeDir, lang, 'notifications/pageMove.txt'),
|
|
|
|
|
- vars: {}
|
|
|
|
|
|
|
+ subject: `#pageMove - ${user.username} moved ${page.path} to ${page.path}`, //FIXME
|
|
|
|
|
+ template: `../../locales/${lang}/notifications/pageMove.txt`,
|
|
|
|
|
+ vars: {
|
|
|
|
|
+ appTitle: this.appTitle,
|
|
|
|
|
+ oldPath: oldPagePath,
|
|
|
|
|
+ newPath: page.path,
|
|
|
|
|
+ username: user.username,
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
slack: {},
|
|
slack: {},
|
|
|
};
|
|
};
|
|
@@ -117,14 +135,18 @@ class GlobalNotification {
|
|
|
* @memberof GlobalNotification
|
|
* @memberof GlobalNotification
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
*/
|
|
*/
|
|
|
- notifyPageLike(page) {
|
|
|
|
|
- const notifications = Notification.findSettingByPathAndEvent(page.path, 'pageLike');
|
|
|
|
|
|
|
+ async notifyPageLike(page, user) {
|
|
|
|
|
+ const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(page.path, 'pageLike');
|
|
|
const lang = 'en-US'; //FIXME
|
|
const lang = 'en-US'; //FIXME
|
|
|
const option = {
|
|
const option = {
|
|
|
mail: {
|
|
mail: {
|
|
|
- subject: `#pageLike - ${page.creator.username} liked ${page.path}`,
|
|
|
|
|
- template: path.join(this.crowi.localeDir, lang, 'notifications/pageLike.txt'),
|
|
|
|
|
- vars: {}
|
|
|
|
|
|
|
+ subject: `#pageLike - ${user.username} liked ${page.path}`,
|
|
|
|
|
+ template: `../../locales/${lang}/notifications/pageLike.txt`,
|
|
|
|
|
+ vars: {
|
|
|
|
|
+ appTitle: this.appTitle,
|
|
|
|
|
+ path: page.path,
|
|
|
|
|
+ username: page.creator.username,
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
slack: {},
|
|
slack: {},
|
|
|
};
|
|
};
|
|
@@ -138,14 +160,20 @@ class GlobalNotification {
|
|
|
* @param {obejct} page
|
|
* @param {obejct} page
|
|
|
* @param {obejct} comment
|
|
* @param {obejct} comment
|
|
|
*/
|
|
*/
|
|
|
- notifyComment(comment, path) {
|
|
|
|
|
- const notifications = Notification.findSettingByPathAndEvent(path, 'comment');
|
|
|
|
|
|
|
+ async notifyComment(comment, path) {
|
|
|
|
|
+ const notifications = await this.GlobalNotification.Parent.findSettingByPathAndEvent(path, 'comment');
|
|
|
const lang = 'en-US'; //FIXME
|
|
const lang = 'en-US'; //FIXME
|
|
|
|
|
+ const user = await this.User.findOne({_id: comment.creator});
|
|
|
const option = {
|
|
const option = {
|
|
|
mail: {
|
|
mail: {
|
|
|
- subject: `#comment - ${comment.creator.username} commented on ${path}`,
|
|
|
|
|
- template: path.join(this.crowi.localeDir, lang, 'notifications/comment.txt'),
|
|
|
|
|
- vars: {}
|
|
|
|
|
|
|
+ subject: `#comment - ${user.username} commented on ${path}`,
|
|
|
|
|
+ template: `../../locales/${lang}/notifications/comment.txt`,
|
|
|
|
|
+ vars: {
|
|
|
|
|
+ appTitle: this.appTitle,
|
|
|
|
|
+ path: path,
|
|
|
|
|
+ username: user.username,
|
|
|
|
|
+ comment: comment.comment,
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
slack: {},
|
|
slack: {},
|
|
|
};
|
|
};
|
|
@@ -154,4 +182,4 @@ class GlobalNotification {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-module.exports = GlobalNotification;
|
|
|
|
|
|
|
+module.exports = GlobalNotificationService;
|