mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
moved unsubscribe endpoint to new user controller
This commit is contained in:
parent
d611984948
commit
bcfc1bee0c
5 changed files with 34 additions and 24 deletions
|
@ -1,4 +1,6 @@
|
||||||
UserDeleter = require("./UserDeleter")
|
UserDeleter = require("./UserDeleter")
|
||||||
|
UserLocator = require("./UserLocator")
|
||||||
|
newsLetterManager = require('../Newsletter/NewsletterManager')
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
|
||||||
|
@ -7,4 +9,9 @@ module.exports =
|
||||||
UserDeleter.deleteUser user_id, (err)->
|
UserDeleter.deleteUser user_id, (err)->
|
||||||
if !err?
|
if !err?
|
||||||
req.session.destroy()
|
req.session.destroy()
|
||||||
res.send(200)
|
res.send(200)
|
||||||
|
|
||||||
|
unsubscribe: (req, res)->
|
||||||
|
UserLocator.findById req.session.user._id, (err, user)->
|
||||||
|
newsLetterManager.unsubscribe user, ->
|
||||||
|
res.send()
|
|
@ -5,7 +5,6 @@ _ = require('underscore')
|
||||||
logger = require('logger-sharelatex')
|
logger = require('logger-sharelatex')
|
||||||
Security = require('../managers/SecurityManager')
|
Security = require('../managers/SecurityManager')
|
||||||
Settings = require('settings-sharelatex')
|
Settings = require('settings-sharelatex')
|
||||||
newsLetterManager = require('../Features/Newsletter/NewsletterManager')
|
|
||||||
dropboxHandler = require('../Features/Dropbox/DropboxHandler')
|
dropboxHandler = require('../Features/Dropbox/DropboxHandler')
|
||||||
userRegistrationHandler = require('../Features/User/UserRegistrationHandler')
|
userRegistrationHandler = require('../Features/User/UserRegistrationHandler')
|
||||||
metrics = require('../infrastructure/Metrics')
|
metrics = require('../infrastructure/Metrics')
|
||||||
|
@ -106,10 +105,7 @@ module.exports =
|
||||||
res.redirect '/login'
|
res.redirect '/login'
|
||||||
|
|
||||||
|
|
||||||
unsubscribe: (req, res)->
|
|
||||||
User.findById req.session.user._id, (err, user)->
|
|
||||||
newsLetterManager.unsubscribe user, ->
|
|
||||||
res.send()
|
|
||||||
|
|
||||||
apiUpdate : (req, res)->
|
apiUpdate : (req, res)->
|
||||||
logger.log user: req.session.user, "updating account settings"
|
logger.log user: req.session.user, "updating account settings"
|
||||||
|
@ -158,13 +154,3 @@ module.exports =
|
||||||
text:'Your old password is wrong'
|
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)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ module.exports = class Router
|
||||||
app.post '/user/password/update', AuthenticationController.requireLogin(), UserController.changePassword
|
app.post '/user/password/update', AuthenticationController.requireLogin(), UserController.changePassword
|
||||||
app.get '/user/passwordreset', UserPagesController.passwordResetPage
|
app.get '/user/passwordreset', UserPagesController.passwordResetPage
|
||||||
app.post '/user/passwordReset', UserController.doRequestPasswordReset
|
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.del '/user', AuthenticationController.requireLogin(), UserController_new.deleteUser
|
||||||
|
|
||||||
app.get '/dropbox/beginAuth', DropboxUserController.redirectUserToDropboxAuth
|
app.get '/dropbox/beginAuth', DropboxUserController.redirectUserToDropboxAuth
|
||||||
|
|
|
@ -11,28 +11,46 @@ ObjectId = require("mongojs").ObjectId
|
||||||
|
|
||||||
describe "UserController", ->
|
describe "UserController", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@user =
|
||||||
|
_id:"!@£!23123"
|
||||||
|
|
||||||
@UserDeleter =
|
@UserDeleter =
|
||||||
deleteUser: sinon.stub().callsArgWith(1)
|
deleteUser: sinon.stub().callsArgWith(1)
|
||||||
|
@UserLocator =
|
||||||
|
findById: sinon.stub().callsArgWith(1, null, @user)
|
||||||
|
@NewsLetterManager =
|
||||||
|
unsubscribe: sinon.stub().callsArgWith(1)
|
||||||
@UserController = SandboxedModule.require modulePath, requires:
|
@UserController = SandboxedModule.require modulePath, requires:
|
||||||
"./UserDeleter": @UserDeleter
|
"./UserDeleter": @UserDeleter
|
||||||
|
"./UserLocator": @UserLocator
|
||||||
|
'../Newsletter/NewsletterManager':@NewsLetterManager
|
||||||
"logger-sharelatex": {log:->}
|
"logger-sharelatex": {log:->}
|
||||||
|
|
||||||
|
|
||||||
@req = new MockRequest()
|
@req = new MockRequest()
|
||||||
@res = new MockResponse()
|
@res = new MockResponse()
|
||||||
@next = sinon.stub()
|
@next = sinon.stub()
|
||||||
|
@user_id = "323123"
|
||||||
|
@req.session.user =
|
||||||
|
_id = @user_id
|
||||||
describe "deleteUser", ->
|
describe "deleteUser", ->
|
||||||
|
|
||||||
it "should delete the user", (done)->
|
it "should delete the user", (done)->
|
||||||
user_id = "323123"
|
|
||||||
@req.session.user =
|
|
||||||
_id = user_id
|
|
||||||
@res.send = (code)=>
|
@res.send = (code)=>
|
||||||
@UserDeleter.deleteUser.calledWith(user_id)
|
@UserDeleter.deleteUser.calledWith(@user_id)
|
||||||
code.should.equal 200
|
code.should.equal 200
|
||||||
done()
|
done()
|
||||||
@UserController.deleteUser @req, @res
|
@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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,7 @@ describe "UserPagesController", ->
|
||||||
@user =
|
@user =
|
||||||
_id:"kwjewkl"
|
_id:"kwjewkl"
|
||||||
features:{}
|
features:{}
|
||||||
@UserDeleter =
|
|
||||||
deleteUser: sinon.stub().callsArgWith(1)
|
|
||||||
@UserLocator =
|
@UserLocator =
|
||||||
findById: sinon.stub().callsArgWith(1, null, @user)
|
findById: sinon.stub().callsArgWith(1, null, @user)
|
||||||
@dropboxStatus = {}
|
@dropboxStatus = {}
|
||||||
|
|
Loading…
Reference in a new issue