Merge branch 'sk-linked-files-mendeley'

This commit is contained in:
Shane Kilkelly 2018-07-04 12:16:39 +01:00
commit 0777e44abf
9 changed files with 95 additions and 27 deletions

View file

@ -6,7 +6,6 @@ logger = require 'logger-sharelatex'
_ = require 'underscore' _ = require 'underscore'
LinkedFilesHandler = require './LinkedFilesHandler' LinkedFilesHandler = require './LinkedFilesHandler'
{ {
UrlFetchFailedError, UrlFetchFailedError,
InvalidUrlError, InvalidUrlError,
OutputFileFetchFailedError, OutputFileFetchFailedError,
@ -16,16 +15,23 @@ LinkedFilesHandler = require './LinkedFilesHandler'
ProjectNotFoundError, ProjectNotFoundError,
V1ProjectNotFoundError, V1ProjectNotFoundError,
SourceFileNotFoundError, SourceFileNotFoundError,
NotOriginalImporterError,
FeatureNotAvailableError,
RemoteServiceError
} = require './LinkedFilesErrors' } = require './LinkedFilesErrors'
Modules = require '../../infrastructure/Modules'
module.exports = LinkedFilesController = { module.exports = LinkedFilesController = {
Agents: { Agents: _.extend(
{
url: require('./UrlAgent'), url: require('./UrlAgent'),
project_file: require('./ProjectFileAgent'), project_file: require('./ProjectFileAgent'),
project_output_file: require('./ProjectOutputFileAgent') project_output_file: require('./ProjectOutputFileAgent'),
} },
Modules.linkedFileAgentsIncludes()
)
_getAgent: (provider) -> _getAgent: (provider) ->
if !LinkedFilesController.Agents.hasOwnProperty(provider) if !LinkedFilesController.Agents.hasOwnProperty(provider)
@ -117,6 +123,22 @@ module.exports = LinkedFilesController = {
"Your URL is not valid. Please check it and try again." "Your URL is not valid. Please check it and try again."
) )
else if error instanceof NotOriginalImporterError
res.status(400).send(
"You are not the user who originally imported this file"
)
else if error instanceof FeatureNotAvailableError
res.status(400).send(
"This feature is not enabled on your account"
)
else if error instanceof RemoteServiceError
res.status(502).send(
"The remote service produced an error"
)
else else
next(error) next(error)
} }

View file

@ -70,6 +70,30 @@ SourceFileNotFoundError = (message) ->
SourceFileNotFoundError.prototype.__proto__ = Error.prototype SourceFileNotFoundError.prototype.__proto__ = Error.prototype
NotOriginalImporterError = (message) ->
error = new Error(message)
error.name = 'NotOriginalImporter'
error.__proto__ = NotOriginalImporterError.prototype
return error
NotOriginalImporterError.prototype.__proto__ = Error.prototype
FeatureNotAvailableError = (message) ->
error = new Error(message)
error.name = 'FeatureNotAvailable'
error.__proto__ = FeatureNotAvailableError.prototype
return error
FeatureNotAvailableError.prototype.__proto__ = Error.prototype
RemoteServiceError = (message) ->
error = new Error(message)
error.name = 'RemoteService'
error.__proto__ = RemoteServiceError.prototype
return error
RemoteServiceError.prototype.__proto__ = Error.prototype
module.exports = { module.exports = {
UrlFetchFailedError, UrlFetchFailedError,
@ -81,4 +105,7 @@ module.exports = {
ProjectNotFoundError, ProjectNotFoundError,
V1ProjectNotFoundError, V1ProjectNotFoundError,
SourceFileNotFoundError, SourceFileNotFoundError,
NotOriginalImporterError,
FeatureNotAvailableError,
RemoteServiceError
} }

View file

@ -51,6 +51,13 @@ module.exports = Modules =
assetFiles.push "#{pathPrefix}#{assetFile}" assetFiles.push "#{pathPrefix}#{assetFile}"
return assetFiles return assetFiles
linkedFileAgentsIncludes: () ->
agents = {}
for module in @modules
for name, agentFunction of module.linkedFileAgents
agents[name] = agentFunction()
return agents
attachHooks: () -> attachHooks: () ->
for module in @modules for module in @modules
if module.hooks? if module.hooks?

View file

@ -78,6 +78,8 @@ div.binary-file.full-size(
| |
| at {{ openFile.created | formatDate:'h:mm a' }} {{ openFile.created | relativeDate }} | at {{ openFile.created | formatDate:'h:mm a' }} {{ openFile.created | relativeDate }}
!= moduleIncludes("binaryFile:linkedFileInfo", locals)
// Bottom Controls // Bottom Controls
span(ng-if="openFile.linkedFileData.provider") span(ng-if="openFile.linkedFileData.provider")
button.btn.btn-success( button.btn.btn-success(
@ -95,7 +97,10 @@ div.binary-file.full-size(
i.fa.fa-fw.fa-download i.fa.fa-fw.fa-download
| |
| #{translate("download")} | #{translate("download")}
div(ng-if="refreshError")
// Refresh Error
div(ng-if="refreshError").row
br br
.alert.alert-danger.col-md-6.col-md-offset-3 .alert.alert-danger.col-md-6.col-md-offset-3
| Error: {{ refreshError}} | Error: {{ refreshError}}
!= moduleIncludes("binaryFile:linkedFileRefreshError", locals)

View file

@ -26,6 +26,8 @@ script(type='text/ng-template', id='newFileModalTemplate')
i.fa.fa-fw.fa-globe i.fa.fa-fw.fa-globe
| |
| From External URL | From External URL
!= moduleIncludes("newFileModal:selector", locals)
td(class="modal-new-file--body modal-new-file--body-{{type}}") td(class="modal-new-file--body modal-new-file--body-{{type}}")
div(ng-if="type == 'doc'", ng-controller="NewDocModalController") div(ng-if="type == 'doc'", ng-controller="NewDocModalController")
form(novalidate, name="newDocForm") form(novalidate, name="newDocForm")
@ -178,6 +180,9 @@ script(type='text/ng-template', id='newFileModalTemplate')
div(ng-switch="error") div(ng-switch="error")
span(ng-switch-when="already exists") #{translate("file_already_exists")} span(ng-switch-when="already exists") #{translate("file_already_exists")}
span(ng-switch-default) {{error}} span(ng-switch-default) {{error}}
!= moduleIncludes("newFileModal:panel", locals)
.modal-footer .modal-footer
button.btn.btn-default( button.btn.btn-default(
ng-disabled="state.inflight" ng-disabled="state.inflight"

View file

@ -17,7 +17,7 @@ services:
PROJECT_HISTORY_ENABLED: 'true' PROJECT_HISTORY_ENABLED: 'true'
ENABLED_LINKED_FILE_TYPES: 'url' ENABLED_LINKED_FILE_TYPES: 'url'
LINKED_URL_PROXY: 'http://localhost:6543' LINKED_URL_PROXY: 'http://localhost:6543'
ENABLED_LINKED_FILE_TYPES: 'url,project_file,project_output_file' ENABLED_LINKED_FILE_TYPES: 'url,project_file,project_output_file,mendeley'
SHARELATEX_CONFIG: /app/test/acceptance/config/settings.test.coffee SHARELATEX_CONFIG: /app/test/acceptance/config/settings.test.coffee
depends_on: depends_on:
- redis - redis

View file

@ -606,8 +606,6 @@ CodeMirror
} }
.referencesImportModal { .referencesImportModal {
.referencesImportPreview {
margin-top: 15px;
.referencesImportPreviewScroller { .referencesImportPreviewScroller {
font-family: monospace; font-family: monospace;
font-size: 0.8em; font-size: 0.8em;
@ -619,7 +617,6 @@ CodeMirror
border: 1px solid @gray-lighter; border: 1px solid @gray-lighter;
background-color: @gray-lightest; background-color: @gray-lightest;
} }
}
} }
.teaser-title, .teaser-title,

View file

@ -107,6 +107,7 @@ describe "LinkedFiles", ->
source_project_id: @project_two_id, source_project_id: @project_two_id,
source_entity_path: "/#{@source_doc_name}", source_entity_path: "/#{@source_doc_name}",
}, (error, response, body) => }, (error, response, body) =>
expect(response.statusCode).to.equal 200
new_file_id = body.new_file_id new_file_id = body.new_file_id
@existing_file_id = new_file_id @existing_file_id = new_file_id
expect(new_file_id).to.exist expect(new_file_id).to.exist
@ -127,6 +128,7 @@ describe "LinkedFiles", ->
url: "/project/#{@project_one_id}/linked_file/#{@existing_file_id}/refresh", url: "/project/#{@project_one_id}/linked_file/#{@existing_file_id}/refresh",
json: true json: true
}, (error, response, body) => }, (error, response, body) =>
expect(response.statusCode).to.equal 200
new_file_id = body.new_file_id new_file_id = body.new_file_id
expect(new_file_id).to.exist expect(new_file_id).to.exist
expect(new_file_id).to.not.equal @existing_file_id expect(new_file_id).to.not.equal @existing_file_id

View file

@ -32,6 +32,9 @@ class User
get: (callback = (error, user)->) -> get: (callback = (error, user)->) ->
db.users.findOne { _id: ObjectId(@_id) }, callback db.users.findOne { _id: ObjectId(@_id) }, callback
mongoUpdate: (updateOp, callback=(error)->) ->
db.users.update {_id: ObjectId(@_id)}, updateOp, callback
register: (callback = (error, user) ->) -> register: (callback = (error, user) ->) ->
return callback(new Error('User already registered')) if @_id? return callback(new Error('User already registered')) if @_id?
@getCsrfToken (error) => @getCsrfToken (error) =>