Merge pull request #1117 from sharelatex/ew-collabratec-project-metadata-api2

Collabratec project metadata api

GitOrigin-RevId: 46f4b84bfb302f68c0a176a8a1686ce22829ba08
This commit is contained in:
Ersun Warncke 2018-11-09 04:57:53 -04:00 committed by sharelatex
parent de4f1a5abd
commit 59a849d46e
5 changed files with 9 additions and 47 deletions

View file

@ -35,7 +35,10 @@ module.exports = AuthorizationMiddlewear =
next()
else
logger.log {user_id, project_id}, "denying user read access to project"
AuthorizationMiddlewear.redirectToRestricted req, res, next
if req.headers?['accept']?.match(/^application\/json.*$/)
res.sendStatus(403)
else
AuthorizationMiddlewear.redirectToRestricted req, res, next
ensureUserCanWriteProjectSettings: (req, res, next) ->
AuthorizationMiddlewear._getUserAndProjectId req, (error, user_id, project_id) ->
@ -99,7 +102,7 @@ module.exports = AuthorizationMiddlewear =
callback(null, user_id, project_id)
_getUserId: (req, callback = (error, user_id) ->) ->
user_id = AuthenticationController.getLoggedInUserId(req)
user_id = AuthenticationController.getLoggedInUserId(req) || req?.oauth_user?._id || null
return callback(null, user_id)
redirectToRestricted: (req, res, next) ->

View file

@ -52,4 +52,3 @@ module.exports = ProjectUploadController =
project_id: project_id, file_path: path, file_name: name, folder_id: folder_id
"uploaded file"
res.send success: true, entity_id: entity?._id, entity_type: entity?.type

View file

@ -41,4 +41,4 @@ module.exports = V1Api =
else
error = new Error("overleaf v1 returned non-success code: #{response.statusCode} #{options.method} #{options.uri}")
error.statusCode = response.statusCode
callback error
callback error

View file

@ -84,27 +84,6 @@ describe "ProjectDuplicateNames", ->
it "should respond with 400 error status", ->
expect(@res.statusCode).to.equal 400
describe "trying to upload a file with the same name", ->
before (done) ->
@owner.request.post
uri: "/project/#{@example_project_id}/upload"
json: true
qs:
folder_id: @rootFolderId
qqfilename: "main.tex"
formData:
qqfile:
value: fs.createReadStream Path.resolve(__dirname + '/../files/1pixel.png')
options:
filename: 'main.tex',
contentType: 'image/png'
, (err, res, body) =>
@body = body
done()
it "should respond with failure status", ->
expect(@body.success).to.equal false
describe "trying to add a folder with the same name", ->
before (done) ->
@owner.request.post {
@ -119,28 +98,6 @@ describe "ProjectDuplicateNames", ->
it "should respond with 400 error status", ->
expect(@res.statusCode).to.equal 400
describe "trying to upload a file with the same name", ->
before (done) ->
@owner.request.post
uri: "/project/#{@example_project_id}/upload"
json: true
qs:
folder_id: @rootFolderId
qqfilename: "main.tex"
formData:
qqfile:
value: fs.createReadStream Path.resolve(__dirname + '/../files/1pixel.png')
options:
filename: 'main.tex',
contentType: 'image/png'
, (err, res, body) =>
@body = body
done()
it "should respond with failure status", ->
expect(@body.success).to.equal false
describe "for an existing file", ->
describe "trying to add a doc with the same name", ->
before (done) ->

View file

@ -35,6 +35,9 @@ module.exports = MockDocUpdaterApi =
@addProjectStructureUpdates(project_id, userId, docUpdates, fileUpdates, version)
res.sendStatus 200
app.post "/project/:project_id/doc/:doc_id/flush", (req, res, next) =>
res.sendStatus 204
app.delete "/project/:project_id/doc/:doc_id", (req, res, next) =>
res.sendStatus 204