From f7035d4220ea82c2718ae48ffad596098cebe52f Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Tue, 22 Apr 2014 19:27:39 -0700 Subject: [PATCH] Added an unsubscribe url for recruit notifications. --- server/routes/auth.coffee | 24 +++++++++++++++++------- test/server/functional/auth.spec.coffee | 12 ++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/server/routes/auth.coffee b/server/routes/auth.coffee index e7aa44b67..3b5c30b1d 100644 --- a/server/routes/auth.coffee +++ b/server/routes/auth.coffee @@ -132,14 +132,24 @@ module.exports.setup = (app) -> return errors.notFound res, "No user found with email '#{req.query.email}'" emails = _.clone(user.get('emails')) or {} - emailSettings.enabled = false for emailSettings in _.values(emails) - emails.generalNews ?= {} - emails.generalNews.enabled = false - emails.anyNotes ?= {} - emails.anyNotes.enabled = false - user.update {$set: {emails: emails, emailSubscriptions: []}}, {}, => + msg = '' + + if req.query.recruitNotes + emails.recruitNotes ?= {} + emails.recruitNotes.enabled = false + msg = "Unsubscribed #{req.query.email} from recruiting emails." + + else + msg = "Unsubscribed #{req.query.email} from all CodeCombat emails. Sorry to see you go!" + emailSettings.enabled = false for emailSettings in _.values(emails) + emails.generalNews ?= {} + emails.generalNews.enabled = false + emails.anyNotes ?= {} + emails.anyNotes.enabled = false + + user.update {$set: {emails: emails}}, {}, => return errors.serverError res, 'Database failure.' if err - res.send "Unsubscribed #{req.query.email} from all CodeCombat emails. Sorry to see you go!

Account settings

" + res.send msg + "

Account settings

" res.end() module.exports.loginUser = loginUser = (req, res, user, send=true, next=null) -> diff --git a/test/server/functional/auth.spec.coffee b/test/server/functional/auth.spec.coffee index 750f4997e..6e5f5f07e 100644 --- a/test/server/functional/auth.spec.coffee +++ b/test/server/functional/auth.spec.coffee @@ -1,5 +1,6 @@ require '../common' request = require 'request' +User = require '../../../server/users/User' urlLogin = getURL('/auth/login') urlReset = getURL('/auth/reset') @@ -134,3 +135,14 @@ describe '/auth/reset', -> form = req.form() form.append('username', 'scott@gmail.com') form.append('password', 'nada') + +describe '/auth/unsubscribe', -> + + it 'removes just recruitment emails if you include ?recruitNotes=1', (done) -> + loginJoe (joe) -> + url = getURL('/auth/unsubscribe?recruitNotes=1&email='+joe.get('email')) + request.get url, (error, response) -> + expect(response.statusCode).toBe(200) + user = User.findOne(joe.get('_id')).exec (err, user) -> + expect(user.get('emails').recruitNotes.enabled).toBe(false) + done()