mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Access Dropbox status via HTTP end points
This commit is contained in:
parent
e596b60af0
commit
7b6ec86cef
4 changed files with 63 additions and 6 deletions
|
@ -0,0 +1,12 @@
|
||||||
|
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,5 +1,7 @@
|
||||||
DropboxUserController = require './DropboxUserController'
|
DropboxUserController = require './DropboxUserController'
|
||||||
DropboxWebhookController = require './DropboxWebhookController'
|
DropboxWebhookController = require './DropboxWebhookController'
|
||||||
|
DropboxProjectController = require "./DropboxProjectController"
|
||||||
|
SecurityManager = require "../../managers/SecurityManager"
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
apply: (app) ->
|
apply: (app) ->
|
||||||
|
@ -11,5 +13,6 @@ module.exports =
|
||||||
app.post '/dropbox/webhook', DropboxWebhookController.webhook
|
app.post '/dropbox/webhook', DropboxWebhookController.webhook
|
||||||
app.ignoreCsrf('post', '/dropbox/webhook')
|
app.ignoreCsrf('post', '/dropbox/webhook')
|
||||||
|
|
||||||
|
app.get '/project/:Project_id/dropbox/status', SecurityManager.requestIsOwner, DropboxProjectController.getStatus
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,13 +22,14 @@ define [
|
||||||
scope:$scope
|
scope:$scope
|
||||||
}
|
}
|
||||||
|
|
||||||
App.controller "DropboxModalController", ($scope, $modalInstance, ide, $timeout) ->
|
App.controller "DropboxModalController", ($scope, $modalInstance, ide, $timeout, $http) ->
|
||||||
user_id = ide.$scope.user.id
|
user_id = ide.$scope.user.id
|
||||||
|
|
||||||
$scope.dbState = cachedState
|
$scope.dbState = cachedState
|
||||||
$scope.dbState.hasDropboxFeature = $scope.project.features.dropbox
|
$scope.dbState.hasDropboxFeature = $scope.project.features.dropbox
|
||||||
|
|
||||||
ide.socket.emit "getUserDropboxLinkStatus", user_id, (err, status)=>
|
$http.get("/project/#{ide.project_id}/dropbox/status")
|
||||||
|
.success (status) ->
|
||||||
$scope.dbState.gotLinkStatus = true
|
$scope.dbState.gotLinkStatus = true
|
||||||
if status.registered
|
if status.registered
|
||||||
$scope.dbState.userIsLinkedToDropbox = true
|
$scope.dbState.userIsLinkedToDropbox = true
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
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
|
Loading…
Reference in a new issue