mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
update all emails to use GraphQL queries; various fixes
This commit is contained in:
parent
44687974ac
commit
0a6034aed1
6 changed files with 90 additions and 115 deletions
|
@ -4,5 +4,6 @@ addRoute([
|
||||||
// {name: "cheatsheet", path: "/cheatsheet", component: import('./components/Cheatsheet.jsx')},
|
// {name: "cheatsheet", path: "/cheatsheet", component: import('./components/Cheatsheet.jsx')},
|
||||||
{name: "groups", path: "/groups", component: () => getDynamicComponent(import('./components/Groups.jsx'))},
|
{name: "groups", path: "/groups", component: () => getDynamicComponent(import('./components/Groups.jsx'))},
|
||||||
{name: "settings", path: "/settings", component: () => getDynamicComponent(import('./components/Settings.jsx'))},
|
{name: "settings", path: "/settings", component: () => getDynamicComponent(import('./components/Settings.jsx'))},
|
||||||
{name: "emails", path: "/emails", component: () => getDynamicComponent(import('./components/Emails.jsx'))},
|
// {name: "emails", path: "/emails", component: () => getDynamicComponent(import('./components/Emails.jsx'))},
|
||||||
|
{name: "emails", path: "/emails", componentName: 'Emails'},
|
||||||
]);
|
]);
|
|
@ -19,7 +19,7 @@ Meteor.startup(function () {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// else get test object (sample post, comment, user, etc.)
|
// else get test object (sample post, comment, user, etc.)
|
||||||
const result = await runQuery(email.query, email.testVariables)
|
const result = await runQuery(email.query, email.testVariables || {})
|
||||||
const emailTestData = result.data;
|
const emailTestData = result.data;
|
||||||
const subject = typeof email.subject === 'function' ? email.subject(emailTestData) : email.subject;
|
const subject = typeof email.subject === 'function' ? email.subject(emailTestData) : email.subject;
|
||||||
|
|
||||||
|
@ -28,12 +28,8 @@ Meteor.startup(function () {
|
||||||
|
|
||||||
html += `
|
html += `
|
||||||
<h4 style="margin: 20px;"><code>Subject: ${subject}</code></h4>
|
<h4 style="margin: 20px;"><code>Subject: ${subject}</code></h4>
|
||||||
<div style="border: 1px solid #999; padding: 20px; margin: 20px;">
|
<div style="border: 1px solid #999; padding: 10px 20px; margin: 20px;">
|
||||||
<pre>
|
<pre><code>${JSON.stringify(emailTestData, null, 2)}</code></pre>
|
||||||
<code>
|
|
||||||
${JSON.stringify(emailTestData, null, '\t')}
|
|
||||||
</code>
|
|
||||||
</pre>
|
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,70 +1,99 @@
|
||||||
import Users from 'meteor/vulcan:users';
|
|
||||||
import VulcanEmail from 'meteor/vulcan:email';
|
import VulcanEmail from 'meteor/vulcan:email';
|
||||||
|
|
||||||
// note: leverage weak dependencies on packages
|
// note: leverage weak dependencies on packages
|
||||||
const Comments = Package['vulcan:comments'] ? Package['vulcan:comments'].default : null;
|
const Comments = Package['vulcan:comments'] ? Package['vulcan:comments'].default : null;
|
||||||
const Posts = Package['vulcan:posts'] ? Package['vulcan:posts'].default : null;
|
const Posts = Package['vulcan:posts'] ? Package['vulcan:posts'].default : null;
|
||||||
|
|
||||||
const getTestUser = userId => typeof Users.findOne(userId) === "undefined" ? Users.findOne() : Users.findOne(userId);
|
|
||||||
|
|
||||||
VulcanEmail.addEmails({
|
VulcanEmail.addEmails({
|
||||||
|
|
||||||
newUser: {
|
newUser: {
|
||||||
template: "newUser",
|
template: "newUser",
|
||||||
path: "/email/new-user/:_id?",
|
path: "/email/new-user/:_id?",
|
||||||
getProperties: Users.getNotificationProperties,
|
|
||||||
subject() {
|
subject() {
|
||||||
return "A new user has been created";
|
return "A new user has been created";
|
||||||
},
|
},
|
||||||
getTestObject: getTestUser,
|
query: `
|
||||||
|
query UsersSingleQuery($documentId: String){
|
||||||
|
UsersSingle(documentId: $documentId){
|
||||||
|
displayName
|
||||||
|
profileUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
},
|
},
|
||||||
|
|
||||||
accountApproved: {
|
accountApproved: {
|
||||||
template: "accountApproved",
|
template: "accountApproved",
|
||||||
path: "/email/account-approved/:_id?",
|
path: "/email/account-approved/:_id?",
|
||||||
getProperties: Users.getNotificationProperties,
|
|
||||||
subject() {
|
subject() {
|
||||||
return "Your account has been approved.";
|
return "Your account has been approved.";
|
||||||
},
|
},
|
||||||
getTestObject: getTestUser,
|
query: `
|
||||||
|
query UsersSingleQuery($documentId: String){
|
||||||
|
UsersSingle(documentId: $documentId){
|
||||||
|
displayName
|
||||||
|
}
|
||||||
|
SiteData{
|
||||||
|
title
|
||||||
|
url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!!Posts) {
|
if (!!Posts) {
|
||||||
|
|
||||||
const getTestPost = postId => typeof Posts.findOne(postId) === "undefined" ? {post: Posts.findOne()} : {post: Posts.findOne(postId)};
|
const postsQuery = `
|
||||||
|
query PostsSingleQuery($documentId: String){
|
||||||
|
PostsSingle(documentId: $documentId){
|
||||||
|
title
|
||||||
|
url
|
||||||
|
pageUrl
|
||||||
|
linkUrl
|
||||||
|
htmlBody
|
||||||
|
thumbnailUrl
|
||||||
|
user{
|
||||||
|
profileUrl
|
||||||
|
displayName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const dummyPost = {title: '[title]', user: {displayName: '[user]'}};
|
||||||
|
|
||||||
VulcanEmail.addEmails({
|
VulcanEmail.addEmails({
|
||||||
|
|
||||||
newPost: {
|
newPost: {
|
||||||
template: "newPost",
|
template: "newPost",
|
||||||
path: "/email/new-post/:_id?",
|
path: "/email/new-post/:_id?",
|
||||||
getProperties: Posts.getNotificationProperties,
|
subject(data) {
|
||||||
subject({postAuthorName="[postAuthorName]", postTitle="[postTitle]"}) {
|
const post = _.isEmpty(data) ? dummyPost : data.PostsSingle;
|
||||||
return postAuthorName+' has created a new post: '+postTitle;
|
return post.user.displayName+' has created a new post: '+post.title;
|
||||||
},
|
},
|
||||||
getTestObject: getTestPost,
|
query: postsQuery
|
||||||
},
|
},
|
||||||
|
|
||||||
newPendingPost: {
|
newPendingPost: {
|
||||||
template: "newPendingPost",
|
template: "newPendingPost",
|
||||||
path: "/email/new-pending-post/:_id?",
|
path: "/email/new-pending-post/:_id?",
|
||||||
getProperties: Posts.getNotificationProperties,
|
subject(data) {
|
||||||
subject({postAuthorName="[postAuthorName]", postTitle="[postTitle]"}) {
|
const post = _.isEmpty(data) ? dummyPost : data.PostsSingle;
|
||||||
return postAuthorName+' has a new post pending approval: '+postTitle;
|
return post.user.displayName+' has a new post pending approval: '+post.title;
|
||||||
},
|
},
|
||||||
getTestObject: getTestPost,
|
query: postsQuery
|
||||||
},
|
},
|
||||||
|
|
||||||
postApproved: {
|
postApproved: {
|
||||||
template: "postApproved",
|
template: "postApproved",
|
||||||
path: "/email/post-approved/:_id?",
|
path: "/email/post-approved/:_id?",
|
||||||
getProperties: Posts.getNotificationProperties,
|
subject(data) {
|
||||||
subject({postTitle="[postTitle]"}) {
|
const post = _.isEmpty(data) ? dummyPost : data.PostsSingle;
|
||||||
return 'Your post “'+postTitle+'” has been approved';
|
return 'Your post “'+post.title+'” has been approved';
|
||||||
},
|
},
|
||||||
getTestObject: getTestPost,
|
query: postsQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -74,38 +103,55 @@ if (!!Posts) {
|
||||||
|
|
||||||
if (!!Comments) {
|
if (!!Comments) {
|
||||||
|
|
||||||
const getTestComment = commentId => typeof Comments.findOne(commentId) === "undefined" ? {comment: Comments.findOne()} : {comment: Comments.findOne(commentId)};
|
const commentsQuery = `
|
||||||
|
query CommentsSingleQuery($documentId: String){
|
||||||
|
CommentsSingle(documentId: $documentId){
|
||||||
|
pageUrl
|
||||||
|
htmlBody
|
||||||
|
post{
|
||||||
|
pageUrl
|
||||||
|
title
|
||||||
|
}
|
||||||
|
user{
|
||||||
|
profileUrl
|
||||||
|
displayName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const dummyComment = {post: {title: '[title]'}, user: {displayName: '[user]'}};
|
||||||
|
|
||||||
VulcanEmail.addEmails({
|
VulcanEmail.addEmails({
|
||||||
|
|
||||||
newComment: {
|
newComment: {
|
||||||
template: "newComment",
|
template: "newComment",
|
||||||
path: "/email/new-comment/:_id?",
|
path: "/email/new-comment/:_id?",
|
||||||
getProperties: Comments.getNotificationProperties,
|
subject(data) {
|
||||||
subject({authorName = "[authorName]", postTitle = "[postTitle]"}) {
|
const comment = _.isEmpty(data) ? dummyComment : data.CommentsSingle;
|
||||||
return authorName+' left a new comment on your post "' + postTitle + '"';
|
return comment.user.displayName+' left a new comment on your post "' + comment.post.title + '"';
|
||||||
},
|
},
|
||||||
getTestObject: getTestComment,
|
query: commentsQuery
|
||||||
},
|
},
|
||||||
|
|
||||||
newReply: {
|
newReply: {
|
||||||
template: "newReply",
|
template: "newReply",
|
||||||
path: "/email/new-reply/:_id?",
|
path: "/email/new-reply/:_id?",
|
||||||
getProperties: Comments.getNotificationProperties,
|
subject(data) {
|
||||||
subject({authorName = "[authorName]", postTitle = "[postTitle]"}) {
|
const comment = _.isEmpty(data) ? dummyComment : data.CommentsSingle;
|
||||||
return authorName+' replied to your comment on "'+postTitle+'"';
|
return comment.user.displayName+' replied to your comment on "'+comment.post.title+'"';
|
||||||
},
|
},
|
||||||
getTestObject: getTestComment,
|
query: commentsQuery
|
||||||
},
|
},
|
||||||
|
|
||||||
newCommentSubscribed: {
|
newCommentSubscribed: {
|
||||||
template: "newComment",
|
template: "newComment",
|
||||||
path: "/email/new-comment-subscribed/:_id?",
|
path: "/email/new-comment-subscribed/:_id?",
|
||||||
getProperties: Comments.getNotificationProperties,
|
subject(data) {
|
||||||
subject({authorName = "[authorName]", postTitle = "[postTitle]"}) {
|
const comment = _.isEmpty(data) ? dummyComment : data.CommentsSingle;
|
||||||
return authorName+' left a new comment on "' + postTitle + '"';
|
return comment.user.displayName+' left a new comment on "' + comment.post.title + '"';
|
||||||
},
|
},
|
||||||
getTestObject: getTestComment,
|
query: commentsQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
import Users from 'meteor/vulcan:users';
|
|
||||||
import { Utils, getSetting } from 'meteor/vulcan:core';
|
|
||||||
|
|
||||||
// note: leverage weak dependencies on packages
|
|
||||||
const Comments = Package['vulcan:comments'] ? Package['vulcan:comments'].default : null;
|
|
||||||
const Posts = Package['vulcan:posts'] ? Package['vulcan:posts'].default : null;
|
|
||||||
|
|
||||||
Users.getNotificationProperties = user => {
|
|
||||||
const properties = {
|
|
||||||
profileUrl: Users.getProfileUrl(user),
|
|
||||||
displayName: Users.getDisplayName(user),
|
|
||||||
siteTitle: getSetting('title'),
|
|
||||||
siteUrl: Utils.getSiteUrl(),
|
|
||||||
};
|
|
||||||
|
|
||||||
return properties;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!!Posts) {
|
|
||||||
|
|
||||||
Posts.getNotificationProperties = data => {
|
|
||||||
const post = data.post;
|
|
||||||
const postAuthor = Users.findOne(post.userId);
|
|
||||||
const properties = {
|
|
||||||
postAuthorName : Posts.getAuthorName(post),
|
|
||||||
postTitle : Utils.cleanUp(post.title),
|
|
||||||
profileUrl: Users.getProfileUrl(postAuthor, true),
|
|
||||||
postUrl: Posts.getPageUrl(post, true),
|
|
||||||
thumbnailUrl: post.thumbnailUrl,
|
|
||||||
linkUrl: !!post.url ? Utils.getOutgoingUrl(post.url) : Posts.getPageUrl(post, true),
|
|
||||||
};
|
|
||||||
|
|
||||||
if(post.url)
|
|
||||||
properties.url = post.url;
|
|
||||||
|
|
||||||
if(post.htmlBody)
|
|
||||||
properties.htmlBody = post.htmlBody;
|
|
||||||
|
|
||||||
return properties;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!!Comments) {
|
|
||||||
|
|
||||||
Comments.getNotificationProperties = data => {
|
|
||||||
const comment = data.comment;
|
|
||||||
const commentAuthor = Users.findOne(comment.userId);
|
|
||||||
const post = Posts.findOne(comment.postId);
|
|
||||||
const properties = {
|
|
||||||
profileUrl: commentAuthor && Users.getProfileUrl(commentAuthor, true),
|
|
||||||
postUrl: Posts.getPageUrl(post, true),
|
|
||||||
authorName : Comments.getAuthorName(comment),
|
|
||||||
postTitle: post.title,
|
|
||||||
htmlBody: comment.htmlBody,
|
|
||||||
commentUrl: Comments.getPageUrl(comment, true),
|
|
||||||
};
|
|
||||||
|
|
||||||
return properties;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,4 +1,3 @@
|
||||||
import './helpers.js';
|
|
||||||
import './emails.js';
|
import './emails.js';
|
||||||
import './callbacks.js';
|
import './callbacks.js';
|
||||||
import './custom_fields.js';
|
import './custom_fields.js';
|
||||||
|
|
|
@ -8,17 +8,12 @@ export const createNotification = (userIds, notificationName, data) => {
|
||||||
// if userIds is not an array, wrap it in one
|
// if userIds is not an array, wrap it in one
|
||||||
if (!Array.isArray(userIds)) userIds = [userIds];
|
if (!Array.isArray(userIds)) userIds = [userIds];
|
||||||
|
|
||||||
|
const email = VulcanEmail.emails[notificationName];
|
||||||
|
|
||||||
userIds.forEach(userId => {
|
userIds.forEach(userId => {
|
||||||
|
const to = Users.getEmail(Users.findOne(userId));
|
||||||
const user = Users.findOne(userId);
|
if (to) {
|
||||||
const email = VulcanEmail.emails[notificationName];
|
VulcanEmail.buildAndSend({ to, email, data });
|
||||||
const properties = email.getProperties(data);
|
|
||||||
const subject = typeof email.subject === 'function' ? email.subject(properties) : email.subject;
|
|
||||||
const html = VulcanEmail.getTemplate(email.template)(properties);
|
|
||||||
|
|
||||||
const userEmail = Users.getEmail(user);
|
|
||||||
if (!!userEmail) {
|
|
||||||
VulcanEmail.buildAndSendHTML(Users.getEmail(user), subject, html);
|
|
||||||
} else {
|
} else {
|
||||||
console.log(`// Couldn't send notification: admin user ${user._id} doesn't have an email`); // eslint-disable-line
|
console.log(`// Couldn't send notification: admin user ${user._id} doesn't have an email`); // eslint-disable-line
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue