2014-06-05 11:18:25 -04:00
|
|
|
ProjectEntityHandler = require "../Project/ProjectEntityHandler"
|
2014-11-07 07:31:47 -05:00
|
|
|
ProjectDeleter = require "../Project/ProjectDeleter"
|
2014-06-05 11:18:25 -04:00
|
|
|
logger = require "logger-sharelatex"
|
|
|
|
EditorRealTimeController = require "./EditorRealTimeController"
|
2014-06-22 07:10:42 -04:00
|
|
|
EditorController = require "./EditorController"
|
2014-11-07 07:31:47 -05:00
|
|
|
Metrics = require('../../infrastructure/Metrics')
|
2014-06-05 11:18:25 -04:00
|
|
|
|
|
|
|
module.exports = EditorHttpController =
|
2014-11-07 07:31:47 -05:00
|
|
|
joinProject: (req, res, next) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
user_id = req.query.user_id
|
|
|
|
logger.log {user_id, project_id}, "join project request"
|
|
|
|
Metrics.inc "editor.join-project"
|
|
|
|
EditorController.buildJoinProjectView project_id, user_id, (error, project, privilegeLevel) ->
|
|
|
|
return next(error) if error?
|
|
|
|
res.json {
|
|
|
|
project: project
|
|
|
|
privilegeLevel: privilegeLevel
|
|
|
|
}
|
|
|
|
# Only show the 'renamed or deleted' message once
|
|
|
|
if project.deletedByExternalDataSource
|
|
|
|
ProjectDeleter.unmarkAsDeletedByExternalSource project_id
|
|
|
|
|
2014-06-05 11:18:25 -04:00
|
|
|
restoreDoc: (req, res, next) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
doc_id = req.params.doc_id
|
|
|
|
name = req.body.name
|
|
|
|
|
|
|
|
if !name?
|
|
|
|
return res.send 400 # Malformed request
|
|
|
|
|
|
|
|
logger.log project_id: project_id, doc_id: doc_id, "restoring doc"
|
|
|
|
ProjectEntityHandler.restoreDoc project_id, doc_id, name, (err, doc, folder_id) =>
|
|
|
|
return next(error) if error?
|
|
|
|
EditorRealTimeController.emitToRoom(project_id, 'reciveNewDoc', folder_id, doc)
|
|
|
|
res.json {
|
|
|
|
doc_id: doc._id
|
|
|
|
}
|
|
|
|
|
2014-06-22 09:39:38 -04:00
|
|
|
|
2014-06-22 07:10:42 -04:00
|
|
|
addDoc: (req, res, next) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
name = req.body.name
|
|
|
|
parent_folder_id = req.body.parent_folder_id
|
2014-10-15 10:18:31 -04:00
|
|
|
EditorController.addDoc project_id, parent_folder_id, name, [], "editor", (error, doc) ->
|
2014-06-22 07:10:42 -04:00
|
|
|
return next(error) if error?
|
|
|
|
res.json doc
|
2014-06-22 09:39:38 -04:00
|
|
|
|
|
|
|
addFolder: (req, res, next) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
name = req.body.name
|
|
|
|
parent_folder_id = req.body.parent_folder_id
|
2014-10-16 06:26:57 -04:00
|
|
|
EditorController.addFolder project_id, parent_folder_id, name, "editor", (error, doc) ->
|
2014-06-22 09:39:38 -04:00
|
|
|
return next(error) if error?
|
|
|
|
res.json doc
|
2014-06-22 15:08:56 -04:00
|
|
|
|
|
|
|
renameEntity: (req, res, next) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
entity_id = req.params.entity_id
|
|
|
|
entity_type = req.params.entity_type
|
|
|
|
name = req.body.name
|
2014-10-07 06:16:26 -04:00
|
|
|
if name.length > 150
|
|
|
|
return res.send 400
|
2014-06-22 15:08:56 -04:00
|
|
|
EditorController.renameEntity project_id, entity_id, entity_type, name, (error) ->
|
|
|
|
return next(error) if error?
|
|
|
|
res.send 204
|
|
|
|
|
|
|
|
moveEntity: (req, res, next) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
entity_id = req.params.entity_id
|
|
|
|
entity_type = req.params.entity_type
|
|
|
|
folder_id = req.body.folder_id
|
|
|
|
EditorController.moveEntity project_id, entity_id, folder_id, entity_type, (error) ->
|
|
|
|
return next(error) if error?
|
|
|
|
res.send 204
|
|
|
|
|
2014-10-24 07:01:35 -04:00
|
|
|
deleteDoc: (req, res, next)->
|
|
|
|
req.params.entity_type = "doc"
|
|
|
|
EditorHttpController.deleteEntity(req, res, next)
|
|
|
|
|
|
|
|
deleteFile: (req, res, next)->
|
|
|
|
req.params.entity_type = "file"
|
|
|
|
EditorHttpController.deleteEntity(req, res, next)
|
|
|
|
|
|
|
|
deleteFolder: (req, res, next)->
|
|
|
|
req.params.entity_type = "folder"
|
|
|
|
EditorHttpController.deleteEntity(req, res, next)
|
|
|
|
|
2014-06-22 15:08:56 -04:00
|
|
|
deleteEntity: (req, res, next) ->
|
|
|
|
project_id = req.params.Project_id
|
|
|
|
entity_id = req.params.entity_id
|
|
|
|
entity_type = req.params.entity_type
|
2014-10-15 10:18:31 -04:00
|
|
|
EditorController.deleteEntity project_id, entity_id, entity_type, "editor", (error) ->
|
2014-06-22 15:08:56 -04:00
|
|
|
return next(error) if error?
|
|
|
|
res.send 204
|
2014-11-06 07:20:45 -05:00
|
|
|
|
2014-06-22 15:08:56 -04:00
|
|
|
|