pass the original story URL to all comments for notification email
This commit is contained in:
@ -291,11 +291,6 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
|
||||
getAllCourses: function() {
|
||||
"use strict";
|
||||
return coursewares;
|
||||
},
|
||||
|
||||
allCoursewareIds: function() {
|
||||
return coursewares.map(function(elem) {
|
||||
return {
|
||||
|
@ -154,6 +154,7 @@ exports.returnIndividualStory = function(req, res, next) {
|
||||
res.render('stories/index', {
|
||||
title: story.headline,
|
||||
link: story.link,
|
||||
originalStoryLink: dashedName,
|
||||
author: story.author,
|
||||
description: story.description,
|
||||
rank: story.upVotes.length,
|
||||
@ -377,6 +378,7 @@ exports.commentSubmit = function(req, res, next) {
|
||||
}
|
||||
var comment = new Comment({
|
||||
associatedPost: data.associatedPost,
|
||||
originalStoryLink: originalStoryLink,
|
||||
body: sanitizedBody,
|
||||
rank: 0,
|
||||
upvotes: 0,
|
||||
@ -391,7 +393,6 @@ exports.commentSubmit = function(req, res, next) {
|
||||
|
||||
exports.commentOnCommentSubmit = function(req, res, next) {
|
||||
var data = req.body.data;
|
||||
|
||||
if (req.user._id.toString() !== data.author.userId.toString()) {
|
||||
return next(new Error('Not authorized'));
|
||||
}
|
||||
@ -412,6 +413,7 @@ exports.commentOnCommentSubmit = function(req, res, next) {
|
||||
body: sanitizedBody,
|
||||
rank: 0,
|
||||
upvotes: 0,
|
||||
originalStoryLink: data.originalStoryLink,
|
||||
author: data.author,
|
||||
comments: [],
|
||||
topLevel: false,
|
||||
@ -444,66 +446,25 @@ function commentSave(comment, Context, res, next) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
Comment.findById(associatedStory._id, function(err, originalStory) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
debug('is it a comment?', originalStory);
|
||||
if (!originalStory) {
|
||||
Story.findById(associatedStory.associatedPost, function(err, originalStory) {
|
||||
debug('is it a story?', originalStory);
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
var transporter = nodemailer.createTransport({
|
||||
service: 'Mandrill',
|
||||
auth: {
|
||||
user: secrets.mandrill.user,
|
||||
pass: secrets.mandrill.password
|
||||
}
|
||||
});
|
||||
console.log('1!');
|
||||
var mailOptions = {
|
||||
to: recipient.email,
|
||||
from: 'Team@freecodecamp.com',
|
||||
subject: originalStory.author.username + " replied to you on Camper News!",
|
||||
text: [
|
||||
"<a href='http://freecodecamp.com/stories/" + originalStory.storyLink + "'>Here.</a>",
|
||||
'- the Volunteer Camp Counselor Team'
|
||||
].join('')
|
||||
};
|
||||
console.log('2!');
|
||||
transporter.sendMail(mailOptions, function(err) {
|
||||
if (err) { return err; }
|
||||
done(null, null);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log('definitely a comment');
|
||||
var transporter = nodemailer.createTransport({
|
||||
service: 'Mandrill',
|
||||
auth: {
|
||||
user: secrets.mandrill.user,
|
||||
pass: secrets.mandrill.password
|
||||
}
|
||||
});
|
||||
console.log('1!');
|
||||
var mailOptions = {
|
||||
to: recipient.email,
|
||||
from: 'Team@freecodecamp.com',
|
||||
subject: originalStory.author.username + " replied to you on Camper News!",
|
||||
text: [
|
||||
"<a href='http://freecodecamp.com/stories/" + originalStory.storyLink + "'>Here.</a>",
|
||||
'- the Volunteer Camp Counselor Team'
|
||||
].join('')
|
||||
};
|
||||
console.log('2!');
|
||||
transporter.sendMail(mailOptions, function(err) {
|
||||
if (err) { return err; }
|
||||
done(null, null);
|
||||
});
|
||||
var transporter = nodemailer.createTransport({
|
||||
service: 'Mandrill',
|
||||
auth: {
|
||||
user: secrets.mandrill.user,
|
||||
pass: secrets.mandrill.password
|
||||
}
|
||||
});
|
||||
var mailOptions = {
|
||||
to: recipient.email,
|
||||
from: 'Team@freecodecamp.com',
|
||||
subject: associatedStory.author.username + " replied to you on Camper News!",
|
||||
text: [
|
||||
"<a href='http://freecodecamp.com/stories/" + comment.originalStoryLink + "'>Here.</a>",
|
||||
'- the Volunteer Camp Counselor Team'
|
||||
].join('')
|
||||
};
|
||||
transporter.sendMail(mailOptions, function(err) {
|
||||
if (err) { return err; }
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
|
@ -6,6 +6,10 @@ var commentSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
originalStoryLink: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
body: {
|
||||
type: String,
|
||||
default: ''
|
||||
|
@ -281,6 +281,7 @@ $(document).ready(function() {
|
||||
{
|
||||
data: {
|
||||
associatedPost: storyId,
|
||||
originalStoryLink: originalStoryLink,
|
||||
body: data,
|
||||
author: {
|
||||
picture: user.profile.picture,
|
||||
@ -295,7 +296,6 @@ $(document).ready(function() {
|
||||
.done(function (data, textStatus, xhr) {
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
$('#comment-button').on('click', commentSubmitButtonHandler);
|
||||
|
@ -16,6 +16,7 @@ h3
|
||||
var docfrag = document.createDocumentFragment();
|
||||
for (var i = 0; i < data.wikiList.length; i++) {
|
||||
var li = document.createElement("li");
|
||||
// strike through wikis previously read
|
||||
var linkedName = getLinkedName(data.wikiList[i].name);
|
||||
if (data.completedWikis.indexOf(data.wikiIds[i]) > -1) {
|
||||
$(li).html("<a class='strikethrough' href='/wiki/" + linkedName + "'>" + data.wikiList[i].name + "</a></li>");
|
||||
|
@ -96,6 +96,7 @@
|
||||
{
|
||||
data: {
|
||||
associatedPost: commentId,
|
||||
originalStoryLink: originalStoryLink,
|
||||
body: $('#comment-to-comment-textinput').val(),
|
||||
author: {
|
||||
picture: user.profile.picture,
|
||||
|
@ -1,6 +1,7 @@
|
||||
.spacer
|
||||
script.
|
||||
var storyId = !{JSON.stringify(id)};
|
||||
var originalStoryLink = !{JSON.stringify(originalStoryLink)};
|
||||
var comments = !{JSON.stringify(comments)};
|
||||
var upVotes = !{JSON.stringify(upVotes)};
|
||||
var image = !{JSON.stringify(image)};
|
||||
|
Reference in New Issue
Block a user