diff --git a/scripts/mail.coffee b/scripts/mail.coffee index c9ff590c4..c73d8ee41 100644 --- a/scripts/mail.coffee +++ b/scripts/mail.coffee @@ -91,8 +91,7 @@ emailUserInitialRecruiting = (user, callback) -> team = user.session.levelInfo.team team = team.substr(0, team.length - 1) context = - email_id: sendwithus.templates.recruiting_email.id - version_name: sendwithus.templates.recruiting_email.version + email_id: sendwithus.templates.recruiting_email recipient: address: if DEBUGGING then 'nick@codecombat.com' else user.email name: name @@ -135,8 +134,7 @@ emailUserTournamentResults = (winner, callback) -> name = winner.name team = winner.team.substr(0, winner.team.length - 1) context = - email_id: sendwithus.templates.greed_tournament_rank.id - version_name: sendwithus.templates.greed_tournament_rank.version + email_id: sendwithus.templates.greed_tournament_rank recipient: address: if DEBUGGING then 'nick@codecombat.com' else winner.email name: name diff --git a/server/commons/Handler.coffee b/server/commons/Handler.coffee index c61941074..aceff9437 100644 --- a/server/commons/Handler.coffee +++ b/server/commons/Handler.coffee @@ -468,8 +468,7 @@ module.exports = class Handler notifyWatcherOfChange: (editor, watcher, changedDocument, editPath) -> context = - email_id: sendwithus.templates.change_made_notify_watcher.id - version_name: sendwithus.templates.change_made_notify_watcher.version + email_id: sendwithus.templates.change_made_notify_watcher recipient: address: watcher.get('email') name: watcher.get('name') diff --git a/server/handlers/course_instance_handler.coffee b/server/handlers/course_instance_handler.coffee index d7353f1ef..bf26df540 100644 --- a/server/handlers/course_instance_handler.coffee +++ b/server/handlers/course_instance_handler.coffee @@ -187,8 +187,7 @@ CourseInstanceHandler = class CourseInstanceHandler extends Handler return @sendForbiddenError(res) unless prepaid.get('maxRedeemers') > prepaid.get('redeemers').length for email in req.body.emails context = - email_id: sendwithus.templates.course_invite_email.id - version: sendwithus.templates.course_invite_email.version + email_id: sendwithus.templates.course_invite_email recipient: address: email subject: course.get('name') diff --git a/server/handlers/patch_handler.coffee b/server/handlers/patch_handler.coffee index f47c88831..b88f63a86 100644 --- a/server/handlers/patch_handler.coffee +++ b/server/handlers/patch_handler.coffee @@ -100,8 +100,7 @@ PatchHandler = class PatchHandler extends Handler sendPatchCreatedEmail: (patchCreator, watcher, patch, target, docLink) -> # return if watcher._id is patchCreator._id context = - email_id: sendwithus.templates.patch_created.id - version_name: sendwithus.templates.patch_created.version + email_id: sendwithus.templates.patch_created recipient: address: watcher.get('email') name: watcher.get('name') diff --git a/server/handlers/user_handler.coffee b/server/handlers/user_handler.coffee index 2d97e95d1..455aa90bb 100644 --- a/server/handlers/user_handler.coffee +++ b/server/handlers/user_handler.coffee @@ -457,11 +457,9 @@ UserHandler = class UserHandler extends Handler # Type-specific email data if type is 'subscribe modal parent' - emailParams['email_id'] = sendwithus.templates.parent_subscribe_email.id - emailParams['version_name'] = sendwithus.templates.parent_subscribe_email.version + emailParams['email_id'] = sendwithus.templates.parent_subscribe_email else if type is 'share progress modal parent' - emailParams['email_id'] = sendwithus.templates.share_progress_email.id - emailParams['version_name'] = sendwithus.templates.share_progress_email.version + emailParams['email_id'] = sendwithus.templates.share_progress_email sendMail emailParams diff --git a/server/middleware/auth.coffee b/server/middleware/auth.coffee index d60013ad1..9f3c2f756 100644 --- a/server/middleware/auth.coffee +++ b/server/middleware/auth.coffee @@ -52,7 +52,7 @@ module.exports = yield req.logInAsync(user) if req.query.callback - res.jsonp(req.user.toObject({req, publicOnly: true})) + res.jsonp(req.user.toObject({req, publicOnly: true})) else res.send(req.user.toObject({req, publicOnly: false})) res.end() @@ -132,8 +132,7 @@ module.exports = user.set('passwordReset', utils.getCodeCamel()) yield user.save() context = - email_id: sendwithus.templates.password_reset.id - version_name: sendwithus.templates.password_reset.version + email_id: sendwithus.templates.password_reset recipient: address: req.body.email email_data: diff --git a/server/middleware/classrooms.coffee b/server/middleware/classrooms.coffee index 783e375e4..1c2ec0f78 100644 --- a/server/middleware/classrooms.coffee +++ b/server/middleware/classrooms.coffee @@ -235,8 +235,7 @@ module.exports = for email in req.body.emails joinCode = (classroom.get('codeCamel') or classroom.get('code')) context = - email_id: sendwithus.templates.course_invite_email.id - version_name: sendwithus.templates.course_invite_email.version + email_id: sendwithus.templates.course_invite_email recipient: address: email email_data: diff --git a/server/middleware/users.coffee b/server/middleware/users.coffee index aff914d5b..b334ca8f2 100644 --- a/server/middleware/users.coffee +++ b/server/middleware/users.coffee @@ -85,8 +85,7 @@ module.exports = if not user throw new errors.NotFound('User not found') context = - email_id: sendwithus.templates.verify_email.id - version_name: sendwithus.templates.verify_email.version + email_id: sendwithus.templates.verify_email recipient: address: user.get('email') name: user.broadName() diff --git a/server/middleware/versions.coffee b/server/middleware/versions.coffee index 21cd9af90..aafebcb08 100644 --- a/server/middleware/versions.coffee +++ b/server/middleware/versions.coffee @@ -107,8 +107,7 @@ module.exports = User.find({_id:{$in:watchers}}).select({email:1, name:1}).exec (err, watchers) -> for watcher in watchers context = - email_id: sendwithus.templates.change_made_notify_watcher.id - version_name: sendwithus.templates.change_made_notify_watcher.version + email_id: sendwithus.templates.change_made_notify_watcher recipient: address: watcher.get('email') name: watcher.get('name') @@ -128,7 +127,7 @@ module.exports = original = req.params.handle version = req.params.version if not database.isID(original) - throw new errors.UnprocessableEntity('Invalid MongoDB id: '+original) + throw new errors.UnprocessableEntity('Invalid MongoDB id: '+original) query = { 'original': mongoose.Types.ObjectId(original) } if version? diff --git a/server/models/User.coffee b/server/models/User.coffee index e177ae7ee..fa43f8c32 100644 --- a/server/models/User.coffee +++ b/server/models/User.coffee @@ -272,8 +272,7 @@ UserSchema.methods.register = (done) -> { welcome_email_student, welcome_email_user } = sendwithus.templates timestamp = (new Date).getTime() data = - email_id: if @isStudent() then welcome_email_student.id else welcome_email_user.id - version_name: if @isStudent() then welcome_email_student.version else welcome_email_user.version + email_id: if @isStudent() then welcome_email_student else welcome_email_user recipient: address: @get('email') name: @broadName() diff --git a/server/routes/contact.coffee b/server/routes/contact.coffee index fea0b2ff7..651639bcb 100644 --- a/server/routes/contact.coffee +++ b/server/routes/contact.coffee @@ -17,7 +17,7 @@ module.exports.setup = (app) -> req.user.update({$set: { enrollmentRequestSent: true }}).exec(_.noop) if req.body.recipientID is 'schools@codecombat.com' closeIO.sendMail fromAddress, subject, content, (err) -> log.error "Error sending contact form email via Close.io: #{err.message or err}" if err - else + else createSendWithUsContext req, fromAddress, subject, content, (context) -> sendwithus.api.send context, (err, result) -> log.error "Error sending contact form email via sendwithus: #{err.message or err}" if err @@ -61,8 +61,7 @@ createSendWithUsContext = (req, fromAddress, subject, content, done) -> else config.mail.supportPrimary context = - email_id: sendwithus.templates.plain_text_email.id - version_name: sendwithus.templates.plain_text_email.version + email_id: sendwithus.templates.plain_text_email recipient: address: toAddress sender: diff --git a/server/routes/mail.coffee b/server/routes/mail.coffee index d823d296c..b888f261e 100644 --- a/server/routes/mail.coffee +++ b/server/routes/mail.coffee @@ -592,8 +592,7 @@ sendLadderUpdateEmail = (session, now, daysAgo) -> sendEmail = (defeatContext, victoryContext, levelVersionsContext) -> # TODO: do something with the preferredLanguage? context = - email_id: sendwithus.templates.ladder_update_email.id - version_name: sendwithus.templates.ladder_update_email.version + email_id: sendwithus.templates.ladder_update_email recipient: address: if DEBUGGING then 'nick@codecombat.com' else user.get('email') name: name @@ -722,8 +721,7 @@ sendNextStepsEmail = (user, now, daysAgo) -> # Used to use these categories to customize the email; not doing it right now. TODO: customize it again in Sendwithus. # TODO: do something with the preferredLanguage? context = - email_id: sendwithus.templates.next_steps_email.id - version_name: sendwithus.templates.next_steps_email.version + email_id: sendwithus.templates.next_steps_email recipient: address: if DEBUGGING then 'nick@codecombat.com' else user.get('email') name: name diff --git a/server/sendwithus.coffee b/server/sendwithus.coffee index df6ba88c3..23f834438 100644 --- a/server/sendwithus.coffee +++ b/server/sendwithus.coffee @@ -11,30 +11,26 @@ module.exports.api = send: (context, cb) -> log.debug('Tried to send email with context: ', JSON.stringify(context, null, ' ')) setTimeout(cb, 10) - + if swuAPIKey module.exports.api = new sendwithusAPI swuAPIKey, debug - -# Version name can be supplied to tie a specific version to a deploy. -# That is most useful for testing templates with new data fields on staging. -# If it doesn't need to be synchronized to a deploy, you can just "publish" -# the new template version on SendWithUs (and leave this version blank) + module.exports.templates = - parent_subscribe_email: { id: 'tem_2APERafogvwKhmcnouigud' } - share_progress_email: { id: 'tem_VHE3ihhGmVa3727qds9zY8' } - welcome_email_user: { id: 'tem_z7Xvj3mtWYk6ec6aW7RwFk' } - welcome_email_student: { id: 'tem_4WYPZNLzs5wawMF9qUJXUH' } - verify_email: { id: 'tem_zJee6uRsRmzqzktzneCkCn' } - ladder_update_email: { id: 'JzaZxf39A4cKMxpPZUfWy4' } - patch_created: { id: 'tem_xhxuNosLALsizTNojBjNcL' } - change_made_notify_watcher: { id: 'tem_7KVkfmv9SZETb25dtHbUtG' } - recruiting_email: { id: 'tem_mdFMgtcczHKYu94Jmq68j8' } - greed_tournament_rank: { id: 'tem_c4KYnk2TriEkkZx5NqqGLG' } - generic_email: { id: 'tem_JhRnQ4pvTS4KdQjYoZdbei' } - plain_text_email: { id: 'tem_85UvKDCCNPXsFckERTig6Y' } - next_steps_email: { id: 'tem_RDHhTG5inXQi8pthyqWr5D' } - course_invite_email: { id: 'tem_u6D2EFWYC5Ptk38bSykjsU', version: 'v3' } - teacher_free_trial: { id: 'tem_R7d9Hpoba9SceQNiYSXBak' } - teacher_free_trial_hoc: { id: 'tem_4ZSY9wsA9Qwn4wBFmZgPdc' } - teacher_request_demo: { id: 'tem_cwG3HZjEyb6QE493hZuUra' } - password_reset: { id: 'tem_wbQUMRtLY9xhec8BSCykLA' } + parent_subscribe_email: 'tem_2APERafogvwKhmcnouigud' + share_progress_email: 'tem_VHE3ihhGmVa3727qds9zY8' + welcome_email_user: 'tem_z7Xvj3mtWYk6ec6aW7RwFk' + welcome_email_student: 'tem_4WYPZNLzs5wawMF9qUJXUH' + verify_email: 'tem_zJee6uRsRmzqzktzneCkCn' + ladder_update_email: 'JzaZxf39A4cKMxpPZUfWy4' + patch_created: 'tem_xhxuNosLALsizTNojBjNcL' + change_made_notify_watcher: 'tem_7KVkfmv9SZETb25dtHbUtG' + recruiting_email: 'tem_mdFMgtcczHKYu94Jmq68j8' + greed_tournament_rank: 'tem_c4KYnk2TriEkkZx5NqqGLG' + generic_email: 'tem_JhRnQ4pvTS4KdQjYoZdbei' + plain_text_email: 'tem_85UvKDCCNPXsFckERTig6Y' + next_steps_email: 'tem_RDHhTG5inXQi8pthyqWr5D' + course_invite_email: 'tem_ic2ZhPkpj8GBADFuyAp4bj' + teacher_free_trial: 'tem_R7d9Hpoba9SceQNiYSXBak' + teacher_free_trial_hoc: 'tem_4ZSY9wsA9Qwn4wBFmZgPdc' + teacher_request_demo: 'tem_cwG3HZjEyb6QE493hZuUra' + password_reset: 'tem_wbQUMRtLY9xhec8BSCykLA' diff --git a/spec/server/functional/article.spec.coffee b/spec/server/functional/article.spec.coffee index d42e8f55e..5a5fb1c4a 100644 --- a/spec/server/functional/article.spec.coffee +++ b/spec/server/functional/article.spec.coffee @@ -127,7 +127,7 @@ describe 'POST /db/article', -> @admin = yield utils.initAdmin({}) yield utils.loginUser(@admin) [@res, @body] = yield request.postAsync { - uri: getURL('/db/article'), json: articleData + uri: getURL('/db/article'), json: articleData } done() @@ -163,8 +163,8 @@ describe 'POST /db/article', -> it 'returns 422 when properties do not pass validation', utils.wrap (done) -> - [res, body] = yield request.postAsync { - uri: getURL('/db/article'), json: { i18nCoverage: 9001 } + [res, body] = yield request.postAsync { + uri: getURL('/db/article'), json: { i18nCoverage: 9001 } } expect(res.statusCode).toBe(422) expect(body.validationErrors).toBeDefined() @@ -461,7 +461,7 @@ describe 'POST /db/article/:handle/new-version', -> it 'notifies watchers of changes', utils.wrap (done) -> sendwithus = require '../../../server/sendwithus' spyOn(sendwithus.api, 'send').and.callFake (context, cb) -> - expect(context.email_id).toBe(sendwithus.templates.change_made_notify_watcher.id) + expect(context.email_id).toBe(sendwithus.templates.change_made_notify_watcher) expect(context.recipient.address).toBe('test@gmail.com') done() user = yield User({email: 'test@gmail.com', name: 'a user'}).save() diff --git a/spec/server/functional/classrooms.spec.coffee b/spec/server/functional/classrooms.spec.coffee index 4ab2efd29..b34cb3152 100644 --- a/spec/server/functional/classrooms.spec.coffee +++ b/spec/server/functional/classrooms.spec.coffee @@ -375,7 +375,7 @@ describe 'POST /db/classroom/:id/invite-members', -> data = { emails: ['test@test.com'] } sendwithus = require '../../../server/sendwithus' spyOn(sendwithus.api, 'send').and.callFake (context, cb) -> - expect(context.email_id).toBe(sendwithus.templates.course_invite_email.id) + expect(context.email_id).toBe(sendwithus.templates.course_invite_email) expect(context.recipient.address).toBe('test@test.com') expect(context.email_data.teacher_name).toBe('Mr Professerson') done()