mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Remove Dropbox front end logic from main sharelatex repo
This commit is contained in:
parent
f75376124e
commit
6c387edbe2
26 changed files with 23 additions and 710 deletions
|
@ -1,81 +0,0 @@
|
|||
request = require('request')
|
||||
settings = require('settings-sharelatex')
|
||||
logger = require('logger-sharelatex')
|
||||
Project = require('../../models/Project').Project
|
||||
projectEntityHandler = require '../Project/ProjectEntityHandler'
|
||||
_ = require('underscore')
|
||||
async = require('async')
|
||||
|
||||
module.exports =
|
||||
|
||||
getUserRegistrationStatus: (user_id, callback)->
|
||||
logger.log user_id:user_id, "getting dropbox registration status from tpds"
|
||||
opts =
|
||||
url : "#{settings.apis.thirdPartyDataStore.url}/user/#{user_id}/dropbox/status"
|
||||
timeout: 5000
|
||||
request.get opts, (err, response, body)->
|
||||
safelyGetResponse err, response, body, (err, body)->
|
||||
if err?
|
||||
logger.err err:err, response:response, "getUserRegistrationStatus problem"
|
||||
return callback err
|
||||
logger.log status:body, "getting dropbox registration status for user #{user_id}"
|
||||
callback err, body
|
||||
|
||||
getDropboxRegisterUrl: (user_id, callback)->
|
||||
opts =
|
||||
url: "#{settings.apis.thirdPartyDataStore.url}/user/#{user_id}/dropbox/register"
|
||||
timeout: 5000
|
||||
request.get opts, (err, response, body)->
|
||||
safelyGetResponse err, response, body, (err, body)->
|
||||
if err?
|
||||
logger.err err:err, response:response, "getUserRegistrationStatus problem"
|
||||
return callback err
|
||||
url = "#{body.authorize_url}&oauth_callback=#{settings.siteUrl}/dropbox/completeRegistration"
|
||||
logger.log user_id:user_id, url:url, "starting dropbox register"
|
||||
callback err, url
|
||||
|
||||
completeRegistration: (user_id, callback)->
|
||||
opts =
|
||||
url: "#{settings.apis.thirdPartyDataStore.url}/user/#{user_id}/dropbox/getaccesstoken"
|
||||
timeout: 5000
|
||||
request.get opts, (err, response, body)=>
|
||||
safelyGetResponse err, response, body, (err, body)=>
|
||||
if err?
|
||||
logger.err err:err, response:response, "getUserRegistrationStatus problem"
|
||||
return callback err
|
||||
success = body.success
|
||||
logger.log user_id:user_id, success:body.success, "completing dropbox register"
|
||||
if success
|
||||
@flushUsersProjectToDropbox user_id
|
||||
callback err, body.success
|
||||
|
||||
|
||||
unlinkAccount: (user_id, callback)->
|
||||
opts =
|
||||
url: "#{settings.apis.thirdPartyDataStore.url}/user/#{user_id}/dropbox"
|
||||
timeout: 5000
|
||||
request.del opts, (err, response, body)=>
|
||||
callback(err)
|
||||
|
||||
flushUsersProjectToDropbox: (user_id, callback)->
|
||||
Project.findAllUsersProjects user_id, '_id', (err, projects = [], collabertions = [], readOnlyProjects = [])->
|
||||
projectList = []
|
||||
projectList = projectList.concat(projects)
|
||||
projectList = projectList.concat(collabertions)
|
||||
projectList = projectList.concat(readOnlyProjects)
|
||||
projectIds = _.pluck(projectList, "_id")
|
||||
logger.log projectIds:projectIds, user_id:user_id, "flushing all a users projects to tpds"
|
||||
jobs = projectIds.map (project_id)->
|
||||
return (cb)->
|
||||
projectEntityHandler.flushProjectToThirdPartyDataStore project_id, cb
|
||||
async.series jobs, callback
|
||||
|
||||
safelyGetResponse = (err, res, body, callback)->
|
||||
statusCode = if res? then res.statusCode else 500
|
||||
if err? or statusCode != 200
|
||||
e = new Error("something went wrong getting response from dropbox, #{err}, #{statusCode}")
|
||||
logger.err err:err
|
||||
callback(e, [])
|
||||
else
|
||||
body = JSON.parse body
|
||||
callback(null, body)
|
|
@ -1,12 +0,0 @@
|
|||
DropboxHandler = require "./DropboxHandler"
|
||||
ProjectGetter = require "../Project/ProjectGetter"
|
||||
|
||||
module.exports = DropboxProjectController =
|
||||
getStatus: (req, res, next) ->
|
||||
project_id = req.params.Project_id
|
||||
ProjectGetter.getProject project_id, {owner_ref: 1}, (error, project) ->
|
||||
return next(error) if error?
|
||||
DropboxHandler.getUserRegistrationStatus project.owner_ref, (error, status) ->
|
||||
return next(error) if error?
|
||||
res.json status
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
DropboxUserController = require './DropboxUserController'
|
||||
DropboxWebhookController = require './DropboxWebhookController'
|
||||
DropboxProjectController = require "./DropboxProjectController"
|
||||
SecurityManager = require "../../managers/SecurityManager"
|
||||
|
||||
module.exports =
|
||||
apply: (app) ->
|
||||
app.get '/dropbox/beginAuth', DropboxUserController.redirectUserToDropboxAuth
|
||||
app.get '/dropbox/completeRegistration', DropboxUserController.completeDropboxRegistration
|
||||
app.get '/dropbox/unlink', DropboxUserController.unlinkDropbox
|
||||
|
||||
app.get '/dropbox/webhook', DropboxWebhookController.verify
|
||||
app.post '/dropbox/webhook', DropboxWebhookController.webhook
|
||||
app.ignoreCsrf('post', '/dropbox/webhook')
|
||||
|
||||
app.get '/project/:Project_id/dropbox/status', SecurityManager.requestIsOwner, DropboxProjectController.getStatus
|
||||
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
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')
|
||||
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
logger = require("logger-sharelatex")
|
||||
DropboxWebhookHandler = require("./DropboxWebhookHandler")
|
||||
|
||||
module.exports = DropboxWebhookController =
|
||||
verify: (req, res, next = (error) ->) ->
|
||||
res.send(req.query.challenge)
|
||||
req.session.destroy()
|
||||
|
||||
webhook: (req, res, next = (error) ->) ->
|
||||
dropbox_uids = req.body?.delta?.users
|
||||
logger.log dropbox_uids: dropbox_uids, "received webhook request from Dropbox"
|
||||
if !dropbox_uids?
|
||||
return res.send(400) # Bad Request
|
||||
|
||||
# Do this in the background so as not to keep Dropbox waiting
|
||||
DropboxWebhookHandler.pollDropboxUids dropbox_uids, (error) ->
|
||||
if error?
|
||||
logger.error err: error, dropbox_uids: dropbox_uids, "error in webhook"
|
||||
|
||||
res.send(200)
|
||||
req.session.destroy()
|
|
@ -1,48 +0,0 @@
|
|||
logger = require("logger-sharelatex")
|
||||
settings = require("settings-sharelatex")
|
||||
async = require "async"
|
||||
User = require("../../models/User").User
|
||||
TpdsUpdateSender = require "../ThirdPartyDataStore/TpdsUpdateSender"
|
||||
|
||||
redis = require("redis-sharelatex")
|
||||
rclient = redis.createClient(settings.redis.web)
|
||||
|
||||
module.exports = DropboxWebhookHandler =
|
||||
pollDropboxUids: (dropbox_uids, callback = (error) ->) ->
|
||||
jobs = []
|
||||
for uid in dropbox_uids
|
||||
do (uid) ->
|
||||
jobs.push (callback) ->
|
||||
DropboxWebhookHandler.pollDropboxUid uid, callback
|
||||
async.series jobs, callback
|
||||
|
||||
pollDropboxUid: (dropbox_uid, callback = (error) ->) ->
|
||||
DropboxWebhookHandler._delayAndBatchPoll dropbox_uid, (error, shouldPoll) ->
|
||||
return callback(error) if error?
|
||||
return callback() if !shouldPoll
|
||||
User.find {
|
||||
"dropbox.access_token.uid": dropbox_uid.toString()
|
||||
"features.dropbox": true
|
||||
}, (error, users = []) ->
|
||||
return callback(error) if error?
|
||||
user = users[0]
|
||||
if !user?
|
||||
logger.log dropbox_uid: dropbox_uid, "no sharelatex user found"
|
||||
return callback()
|
||||
TpdsUpdateSender.pollDropboxForUser user._id, callback
|
||||
|
||||
POLL_DELAY_IN_MS: 5000 # 5 seconds
|
||||
_delayAndBatchPoll: (dropbox_uid, callback = (error, shouldPoll) ->) ->
|
||||
rclient.set(
|
||||
"dropbox-poll-lock:#{dropbox_uid}", "LOCK",
|
||||
"PX", DropboxWebhookHandler.POLL_DELAY_IN_MS,
|
||||
"NX",
|
||||
(error, gotLock) ->
|
||||
return callback(error) if error?
|
||||
if gotLock
|
||||
setTimeout () ->
|
||||
callback(null, true)
|
||||
, DropboxWebhookHandler.POLL_DELAY_IN_MS
|
||||
else
|
||||
callback(null, false)
|
||||
)
|
|
@ -151,9 +151,6 @@ module.exports = EditorController =
|
|||
return {_id:doc._id, path:path.substring(1)}
|
||||
callback(null, docList)
|
||||
|
||||
forceResyncOfDropbox: (project_id, callback)->
|
||||
ProjectEntityHandler.flushProjectToThirdPartyDataStore project_id, callback
|
||||
|
||||
notifyUsersProjectHasBeenDeletedOrRenamed: (project_id, callback)->
|
||||
EditorRealTimeController.emitToRoom(project_id, 'projectRenamedOrDeletedByExternalSource')
|
||||
callback()
|
||||
|
|
|
@ -6,7 +6,7 @@ logger = require('logger-sharelatex')
|
|||
SubscriptionUpdater = require("./SubscriptionUpdater")
|
||||
LimitationsManager = require('./LimitationsManager')
|
||||
EmailHandler = require("../Email/EmailHandler")
|
||||
DropboxHandler = require("../Dropbox/DropboxHandler")
|
||||
Events = require "../../infrastructure/Events"
|
||||
|
||||
module.exports =
|
||||
|
||||
|
@ -52,8 +52,8 @@ module.exports =
|
|||
ONE_HOUR_IN_MS = 1000 * 60 * 60
|
||||
setTimeout (-> EmailHandler.sendEmail "canceledSubscription", emailOpts
|
||||
), ONE_HOUR_IN_MS
|
||||
DropboxHandler.unlinkAccount user._id, ->
|
||||
callback()
|
||||
Events.emit "cancelSubscription", user._id
|
||||
callback()
|
||||
else
|
||||
callback()
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
UserLocator = require("./UserLocator")
|
||||
dropboxHandler = require('../Dropbox/DropboxHandler')
|
||||
logger = require("logger-sharelatex")
|
||||
Settings = require("settings-sharelatex")
|
||||
fs = require('fs')
|
||||
|
@ -27,14 +26,12 @@ module.exports =
|
|||
title: 'login',
|
||||
redir: req.query.redir
|
||||
|
||||
settingsPage : (req, res)->
|
||||
settingsPage : (req, res, next)->
|
||||
logger.log user: req.session.user, "loading settings page"
|
||||
UserLocator.findById req.session.user._id, (err, user)->
|
||||
dropboxHandler.getUserRegistrationStatus user._id, (err, status)->
|
||||
userIsRegisteredWithDropbox = !err? and status.registered
|
||||
res.render 'user/settings',
|
||||
title:'account_settings'
|
||||
userIsRegisteredWithDropbox: userIsRegisteredWithDropbox
|
||||
user: user,
|
||||
languages: Settings.languages,
|
||||
accountSettingsTabActive: true
|
||||
return next(err) if err?
|
||||
res.render 'user/settings',
|
||||
title:'account_settings'
|
||||
user: user,
|
||||
languages: Settings.languages,
|
||||
accountSettingsTabActive: true
|
||||
|
|
2
services/web/app/coffee/infrastructure/Events.coffee
Normal file
2
services/web/app/coffee/infrastructure/Events.coffee
Normal file
|
@ -0,0 +1,2 @@
|
|||
events = require "events"
|
||||
module.exports = new events.EventEmitter()
|
|
@ -157,5 +157,6 @@ module.exports = (app)->
|
|||
if Settings.reloadModuleViewsOnEachRequest
|
||||
Modules.loadViewIncludes()
|
||||
res.locals.moduleIncludes = Modules.moduleIncludes
|
||||
res.locals.moduleIncludesAvailable = Modules.moduleIncludesAvailable
|
||||
next()
|
||||
|
||||
|
|
|
@ -32,5 +32,8 @@ module.exports = Modules =
|
|||
compiler = jade.compile(partial, doctype: "html")
|
||||
html += compiler(locals)
|
||||
return html
|
||||
|
||||
moduleIncludesAvailable: (view) ->
|
||||
return (Modules.viewIncludes[view] or []).length > 0
|
||||
|
||||
Modules.loadModules()
|
|
@ -33,8 +33,6 @@ StaticPagesRouter = require("./Features/StaticPages/StaticPagesRouter")
|
|||
ChatController = require("./Features/Chat/ChatController")
|
||||
BlogController = require("./Features/Blog/BlogController")
|
||||
WikiController = require("./Features/Wiki/WikiController")
|
||||
DropboxRouter = require "./Features/Dropbox/DropboxRouter"
|
||||
dropboxHandler = require "./Features/Dropbox/DropboxHandler"
|
||||
Modules = require "./infrastructure/Modules"
|
||||
RateLimiterMiddlewear = require('./Features/Security/RateLimiterMiddlewear')
|
||||
|
||||
|
@ -66,7 +64,6 @@ module.exports = class Router
|
|||
PasswordResetRouter.apply(app)
|
||||
StaticPagesRouter.apply(app)
|
||||
TemplatesRouter.apply(app)
|
||||
DropboxRouter.apply(app)
|
||||
|
||||
Modules.applyRouter(app)
|
||||
|
||||
|
@ -190,16 +187,6 @@ module.exports = class Router
|
|||
), 10000
|
||||
req.session.destroy()
|
||||
|
||||
app.get '/test', (req, res) ->
|
||||
res.render "tests",
|
||||
privilegeLevel: "owner"
|
||||
project:
|
||||
name: "test"
|
||||
date: Date.now()
|
||||
layout: false
|
||||
userCanSeeDropbox: true
|
||||
languages: []
|
||||
|
||||
app.get "/ip", (req, res, next) ->
|
||||
res.send({
|
||||
ip: req.ip
|
||||
|
|
|
@ -56,7 +56,6 @@ block content
|
|||
include ./editor/binary-file
|
||||
include ./editor/track-changes
|
||||
include ./editor/publish-template
|
||||
include ./editor/dropbox
|
||||
|
||||
.ui-layout-east
|
||||
include ./editor/chat
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
script(type="text/ng-template", id="dropboxModalTemplate")
|
||||
.modal-header
|
||||
button.close(
|
||||
type="button"
|
||||
data-dismiss="modal"
|
||||
ng-click="cancel()"
|
||||
) ×
|
||||
h3 #{translate("dropbox_sync")}
|
||||
.modal-body.modal-body-share
|
||||
|
||||
div(ng-show="dbState.gotLinkStatus")
|
||||
div(ng-hide="dbState.userIsLinkedToDropbox || !dbState.hasDropboxFeature")
|
||||
|
||||
span(ng-hide="dbState.startedLinkProcess") #{translate("account_not_linked_to_dropbox")}
|
||||
|
|
||||
a(ng-click="linkToDropbox()").btn.btn-info #{translate("update_dropbox_settings")}
|
||||
|
||||
p.small.text-center(ng-show="dbState.startedLinkProcess")
|
||||
| #{translate("refresh_page_after_starting_free_trial")}
|
||||
|
||||
|
||||
div(ng-show="dbState.hasDropboxFeature && dbState.userIsLinkedToDropbox")
|
||||
p.small
|
||||
| #{translate("this_project_will_appear_in_your_dropbox_folder_at")}
|
||||
strong Dropbox/sharelatex/{{ project.name }}
|
||||
div.text-center(ng-hide="dbState.hasDropboxFeature")
|
||||
p #{translate("need_to_upgrade_for_dropbox")}
|
||||
p(ng-controller="FreeTrialModalController")
|
||||
a.btn(ng-click="startFreeTrial('dropbox')", ng-class="buttonClass") #{translate("start_free_trial")}
|
||||
p.small(ng-show="startedFreeTrial")
|
||||
| #{translate("refresh_page_after_starting_free_trial")}
|
||||
|
||||
div(ng-hide="dbState.gotLinkStatus")
|
||||
i.fa.fa-refresh.fa-spin
|
||||
span.small #{translate("checking_dropbox_status")}
|
||||
|
||||
.modal-footer()
|
||||
button.btn.btn-default(
|
||||
ng-click="cancel()",
|
||||
)
|
||||
span #{translate("dismiss")}
|
|
@ -46,16 +46,10 @@ aside#left-menu.full-size(
|
|||
i.fa.fa-external-link.fa-fw
|
||||
| #{translate("publish_as_template")}
|
||||
|
||||
div(ng-show="!anonymous")
|
||||
h4() #{translate("sync")}
|
||||
span(ng-controller="DropboxController")
|
||||
ul.list-unstyled.nav()
|
||||
li
|
||||
a(ng-click="openDropboxModal()")
|
||||
i.fa.fa-dropbox.fa-fw
|
||||
| Dropbox
|
||||
|
||||
!{moduleIncludes("editorLeftMenu", locals)}
|
||||
if (moduleIncludesAvailable("editorLeftMenu:sync"))
|
||||
div(ng-show="!anonymous")
|
||||
h4() #{translate("sync")}
|
||||
!{moduleIncludes("editorLeftMenu:sync", locals)}
|
||||
|
||||
h4(ng-show="!anonymous") #{translate("settings")}
|
||||
form.settings(ng-controller="SettingsController", ng-show="!anonymous")
|
||||
|
|
|
@ -96,27 +96,6 @@ block content
|
|||
ng-disabled="changePasswordForm.$invalid"
|
||||
) #{translate("change")}
|
||||
|
||||
hr
|
||||
|
||||
h3 #{translate("dropbox_integration")}
|
||||
span.small
|
||||
a(href='/help/kb/dropbox-2') (#{translate("learn_more")})
|
||||
- if(!user.features.dropbox)
|
||||
p.small #{translate("dropbox_sync_description")}
|
||||
.alert.alert-info
|
||||
p #{translate("dropbox_is_premium")}
|
||||
p
|
||||
a.btn.btn-info(href='/user/subscription/plans') #{translate("upgrade")}
|
||||
- else if(userIsRegisteredWithDropbox)
|
||||
.alert.alert-success
|
||||
| #{translate("account_is_linked")}.
|
||||
|
|
||||
a(href='/dropbox/unlink') #{translate("unlink_dropbox")}
|
||||
- else
|
||||
p.small #{translate("dropbox_sync_description")}
|
||||
p
|
||||
a.btn.btn-info(href='/dropbox/beginAuth') #{translate("link_to_dropbox")}
|
||||
|
||||
| !{moduleIncludes("userSettings", locals)}
|
||||
|
||||
hr
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
define [
|
||||
"base"
|
||||
"ide/permissions/PermissionsManager"
|
||||
], (App, PermissionsManager) ->
|
||||
|
||||
POLLING_INTERVAL = 15
|
||||
ONE_MIN_MILI = 1000 * 60
|
||||
|
||||
cachedState =
|
||||
gotLinkStatus: false
|
||||
startedLinkProcess: false
|
||||
userIsLinkedToDropbox: false
|
||||
hasDropboxFeature: false
|
||||
|
||||
|
||||
App.controller "DropboxController", ($scope, $modal, ide) ->
|
||||
$scope.openDropboxModal = () ->
|
||||
|
||||
$modal.open {
|
||||
templateUrl: "dropboxModalTemplate"
|
||||
controller: "DropboxModalController"
|
||||
scope:$scope
|
||||
}
|
||||
|
||||
App.controller "DropboxModalController", ($scope, $modalInstance, ide, $timeout, $http) ->
|
||||
user_id = ide.$scope.user.id
|
||||
|
||||
$scope.dbState = cachedState
|
||||
$scope.dbState.hasDropboxFeature = $scope.project.features.dropbox
|
||||
|
||||
$http.get("/project/#{ide.project_id}/dropbox/status")
|
||||
.success (status) ->
|
||||
$scope.dbState.gotLinkStatus = true
|
||||
if status.registered
|
||||
$scope.dbState.userIsLinkedToDropbox = true
|
||||
cachedState = $scope.dbState
|
||||
|
||||
$scope.linkToDropbox = ->
|
||||
window.open("/user/settings#dropboxSettings")
|
||||
$scope.startedLinkProcess = true
|
||||
|
||||
$scope.cancel = () ->
|
||||
$modalInstance.dismiss()
|
|
@ -1,4 +0,0 @@
|
|||
define [
|
||||
"ide/dropbox/controllers/DropboxController"
|
||||
], () ->
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
require('chai').should()
|
||||
sinon = require('sinon')
|
||||
modulePath = require('path').join __dirname, '../../../../app/js/Features/Dropbox/DropboxHandler.js'
|
||||
|
||||
thirdPartyDataStoreApiUrl = "http://third-party-json-store.herokuapp.com"
|
||||
siteUrl = "www.sharelatex.com"
|
||||
|
||||
describe 'third party data store', ->
|
||||
user_id = "123nd3ijdks"
|
||||
|
||||
beforeEach ->
|
||||
@stubGet = sinon.stub()
|
||||
@stubDel = sinon.stub()
|
||||
@projectEntityHandler = flushProjectToThirdPartyDataStore:sinon.stub().callsArgWith(1)
|
||||
@projectModel = findAllUsersProjects : sinon.stub()
|
||||
@handler = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex": {siteUrl:siteUrl, apis: {thirdPartyDataStore: {url: thirdPartyDataStoreApiUrl}}}
|
||||
"../../models/Project":{Project:@projectModel}
|
||||
'../Project/ProjectEntityHandler':@projectEntityHandler
|
||||
"request":
|
||||
get:@stubGet
|
||||
del: @stubDel
|
||||
'logger-sharelatex':
|
||||
log:->
|
||||
err:->
|
||||
|
||||
|
||||
it 'should be able to get userStatus', (done)->
|
||||
body = JSON.stringify({registered:true})
|
||||
opts =
|
||||
url: "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/dropbox/status"
|
||||
timeout: 5000
|
||||
@stubGet.withArgs(opts).callsArgWith(1, null, {statusCode:200}, body)
|
||||
@handler.getUserRegistrationStatus user_id, (err, status)->
|
||||
status.registered.should.equal true
|
||||
done()
|
||||
|
||||
it 'should be able to get auth url with callback url on it', (done)->
|
||||
url = "http://www.dropbox.com"
|
||||
body = JSON.stringify({authorize_url:url})
|
||||
opts =
|
||||
url: "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/dropbox/register"
|
||||
timeout: 5000
|
||||
@stubGet.withArgs(opts).callsArgWith(1, null, {statusCode:200}, body)
|
||||
@handler.getDropboxRegisterUrl user_id, (err, returnedUrl)->
|
||||
returnedUrl.should.equal "#{url}&oauth_callback=#{siteUrl}/dropbox/completeRegistration"
|
||||
done()
|
||||
|
||||
it 'should be able to complete registration and get getAccessToken from dropbox', (done)->
|
||||
body = JSON.stringify({success:true})
|
||||
opts =
|
||||
url: "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/dropbox/getaccesstoken"
|
||||
timeout: 5000
|
||||
@stubGet.withArgs(opts).callsArgWith(1, null, {statusCode:200}, body)
|
||||
@handler.flushUsersProjectToDropbox = sinon.stub()
|
||||
@handler.completeRegistration user_id, (err, successful)=>
|
||||
@handler.flushUsersProjectToDropbox.called.should.equal true
|
||||
successful.should.equal true
|
||||
done()
|
||||
|
||||
it 'should tell the tpds to unlink the account', (done)->
|
||||
opts =
|
||||
url: "#{thirdPartyDataStoreApiUrl}/user/#{user_id}/dropbox"
|
||||
timeout: 5000
|
||||
@stubDel.callsArgWith(1, null, {statusCode:200})
|
||||
@handler.unlinkAccount user_id, (err)=>
|
||||
@stubDel.calledWith(opts).should.equal true
|
||||
done()
|
||||
|
||||
it 'should tell the project entity handler to flush project to tpds', (done)->
|
||||
user_id = "123u9oijllkj"
|
||||
projectList = [{_id:"123lk"}, {_id:"12ji3ojio"}, {_id:"2jiojdoi"}]
|
||||
collabProjectList = [{_id:"213ds"}]
|
||||
@projectModel.findAllUsersProjects.callsArgWith(2, null, projectList, collabProjectList)
|
||||
@handler.flushUsersProjectToDropbox user_id, =>
|
||||
@projectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(projectList[0]._id).should.equal true
|
||||
@projectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(projectList[1]._id).should.equal true
|
||||
@projectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(projectList[2]._id).should.equal true
|
||||
@projectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(collabProjectList[0]._id).should.equal true
|
||||
done()
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
require('chai').should()
|
||||
sinon = require('sinon')
|
||||
modulePath = require('path').join __dirname, '../../../../app/js/Features/Dropbox/DropboxProjectController.js'
|
||||
|
||||
describe 'DropboxProjectController', ->
|
||||
beforeEach ->
|
||||
@DropboxProjectController = SandboxedModule.require modulePath, requires:
|
||||
'./DropboxHandler': @DropboxHandler = {}
|
||||
'../Project/ProjectGetter': @ProjectGetter = {}
|
||||
'logger-sharelatex':
|
||||
log:->
|
||||
err:->
|
||||
|
||||
@project_id = "project-id-123"
|
||||
@user_id = "user-id-123"
|
||||
@req = {}
|
||||
@res =
|
||||
json: sinon.stub()
|
||||
|
||||
describe "getStatus", ->
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
Project_id: @project_id
|
||||
@ProjectGetter.getProject = sinon.stub().callsArgWith(2, null, { owner_ref: @user_id })
|
||||
@DropboxHandler.getUserRegistrationStatus = sinon.stub().callsArgWith(1, null, @status = {"mock": "status"})
|
||||
@DropboxProjectController.getStatus @req, @res
|
||||
|
||||
it "should look up the project owner", ->
|
||||
@ProjectGetter.getProject
|
||||
.calledWith(@project_id, {owner_ref: 1})
|
||||
.should.equal true
|
||||
|
||||
it "should get the owner's Dropbox status", ->
|
||||
@DropboxHandler.getUserRegistrationStatus
|
||||
.calledWith(@user_id)
|
||||
.should.equal true
|
||||
|
||||
it "should send the status to the client", ->
|
||||
@res.json.calledWith(@status).should.equal true
|
|
@ -1,70 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
require('chai').should()
|
||||
sinon = require('sinon')
|
||||
modulePath = require('path').join __dirname, '../../../../app/js/Features/Dropbox/DropboxWebhookController.js'
|
||||
|
||||
describe 'DropboxWebhookController', ->
|
||||
beforeEach ->
|
||||
@req =
|
||||
session:
|
||||
destroy: ->
|
||||
|
||||
@DropboxWebhookController = SandboxedModule.require modulePath, requires:
|
||||
"./DropboxWebhookHandler": @DropboxWebhookHandler = {}
|
||||
'logger-sharelatex':
|
||||
log:->
|
||||
err:->
|
||||
|
||||
describe "verify", ->
|
||||
beforeEach ->
|
||||
@res =
|
||||
send: sinon.stub()
|
||||
@req.query =
|
||||
challenge: @challenge = "foo"
|
||||
@DropboxWebhookController.verify(@req, @res)
|
||||
|
||||
it "should echo the challenge parameter back", ->
|
||||
@res.send.calledWith(@challenge).should.equal true
|
||||
|
||||
describe "webhook", ->
|
||||
beforeEach ->
|
||||
@req.body =
|
||||
delta:
|
||||
users: @dropbox_uids = [
|
||||
"123456",
|
||||
"789123"
|
||||
]
|
||||
@res.send = sinon.stub()
|
||||
@DropboxWebhookHandler.pollDropboxUids = sinon.stub().callsArg(1)
|
||||
@DropboxWebhookController.webhook(@req, @res)
|
||||
|
||||
it "should poll the Dropbox uids", ->
|
||||
@DropboxWebhookHandler.pollDropboxUids
|
||||
.calledWith(@dropbox_uids)
|
||||
.should.equal true
|
||||
|
||||
it "should return success", ->
|
||||
@res.send
|
||||
.calledWith(200)
|
||||
.should.equal true
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
require('chai').should()
|
||||
expect = require("chai").expect
|
||||
sinon = require('sinon')
|
||||
modulePath = require('path').join __dirname, '../../../../app/js/Features/Dropbox/DropboxWebhookHandler.js'
|
||||
|
||||
describe 'DropboxWebhookHandler', ->
|
||||
beforeEach ->
|
||||
@DropboxWebhookHandler = SandboxedModule.require modulePath, requires:
|
||||
"../../models/User": User: @User = {}
|
||||
"../ThirdPartyDataStore/TpdsUpdateSender": @TpdsUpdateSender = {}
|
||||
"redis-sharelatex":
|
||||
createClient: () => @rclient =
|
||||
auth: sinon.stub()
|
||||
'settings-sharelatex': redis: web: {}
|
||||
'logger-sharelatex':
|
||||
log:->
|
||||
err:->
|
||||
@callback = sinon.stub()
|
||||
|
||||
describe "pollDropboxUids", ->
|
||||
beforeEach (done) ->
|
||||
@dropbox_uids = [
|
||||
"123456",
|
||||
"789123"
|
||||
]
|
||||
@DropboxWebhookHandler.pollDropboxUid = sinon.stub().callsArg(1)
|
||||
@DropboxWebhookHandler.pollDropboxUids @dropbox_uids, done
|
||||
|
||||
it "should call pollDropboxUid for each uid", ->
|
||||
for uid in @dropbox_uids
|
||||
@DropboxWebhookHandler.pollDropboxUid
|
||||
.calledWith(uid)
|
||||
.should.equal true
|
||||
|
||||
describe "pollDropboxUid", ->
|
||||
beforeEach ->
|
||||
@dropbox_uid = "dropbox-123456"
|
||||
@user_id = "sharelatex-user-id"
|
||||
@User.find = sinon.stub().callsArgWith(1, null, [ _id: @user_id ])
|
||||
@TpdsUpdateSender.pollDropboxForUser = sinon.stub().callsArg(1)
|
||||
|
||||
describe "when there is already a poll in progress", () ->
|
||||
beforeEach ->
|
||||
@DropboxWebhookHandler._delayAndBatchPoll = sinon.stub().callsArgWith(1, null, false)
|
||||
@DropboxWebhookHandler.pollDropboxUid @dropbox_uid, @callback
|
||||
|
||||
it "should not go ahead with the poll", ->
|
||||
@TpdsUpdateSender.pollDropboxForUser.called.should.equal false
|
||||
|
||||
describe "when we are the one to do the delayed poll", () ->
|
||||
beforeEach ->
|
||||
@DropboxWebhookHandler._delayAndBatchPoll = sinon.stub().callsArgWith(1, null, true)
|
||||
@DropboxWebhookHandler.pollDropboxUid @dropbox_uid, @callback
|
||||
|
||||
it "should look up the user", ->
|
||||
@User.find
|
||||
.calledWith({ "dropbox.access_token.uid": @dropbox_uid, "features.dropbox": true })
|
||||
.should.equal true
|
||||
|
||||
it "should poll the user's Dropbox", ->
|
||||
@TpdsUpdateSender.pollDropboxForUser
|
||||
.calledWith(@user_id)
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback", ->
|
||||
@callback.called.should.equal true
|
||||
|
||||
describe "_delayAndBatchPoll", () ->
|
||||
beforeEach ->
|
||||
@dropbox_uid = "dropbox-uid-123"
|
||||
@DropboxWebhookHandler.POLL_DELAY_IN_MS = 100
|
||||
|
||||
describe "when no one else is polling yet", ->
|
||||
beforeEach (done) ->
|
||||
@rclient.set = sinon.stub().callsArgWith(5, null, "OK")
|
||||
@start = Date.now()
|
||||
@DropboxWebhookHandler._delayAndBatchPoll @dropbox_uid, (error, @shouldPoll) =>
|
||||
@end = Date.now()
|
||||
done()
|
||||
|
||||
it "should set the lock", ->
|
||||
@rclient.set
|
||||
.calledWith("dropbox-poll-lock:#{@dropbox_uid}", "LOCK", "PX", @DropboxWebhookHandler.POLL_DELAY_IN_MS, "NX")
|
||||
.should.equal true
|
||||
|
||||
it "should return the callback after the delay with shouldPoll=true", ->
|
||||
@shouldPoll.should.equal true
|
||||
expect(@end - @start).to.be.at.least(@DropboxWebhookHandler.POLL_DELAY_IN_MS)
|
||||
|
||||
describe "when someone else is already polling", ->
|
||||
beforeEach ->
|
||||
@rclient.set = sinon.stub().callsArgWith(5, null, null)
|
||||
@DropboxWebhookHandler._delayAndBatchPoll @dropbox_uid, @callback
|
||||
|
||||
it "should return the callback immediately with shouldPoll=false", ->
|
||||
@callback.calledWith(null, false).should.equal true
|
||||
|
|
@ -512,13 +512,6 @@ describe "EditorController", ->
|
|||
returnedDocs[1].path.should.equal "doc2.tex"
|
||||
done()
|
||||
|
||||
describe "forceResyncOfDropbox", ->
|
||||
it 'should tell the project entity handler to flush to tpds', (done)->
|
||||
@ProjectEntityHandler.flushProjectToThirdPartyDataStore = sinon.stub().callsArgWith(1)
|
||||
@EditorController.forceResyncOfDropbox @project_id, (err)=>
|
||||
@ProjectEntityHandler.flushProjectToThirdPartyDataStore.calledWith(@project_id).should.equal true
|
||||
done()
|
||||
|
||||
describe "notifyUsersProjectHasBeenDeletedOrRenamed", ->
|
||||
it 'should emmit a message to all users in a project', (done)->
|
||||
@EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
|
|
|
@ -66,6 +66,7 @@ describe "Subscription Handler sanboxed", ->
|
|||
'./LimitationsManager':@LimitationsManager
|
||||
"../Email/EmailHandler":@EmailHandler
|
||||
"../Dropbox/DropboxHandler":@DropboxHandler
|
||||
"../../infrastructure/Events": @Events = {emit: sinon.stub()}
|
||||
|
||||
@SubscriptionHandler.syncSubscriptionToUser = sinon.stub().callsArgWith(2)
|
||||
|
||||
|
@ -160,10 +161,8 @@ describe "Subscription Handler sanboxed", ->
|
|||
@RecurlyWrapper.cancelSubscription.called.should.equal true
|
||||
@RecurlyWrapper.cancelSubscription.calledWith(@subscription.recurlySubscription_id).should.equal true
|
||||
|
||||
|
||||
it "should unlink dropbox", ->
|
||||
@DropboxHandler.unlinkAccount.called.should.equal true
|
||||
@DropboxHandler.unlinkAccount.calledWith(@user._id).should.equal true
|
||||
it "should trigger the cancel subscription event", ->
|
||||
@Events.emit.calledWith("cancelSubscription", @user._id).should.equal true
|
||||
|
||||
describe "reactiveRecurlySubscription", ->
|
||||
describe "with a user without a subscription", ->
|
||||
|
|
Loading…
Reference in a new issue