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

View file

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

View file

@ -118,7 +118,10 @@ module.exports = class Router
webRouter.get '/user/personal_info', AuthenticationController.requireLogin(), UserInfoController.getLoggedInUsersPersonalInfo
privateApiRouter.get '/user/:user_id/personal_info', AuthenticationController.httpAuth, UserInfoController.getPersonalInfo
webRouter.get '/user/projects', AuthenticationController.requireLogin(), ProjectController.projectsJson
# TODO: check this is the right router for these routes
webRouter.get '/user/projects', AuthenticationController.requireLogin(), ProjectController.userProjectsJson
webRouter.get '/project/:Project_id/entities', AuthenticationController.requireLogin(), ProjectController.projectEntitiesJson
webRouter.get '/project', AuthenticationController.requireLogin(), ProjectController.projectListPage
webRouter.post '/project/new', AuthenticationController.requireLogin(), ProjectController.newProject

View file

@ -46,6 +46,11 @@ define [
_csrf: window.csrfToken
}
window._getProjectEntities = (project_id) =>
@ide.$http.get "/project/#{project_id}/entities", {
_csrf: window.csrfToken
}
_bindToSocketEvents: () ->
@ide.socket.on "reciveNewDoc", (parent_folder_id, doc) =>
parent_folder = @findEntityById(parent_folder_id) or @$scope.rootFolder