moved unsubscribe endpoint to new user controller

This commit is contained in:
Henry Oswald 2014-04-09 15:41:19 +01:00
parent d611984948
commit bcfc1bee0c
5 changed files with 34 additions and 24 deletions

View file

@ -1,4 +1,6 @@
UserDeleter = require("./UserDeleter")
UserLocator = require("./UserLocator")
newsLetterManager = require('../Newsletter/NewsletterManager')
module.exports =
@ -8,3 +10,8 @@ module.exports =
if !err?
req.session.destroy()
res.send(200)
unsubscribe: (req, res)->
UserLocator.findById req.session.user._id, (err, user)->
newsLetterManager.unsubscribe user, ->
res.send()

View file

@ -5,7 +5,6 @@ _ = require('underscore')
logger = require('logger-sharelatex')
Security = require('../managers/SecurityManager')
Settings = require('settings-sharelatex')
newsLetterManager = require('../Features/Newsletter/NewsletterManager')
dropboxHandler = require('../Features/Dropbox/DropboxHandler')
userRegistrationHandler = require('../Features/User/UserRegistrationHandler')
metrics = require('../infrastructure/Metrics')
@ -106,10 +105,7 @@ module.exports =
res.redirect '/login'
unsubscribe: (req, res)->
User.findById req.session.user._id, (err, user)->
newsLetterManager.unsubscribe user, ->
res.send()
apiUpdate : (req, res)->
logger.log user: req.session.user, "updating account settings"
@ -158,13 +154,3 @@ module.exports =
text:'Your old password is wrong'
deleteUser: (req, res)->
user_id = req.session.user._id
UserDeleter.deleteUser user_id, (err)->
if !err?
req.session.destroy()
res.send(200)

View file

@ -80,7 +80,7 @@ module.exports = class Router
app.post '/user/password/update', AuthenticationController.requireLogin(), UserController.changePassword
app.get '/user/passwordreset', UserPagesController.passwordResetPage
app.post '/user/passwordReset', UserController.doRequestPasswordReset
app.del '/user/newsletter/unsubscribe', AuthenticationController.requireLogin(), UserController.unsubscribe
app.del '/user/newsletter/unsubscribe', AuthenticationController.requireLogin(), UserController_new.unsubscribe
app.del '/user', AuthenticationController.requireLogin(), UserController_new.deleteUser
app.get '/dropbox/beginAuth', DropboxUserController.redirectUserToDropboxAuth

View file

@ -11,28 +11,46 @@ ObjectId = require("mongojs").ObjectId
describe "UserController", ->
beforeEach ->
@user =
_id:"!@£!23123"
@UserDeleter =
deleteUser: sinon.stub().callsArgWith(1)
@UserLocator =
findById: sinon.stub().callsArgWith(1, null, @user)
@NewsLetterManager =
unsubscribe: sinon.stub().callsArgWith(1)
@UserController = SandboxedModule.require modulePath, requires:
"./UserDeleter": @UserDeleter
"./UserLocator": @UserLocator
'../Newsletter/NewsletterManager':@NewsLetterManager
"logger-sharelatex": {log:->}
@req = new MockRequest()
@res = new MockResponse()
@next = sinon.stub()
@user_id = "323123"
@req.session.user =
_id = @user_id
describe "deleteUser", ->
it "should delete the user", (done)->
user_id = "323123"
@req.session.user =
_id = user_id
@res.send = (code)=>
@UserDeleter.deleteUser.calledWith(user_id)
@UserDeleter.deleteUser.calledWith(@user_id)
code.should.equal 200
done()
@UserController.deleteUser @req, @res
describe "unsubscribe", ->
it "should send the user to unsubscribe", (done)->
@res.send = (code)=>
@NewsLetterManager.unsubscribe.calledWith(@user).should.equal true
done()
@UserController.unsubscribe @req, @res

View file

@ -14,8 +14,7 @@ describe "UserPagesController", ->
@user =
_id:"kwjewkl"
features:{}
@UserDeleter =
deleteUser: sinon.stub().callsArgWith(1)
@UserLocator =
findById: sinon.stub().callsArgWith(1, null, @user)
@dropboxStatus = {}