Add endpoint to list entities within a project

This commit is contained in:
Shane Kilkelly
2018-05-04 10:45:13 +01:00
parent 4925bfe536
commit 3c3ce2010a
3 changed files with 29 additions and 3 deletions
@@ -25,6 +25,7 @@ Sources = require "../Authorization/Sources"
TokenAccessHandler = require '../TokenAccess/TokenAccessHandler'
CollaboratorsHandler = require '../Collaborators/CollaboratorsHandler'
Modules = require '../../infrastructure/Modules'
ProjectEntityHandler = require './ProjectEntityHandler'
crypto = require 'crypto'
module.exports = ProjectController =
@@ -138,9 +139,8 @@ module.exports = ProjectController =
return next(err) if err?
res.sendStatus 200
projectsJson: (req, res, next) ->
userProjectsJson: (req, res, next) ->
user_id = AuthenticationController.getLoggedInUserId(req)
ProjectGetter.findAllUsersProjects user_id,
'name lastUpdated publicAccesLevel archived owner_ref tokens', (err, projects) ->
return next(err) if err?
@@ -151,6 +151,24 @@ module.exports = ProjectController =
res.json({projects: projects})
projectEntitiesJson: (req, res, next) ->
user_id = AuthenticationController.getLoggedInUserId(req)
project_id = req.params.Project_id
AuthorizationManager.canUserReadProject user_id, project_id,
null, (err, canRead) ->
return next(err) if err?
return res.status(403) if !canRead
ProjectGetter.getProject project_id, (err, project) ->
return next(err) if err?
ProjectEntityHandler.getAllEntitiesFromProject project, (err, docs, files) ->
return next(err) if err?
entities = docs.concat(files)
.map (e) -> {
path: e.path,
type: if e.doc? then 'doc' else 'file'
}
res.json({entities: entities})
projectListPage: (req, res, next)->
timer = new metrics.Timer("project-list")
user_id = AuthenticationController.getLoggedInUserId(req)