mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Refactor, and remove the source_project_display_name
prop from linkedFileData
This commit is contained in:
parent
dfb4898be5
commit
ebe828aa62
6 changed files with 39 additions and 44 deletions
|
@ -5,6 +5,7 @@ Settings = require 'settings-sharelatex'
|
|||
logger = require 'logger-sharelatex'
|
||||
_ = require 'underscore'
|
||||
LinkedFilesErrors = require './LinkedFilesErrors'
|
||||
LinkedFilesHandler = require './LinkedFilesHandler'
|
||||
|
||||
|
||||
module.exports = LinkedFilesController = {
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
LinkedFilesErrors = require './LinkedFilesErrors'
|
||||
FileWriter = require '../../infrastructure/FileWriter'
|
||||
EditorController = require '../Editor/EditorController'
|
||||
ProjectLocator = require '../Project/ProjectLocator'
|
||||
Project = require("../../models/Project").Project
|
||||
ProjectGetter = require("../Project/ProjectGetter")
|
||||
_ = require 'underscore'
|
||||
{
|
||||
ProjectNotFoundError,
|
||||
V1ProjectNotFoundError,
|
||||
BadDataError
|
||||
} = require './LinkedFilesErrors'
|
||||
|
||||
|
||||
module.exports = LinkedFilesHandler =
|
||||
|
@ -16,6 +22,23 @@ module.exports = LinkedFilesHandler =
|
|||
return callback(err) if err?
|
||||
callback(null, file, path, parentFolder)
|
||||
|
||||
getSourceProject: (data, callback=(err, project)->) ->
|
||||
projection = {_id: 1, name: 1}
|
||||
if data.v1_source_doc_id?
|
||||
Project.findOne {'overleaf.id': data.v1_source_doc_id}, projection, (err, project) ->
|
||||
return callback(err) if err?
|
||||
if !project?
|
||||
return callback(new V1ProjectNotFoundError())
|
||||
callback(null, project)
|
||||
else if data.source_project_id?
|
||||
ProjectGetter.getProject data.source_project_id, projection, (err, project) ->
|
||||
return callback(err) if err?
|
||||
if !project?
|
||||
return callback(new ProjectNotFoundError())
|
||||
callback(null, project)
|
||||
else
|
||||
callback(new BadDataError('neither v1 nor v2 id present'))
|
||||
|
||||
importFromStream: (
|
||||
project_id,
|
||||
readStream,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
AuthorizationManager = require('../Authorization/AuthorizationManager')
|
||||
ProjectLocator = require('../Project/ProjectLocator')
|
||||
ProjectGetter = require('../Project/ProjectGetter')
|
||||
Project = require("../../models/Project").Project
|
||||
DocstoreManager = require('../Docstore/DocstoreManager')
|
||||
FileStoreHandler = require('../FileStore/FileStoreHandler')
|
||||
_ = require "underscore"
|
||||
|
@ -30,11 +29,9 @@ module.exports = ProjectFileAgent = {
|
|||
@_checkAuth project_id, linkedFileData, user_id, (err, allowed) =>
|
||||
return callback(err) if err?
|
||||
return callback(new AccessDeniedError()) if !allowed
|
||||
@_decorateLinkedFileData linkedFileData, (err, newLinkedFileData) =>
|
||||
return callback(err) if err?
|
||||
if !@_validate(newLinkedFileData)
|
||||
if !@_validate(linkedFileData)
|
||||
return callback(new BadDataError())
|
||||
callback(null, newLinkedFileData)
|
||||
callback(null, linkedFileData)
|
||||
|
||||
_go: (project_id, linkedFileData, name, parent_folder_id, user_id, callback) ->
|
||||
linkedFileData = @_sanitizeData(linkedFileData)
|
||||
|
@ -107,28 +104,7 @@ module.exports = ProjectFileAgent = {
|
|||
# Don't allow creation of linked-files with v1 doc ids
|
||||
!data.v1_source_doc_id?
|
||||
|
||||
_getSourceProject: (data, callback=(err, project)->) ->
|
||||
projection = {_id: 1, name: 1}
|
||||
if data.v1_source_doc_id?
|
||||
Project.findOne {'overleaf.id': data.v1_source_doc_id}, projection, (err, project) ->
|
||||
return callback(err) if err?
|
||||
if !project?
|
||||
return callback(new V1ProjectNotFoundError())
|
||||
callback(null, project)
|
||||
else if data.source_project_id?
|
||||
ProjectGetter.getProject data.source_project_id, projection, (err, project) ->
|
||||
return callback(err) if err?
|
||||
if !project?
|
||||
return callback(new ProjectNotFoundError())
|
||||
callback(null, project)
|
||||
else
|
||||
callback(new BadDataError('neither v1 nor v2 id present'))
|
||||
|
||||
_decorateLinkedFileData: (data, callback = (err, newData) ->) ->
|
||||
callback = _.once(callback)
|
||||
@_getSourceProject data, (err, project) ->
|
||||
return callback(err) if err?
|
||||
callback(err, _.extend(data, {source_project_display_name: project.name}))
|
||||
_getSourceProject: LinkedFilesHandler.getSourceProject
|
||||
|
||||
_checkAuth: (project_id, data, current_user_id, callback = (error, allowed)->) ->
|
||||
callback = _.once(callback)
|
||||
|
|
|
@ -21,11 +21,9 @@ module.exports = ProjectOutputFileAgent = {
|
|||
@_checkAuth project_id, linkedFileData, user_id, (err, allowed) =>
|
||||
return callback(err) if err?
|
||||
return callback(new AccessDeniedError()) if !allowed
|
||||
@_decorateLinkedFileData linkedFileData, (err, newLinkedFileData) =>
|
||||
return callback(err) if err?
|
||||
if !@_validate(newLinkedFileData)
|
||||
if !@_validate(linkedFileData)
|
||||
return callback(new BadDataError())
|
||||
callback(null, newLinkedFileData)
|
||||
callback(null, linkedFileData)
|
||||
|
||||
createLinkedFile: (project_id, linkedFileData, name, parent_folder_id, user_id, callback) ->
|
||||
if !@_canCreate(linkedFileData)
|
||||
|
@ -92,9 +90,7 @@ module.exports = ProjectOutputFileAgent = {
|
|||
|
||||
_canCreate: ProjectFileAgent._canCreate
|
||||
|
||||
_getSourceProject: ProjectFileAgent._getSourceProject
|
||||
|
||||
_decorateLinkedFileData: ProjectFileAgent._decorateLinkedFileData
|
||||
_getSourceProject: LinkedFilesHandler.getSourceProject
|
||||
|
||||
_validate: (data) ->
|
||||
return (
|
||||
|
|
|
@ -56,9 +56,9 @@ div.binary-file.full-size(
|
|||
|
|
||||
a(ng-if='!openFile.linkedFileData.v1_source_doc_id'
|
||||
ng-href='/project/{{openFile.linkedFileData.source_project_id}}' target="_blank")
|
||||
| {{ openFile.linkedFileData.source_project_display_name }}
|
||||
| Another project
|
||||
span(ng-if='openFile.linkedFileData.v1_source_doc_id')
|
||||
| {{ openFile.linkedFileData.source_project_display_name }}
|
||||
| Another project
|
||||
| /{{ openFile.linkedFileData.source_entity_path.slice(1) }},
|
||||
|
|
||||
| at {{ openFile.created | formatDate:'h:mm a' }} {{ openFile.created | relativeDate }}
|
||||
|
@ -71,9 +71,9 @@ div.binary-file.full-size(
|
|||
|
|
||||
a(ng-if='!openFile.linkedFileData.v1_source_doc_id'
|
||||
ng-href='/project/{{openFile.linkedFileData.source_project_id}}' target="_blank")
|
||||
| {{ openFile.linkedFileData.source_project_display_name }}
|
||||
| Another project
|
||||
span(ng-if='openFile.linkedFileData.v1_source_doc_id')
|
||||
| {{ openFile.linkedFileData.source_project_display_name }}
|
||||
| Another project
|
||||
| : {{ openFile.linkedFileData.source_output_file_path }},
|
||||
|
|
||||
| at {{ openFile.created | formatDate:'h:mm a' }} {{ openFile.created | relativeDate }}
|
||||
|
|
|
@ -118,7 +118,6 @@ describe "LinkedFiles", ->
|
|||
provider: 'project_file',
|
||||
source_project_id: @project_two_id,
|
||||
source_entity_path: "/#{@source_doc_name}",
|
||||
source_project_display_name: "plf-test-two"
|
||||
}
|
||||
expect(firstFile.name).to.equal('test-link.txt')
|
||||
done()
|
||||
|
@ -393,7 +392,6 @@ describe "LinkedFiles", ->
|
|||
provider: 'project_output_file',
|
||||
source_project_id: @project_two_id,
|
||||
source_output_file_path: "output.pdf",
|
||||
source_project_display_name: "output-test-two"
|
||||
build_id: '1234-abcd'
|
||||
}
|
||||
expect(firstFile.name).to.equal('test.pdf')
|
||||
|
@ -430,7 +428,8 @@ describe "LinkedFiles", ->
|
|||
linkedFileData: {
|
||||
provider: "project_output_file",
|
||||
v1_source_doc_id: 9999999, # We won't find this id in the database
|
||||
source_output_file_path: "output.pdf"
|
||||
source_output_file_path: "output.pdf",
|
||||
build_id: '123'
|
||||
},
|
||||
_id: "abcdef",
|
||||
rev: 0,
|
||||
|
|
Loading…
Reference in a new issue