Collabratec Get Projects API (#1092)

collabratec get projects api

GitOrigin-RevId: c733aecf515cf75ca1ae9c454efa7a35f09cf495
This commit is contained in:
Ersun Warncke 2018-11-06 09:33:12 -04:00 committed by sharelatex
parent 2ea0644cfa
commit f3b92bbeec
5 changed files with 29 additions and 5 deletions

View file

@ -85,6 +85,7 @@ docker-shared.yml
config/*.coffee
modules/**/Makefile
modules/**/index.js
modules/**/app/js/*
modules/**/test/unit/js/*

View file

@ -184,7 +184,7 @@ module.exports = AuthenticationController =
return res.status(401).json({error: "invalid_token"}) unless body?.user_profile?.id
User.findOne { "overleaf.id": body.user_profile.id }, (error, user) ->
return next(error) if error?
return res.status(401).send() unless user?
return res.status(401).send({error: "invalid_token"}) unless user?
req.oauth = access_token: body.access_token
req.oauth_user = user
next()

View file

@ -11,16 +11,34 @@ DEFAULT_V1_PARAMS = {
timeout: 30 * 1000
}
request = request.defaults(DEFAULT_V1_PARAMS)
v1Request = request.defaults(DEFAULT_V1_PARAMS)
DEFAULT_V1_OAUTH_PARAMS = {
baseUrl: settings?.apis?.v1?.url
json: true,
timeout: 30 * 1000
}
v1OauthRequest = request.defaults(DEFAULT_V1_OAUTH_PARAMS)
module.exports = V1Api =
request: (options, callback) ->
return request(options) if !callback?
request options, (error, response, body) ->
v1Request options, (error, response, body) ->
V1Api._responseHandler options, error, response, body, callback
oauthRequest: (options, token, callback) ->
return callback(new Error "uri required") unless options.uri?
options.method = "GET" unless options.method?
options.auth = bearer: token
v1OauthRequest options, (error, response, body) ->
V1Api._responseHandler options, error, response, body, callback
_responseHandler: (options, error, response, body, callback) ->
return callback(error, response, body) if error?
if 200 <= response.statusCode < 300 or response.statusCode in (options.expectedStatusCodes or [])
callback null, response, body
else
error = new Error("overleaf v1 returned non-success code: #{response.statusCode}")
error = new Error("overleaf v1 returned non-success code: #{response.statusCode} #{options.method} #{options.uri}")
error.statusCode = response.statusCode
callback error

View file

@ -75,6 +75,7 @@ UserSchema = new Schema
accessToken: { type: String }
refreshToken: { type: String }
awareOfV2: { type:Boolean, default: false }
useCollabratecV2: { type:Boolean, default: false }
conn = mongoose.createConnection(Settings.mongo.url, {
server: {poolSize: Settings.mongo.poolSize || 10},

View file

@ -185,6 +185,10 @@ class User
return callback(error) if error?
callback(null)
deleteProjects: (callback=(error)) ->
db.projects.remove owner_ref:ObjectId(@id), {multi:true}, (err)->
callback(err)
openProject: (project_id, callback=(error)) ->
@request.get {
url: "/project/#{project_id}"