mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Use a decorateLinkedFileData function on server to add project name
This commit is contained in:
@@ -26,11 +26,14 @@ module.exports = LinkedFilesController = {
|
|||||||
Agent.checkAuth project_id, linkedFileData, user_id, (err, allowed) ->
|
Agent.checkAuth project_id, linkedFileData, user_id, (err, allowed) ->
|
||||||
return Agent.handleError(err, req, res, next) if err?
|
return Agent.handleError(err, req, res, next) if err?
|
||||||
return res.sendStatus(403) if !allowed
|
return res.sendStatus(403) if !allowed
|
||||||
Agent.writeIncomingFileToDisk project_id, linkedFileData, user_id, (error, fsPath) ->
|
Agent.decorateLinkedFileData linkedFileData, (err, newLinkedFileData) ->
|
||||||
if error?
|
return Agent.handleError(err) if err?
|
||||||
logger.error {err: error, project_id, name, linkedFileData, parent_folder_id, user_id}, 'error writing linked file to disk'
|
linkedFileData = newLinkedFileData
|
||||||
return Agent.handleError(error, req, res, next)
|
Agent.writeIncomingFileToDisk project_id, linkedFileData, user_id, (error, fsPath) ->
|
||||||
EditorController.upsertFile project_id, parent_folder_id, name, fsPath, linkedFileData, "upload", user_id, (error, file) ->
|
if error?
|
||||||
return next(error) if error?
|
logger.error {err: error, project_id, name, linkedFileData, parent_folder_id, user_id}, 'error writing linked file to disk'
|
||||||
res.json(new_file_id: file._id) # created
|
return Agent.handleError(error, req, res, next)
|
||||||
}
|
EditorController.upsertFile project_id, parent_folder_id, name, fsPath, linkedFileData, "upload", user_id, (error, file) ->
|
||||||
|
return next(error) if error?
|
||||||
|
res.json(new_file_id: file._id) # created
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
FileWriter = require('../../infrastructure/FileWriter')
|
FileWriter = require('../../infrastructure/FileWriter')
|
||||||
AuthorizationManager = require('../Authorization/AuthorizationManager')
|
AuthorizationManager = require('../Authorization/AuthorizationManager')
|
||||||
ProjectLocator = require('../Project/ProjectLocator')
|
ProjectLocator = require('../Project/ProjectLocator')
|
||||||
|
ProjectGetter = require('../Project/ProjectGetter')
|
||||||
DocstoreManager = require('../Docstore/DocstoreManager')
|
DocstoreManager = require('../Docstore/DocstoreManager')
|
||||||
FileStoreHandler = require('../FileStore/FileStoreHandler')
|
FileStoreHandler = require('../FileStore/FileStoreHandler')
|
||||||
FileWriter = require('../../infrastructure/FileWriter')
|
FileWriter = require('../../infrastructure/FileWriter')
|
||||||
@@ -32,6 +33,14 @@ BadDataError = (message) ->
|
|||||||
BadDataError.prototype.__proto__ = Error.prototype
|
BadDataError.prototype.__proto__ = Error.prototype
|
||||||
|
|
||||||
|
|
||||||
|
ProjectNotFoundError = (message) ->
|
||||||
|
error = new Error(message)
|
||||||
|
error.name = 'ProjectNotFound'
|
||||||
|
error.__proto__ = ProjectNotFoundError.prototype
|
||||||
|
return error
|
||||||
|
ProjectNotFoundError.prototype.__proto__ = Error.prototype
|
||||||
|
|
||||||
|
|
||||||
SourceFileNotFoundError = (message) ->
|
SourceFileNotFoundError = (message) ->
|
||||||
error = new Error(message)
|
error = new Error(message)
|
||||||
error.name = 'BadData'
|
error.name = 'BadData'
|
||||||
@@ -46,17 +55,24 @@ module.exports = ProjectFileAgent =
|
|||||||
return _.pick(
|
return _.pick(
|
||||||
data,
|
data,
|
||||||
'source_project_id',
|
'source_project_id',
|
||||||
'source_entity_path',
|
'source_entity_path'
|
||||||
'source_project_display_name'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
_validate: (data) ->
|
_validate: (data) ->
|
||||||
return (
|
return (
|
||||||
data.source_project_id? &&
|
data.source_project_id? &&
|
||||||
data.source_entity_path? &&
|
data.source_entity_path?
|
||||||
data.source_project_display_name?
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
decorateLinkedFileData: (data, callback = (err, newData) ->) ->
|
||||||
|
callback = _.once(callback)
|
||||||
|
{ source_project_id } = data
|
||||||
|
return callback(new BadDataError()) if !source_project_id?
|
||||||
|
ProjectGetter.getProject source_project_id, (err, project) ->
|
||||||
|
return callback(err) if err?
|
||||||
|
return callback(new ProjectNotFoundError()) if !project?
|
||||||
|
callback(err, _.extend(data, {source_project_display_name: project.name}))
|
||||||
|
|
||||||
checkAuth: (project_id, data, current_user_id, callback = (error, allowed)->) ->
|
checkAuth: (project_id, data, current_user_id, callback = (error, allowed)->) ->
|
||||||
callback = _.once(callback)
|
callback = _.once(callback)
|
||||||
if !ProjectFileAgent._validate(data)
|
if !ProjectFileAgent._validate(data)
|
||||||
@@ -104,6 +120,8 @@ module.exports = ProjectFileAgent =
|
|||||||
res.status(400).send("The file is the wrong type")
|
res.status(400).send("The file is the wrong type")
|
||||||
else if error instanceof SourceFileNotFoundError
|
else if error instanceof SourceFileNotFoundError
|
||||||
res.status(404).send("Source file not found")
|
res.status(404).send("Source file not found")
|
||||||
|
else if error instanceof ProjectNotFoundError
|
||||||
|
res.status(404).send("Project not found")
|
||||||
else
|
else
|
||||||
next(error)
|
next(error)
|
||||||
next()
|
next()
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ module.exports = UrlAgent = {
|
|||||||
url: @._prependHttpIfNeeded(data.url)
|
url: @._prependHttpIfNeeded(data.url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
decorateLinkedFileData: (data, callback = (err, newData) ->) ->
|
||||||
|
return callback(null, data)
|
||||||
|
|
||||||
checkAuth: (project_id, data, current_user_id, callback = (error, allowed)->) ->
|
checkAuth: (project_id, data, current_user_id, callback = (error, allowed)->) ->
|
||||||
callback(null, true)
|
callback(null, true)
|
||||||
|
|
||||||
|
|||||||
@@ -301,18 +301,16 @@ define [
|
|||||||
|
|
||||||
$scope.create = () ->
|
$scope.create = () ->
|
||||||
projectId = $scope.data.selectedProjectId
|
projectId = $scope.data.selectedProjectId
|
||||||
projectDisplayName = _.find($scope.data.projects, (p) -> p._id == projectId).name
|
|
||||||
path = $scope.data.selectedProjectEntity
|
path = $scope.data.selectedProjectEntity
|
||||||
name = $scope.data.name
|
name = $scope.data.name
|
||||||
if !name || !path || !projectId || !projectDisplayName
|
if !name || !path || !projectId
|
||||||
_reset(err: true)
|
_reset(err: true)
|
||||||
return
|
return
|
||||||
_setInFlight('create')
|
_setInFlight('create')
|
||||||
ide.fileTreeManager
|
ide.fileTreeManager
|
||||||
.createLinkedFile(name, parent_folder, 'project_file', {
|
.createLinkedFile(name, parent_folder, 'project_file', {
|
||||||
source_project_id: projectId,
|
source_project_id: projectId,
|
||||||
source_entity_path: path,
|
source_entity_path: path
|
||||||
source_project_display_name: projectDisplayName
|
|
||||||
})
|
})
|
||||||
.then () ->
|
.then () ->
|
||||||
_reset(err: false)
|
_reset(err: false)
|
||||||
|
|||||||
Reference in New Issue
Block a user