Access Dropbox status via HTTP end points

This commit is contained in:
James Allen 2014-11-06 12:41:00 +00:00
parent e596b60af0
commit 7b6ec86cef
4 changed files with 63 additions and 6 deletions

View file

@ -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

View file

@ -1,5 +1,7 @@
DropboxUserController = require './DropboxUserController'
DropboxWebhookController = require './DropboxWebhookController'
DropboxProjectController = require "./DropboxProjectController"
SecurityManager = require "../../managers/SecurityManager"
module.exports =
apply: (app) ->
@ -11,5 +13,6 @@ module.exports =
app.post '/dropbox/webhook', DropboxWebhookController.webhook
app.ignoreCsrf('post', '/dropbox/webhook')
app.get '/project/:Project_id/dropbox/status', SecurityManager.requestIsOwner, DropboxProjectController.getStatus

View file

@ -22,13 +22,14 @@ define [
scope:$scope
}
App.controller "DropboxModalController", ($scope, $modalInstance, ide, $timeout) ->
App.controller "DropboxModalController", ($scope, $modalInstance, ide, $timeout, $http) ->
user_id = ide.$scope.user.id
$scope.dbState = cachedState
$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
if status.registered
$scope.dbState.userIsLinkedToDropbox = true

View file

@ -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