mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-06 03:27:39 +00:00
broken dropbox endpoints for user into its own controller
This commit is contained in:
parent
6891d1bfb5
commit
bc07525d71
4 changed files with 100 additions and 20 deletions
|
@ -0,0 +1,26 @@
|
|||
dropboxHandler = require('./DropboxHandler')
|
||||
logger = require('logger-sharelatex')
|
||||
|
||||
|
||||
module.exports =
|
||||
|
||||
redirectUserToDropboxAuth: (req, res, next)->
|
||||
user_id = req.session.user._id
|
||||
dropboxHandler.getDropboxRegisterUrl user_id, (err, url)->
|
||||
return next(err) if err?
|
||||
logger.log url:url, "redirecting user for dropbox auth"
|
||||
res.redirect url
|
||||
|
||||
completeDropboxRegistration: (req, res, next)->
|
||||
user_id = req.session.user._id
|
||||
dropboxHandler.completeRegistration user_id, (err, success)->
|
||||
return next(err) if err?
|
||||
res.redirect('/user/settings#dropboxSettings')
|
||||
|
||||
unlinkDropbox: (req, res, next)->
|
||||
user_id = req.session.user._id
|
||||
dropboxHandler.unlinkAccount user_id, (err, success)->
|
||||
return next(err) if err?
|
||||
res.redirect('/user/settings#dropboxSettings')
|
||||
|
||||
|
|
@ -198,24 +198,7 @@ module.exports =
|
|||
type:'error'
|
||||
text:'Your old password is wrong'
|
||||
|
||||
redirectUserToDropboxAuth: (req, res, next)->
|
||||
user_id = req.session.user._id
|
||||
dropboxHandler.getDropboxRegisterUrl user_id, (err, url)->
|
||||
return next(err) if err?
|
||||
logger.log url:url, "redirecting user for dropbox auth"
|
||||
res.redirect url
|
||||
|
||||
completeDropboxRegistration: (req, res, next)->
|
||||
user_id = req.session.user._id
|
||||
dropboxHandler.completeRegistration user_id, (err, success)->
|
||||
return next(err) if err?
|
||||
res.redirect('/user/settings#dropboxSettings')
|
||||
|
||||
unlinkDropbox: (req, res, next)->
|
||||
user_id = req.session.user._id
|
||||
dropboxHandler.unlinkAccount user_id, (err, success)->
|
||||
return next(err) if err?
|
||||
res.redirect('/user/settings#dropboxSettings')
|
||||
|
||||
deleteUser: (req, res)->
|
||||
user_id = req.session.user._id
|
||||
|
|
|
@ -31,6 +31,7 @@ HealthCheckController = require("./Features/HealthCheck/HealthCheckController")
|
|||
ProjectDownloadsController = require "./Features/Downloads/ProjectDownloadsController"
|
||||
FileStoreController = require("./Features/FileStore/FileStoreController")
|
||||
TrackChangesController = require("./Features/TrackChanges/TrackChangesController")
|
||||
DropboxUserController = require("./Features/Dropbox/DropboxUserController")
|
||||
logger = require("logger-sharelatex")
|
||||
_ = require("underscore")
|
||||
|
||||
|
@ -82,9 +83,9 @@ module.exports = class Router
|
|||
app.del '/user/newsletter/unsubscribe', AuthenticationController.requireLogin(), UserController.unsubscribe
|
||||
app.del '/user', AuthenticationController.requireLogin(), UserController.deleteUser
|
||||
|
||||
app.get '/dropbox/beginAuth', UserController.redirectUserToDropboxAuth
|
||||
app.get '/dropbox/completeRegistration', UserController.completeDropboxRegistration
|
||||
app.get '/dropbox/unlink', UserController.unlinkDropbox
|
||||
app.get '/dropbox/beginAuth', DropboxUserController.redirectUserToDropboxAuth
|
||||
app.get '/dropbox/completeRegistration', DropboxUserController.completeDropboxRegistration
|
||||
app.get '/dropbox/unlink', DropboxUserController.unlinkDropbox
|
||||
|
||||
app.get '/user/auth_token', AuthenticationController.requireLogin(), AuthenticationController.getAuthToken
|
||||
app.get '/user/personal_info', AuthenticationController.requireLogin(allow_auth_token: true), PersonalInfoController.getLoggedInUsersPersonalInfo
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
require('chai').should()
|
||||
sinon = require('sinon')
|
||||
modulePath = require('path').join __dirname, '../../../../app/js/Features/Dropbox/DropboxUserController.js'
|
||||
|
||||
|
||||
describe 'DropboxUserController', ->
|
||||
|
||||
beforeEach ->
|
||||
@DropboxHandler =
|
||||
getDropboxRegisterUrl: sinon.stub()
|
||||
completeRegistration: sinon.stub()
|
||||
unlinkAccount: sinon.stub()
|
||||
|
||||
@controller = SandboxedModule.require modulePath, requires:
|
||||
'./DropboxHandler': @DropboxHandler
|
||||
'logger-sharelatex':
|
||||
log:->
|
||||
err:->
|
||||
|
||||
@user_id = "23j21lk3j1312j321jkljkl"
|
||||
@req =
|
||||
session:
|
||||
user:
|
||||
_id: @user_id
|
||||
@res = {}
|
||||
|
||||
describe "redirectUserToDropboxAuth", ->
|
||||
beforeEach ->
|
||||
@dropboxUrl = "www.dropbox.com"
|
||||
@DropboxHandler.getDropboxRegisterUrl.callsArgWith(1, null, @dropboxUrl)
|
||||
|
||||
it "should call getDropboxRegisterUrl with the user id", (done)->
|
||||
|
||||
@res.redirect = (redirectUrl)=>
|
||||
redirectUrl.should.equal @dropboxUrl
|
||||
@DropboxHandler.getDropboxRegisterUrl.calledWith(@user_id).should.equal true
|
||||
done()
|
||||
|
||||
@controller.redirectUserToDropboxAuth @req, @res
|
||||
|
||||
describe "completeDropboxRegistration", ->
|
||||
beforeEach ->
|
||||
@DropboxHandler.completeRegistration.callsArgWith(1)
|
||||
|
||||
it "should call getDropboxRegisterUrl with the user id", (done)->
|
||||
|
||||
@res.redirect = (redirectUrl)=>
|
||||
redirectUrl.should.equal "/user/settings#dropboxSettings"
|
||||
@DropboxHandler.completeRegistration.calledWith(@user_id).should.equal true
|
||||
done()
|
||||
|
||||
@controller.completeDropboxRegistration @req, @res
|
||||
|
||||
|
||||
describe "unlinkDropbox", ->
|
||||
|
||||
beforeEach ->
|
||||
@DropboxHandler.unlinkAccount.callsArgWith(1)
|
||||
|
||||
it "should call getDropboxRegisterUrl with the user id", (done)->
|
||||
|
||||
@res.redirect = (redirectUrl)=>
|
||||
redirectUrl.should.equal "/user/settings#dropboxSettings"
|
||||
@DropboxHandler.unlinkAccount.calledWith(@user_id).should.equal true
|
||||
done()
|
||||
|
||||
@controller.unlinkDropbox @req, @res
|
||||
|
Loading…
Add table
Reference in a new issue