mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #1278 from sharelatex/revert-1240-as-import-status-page
Revert "Import status page" GitOrigin-RevId: aa667a7b158b38aeccc8251931cc20589dcb2bdd
This commit is contained in:
parent
56784c4089
commit
1160620afc
13 changed files with 18 additions and 228 deletions
|
@ -106,7 +106,6 @@ module.exports = AuthorizationMiddlewear =
|
|||
return callback(null, user_id)
|
||||
|
||||
redirectToRestricted: (req, res, next) ->
|
||||
# TODO: move this to throwing ForbiddenError
|
||||
res.redirect "/restricted?from=#{encodeURIComponent(req.url)}"
|
||||
|
||||
restricted : (req, res, next)->
|
||||
|
|
|
@ -8,10 +8,6 @@ module.exports = ErrorController =
|
|||
res.render 'general/404',
|
||||
title: "page_not_found"
|
||||
|
||||
forbidden: (req, res) ->
|
||||
res.status(403)
|
||||
res.render 'user/restricted'
|
||||
|
||||
serverError: (req, res)->
|
||||
res.status(500)
|
||||
res.render 'general/500',
|
||||
|
@ -31,9 +27,6 @@ module.exports = ErrorController =
|
|||
if error instanceof Errors.NotFoundError
|
||||
logger.warn {err: error, url: req.url}, "not found error"
|
||||
ErrorController.notFound req, res
|
||||
else if error instanceof Errors.ForbiddenError
|
||||
logger.error err: error, "forbidden error"
|
||||
ErrorController.forbidden req, res
|
||||
else if error instanceof Errors.TooManyRequestsError
|
||||
logger.warn {err: error, url: req.url}, "too many requests error"
|
||||
res.sendStatus(429)
|
||||
|
|
|
@ -5,13 +5,6 @@ NotFoundError = (message) ->
|
|||
return error
|
||||
NotFoundError.prototype.__proto__ = Error.prototype
|
||||
|
||||
ForbiddenError = (message) ->
|
||||
error = new Error(message)
|
||||
error.name = "ForbiddenError"
|
||||
error.__proto__ = ForbiddenError.prototype
|
||||
return error
|
||||
ForbiddenError.prototype.__proto__ = Error.prototype
|
||||
|
||||
ServiceNotConfiguredError = (message) ->
|
||||
error = new Error(message)
|
||||
error.name = "ServiceNotConfiguredError"
|
||||
|
@ -112,7 +105,6 @@ SLInV2Error.prototype.__proto__ = Error.prototype
|
|||
|
||||
module.exports = Errors =
|
||||
NotFoundError: NotFoundError
|
||||
ForbiddenError: ForbiddenError
|
||||
ServiceNotConfiguredError: ServiceNotConfiguredError
|
||||
TooManyRequestsError: TooManyRequestsError
|
||||
InvalidNameError: InvalidNameError
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
ProjectController = require "../Project/ProjectController"
|
||||
AuthenticationController = require '../Authentication/AuthenticationController'
|
||||
TokenAccessHandler = require './TokenAccessHandler'
|
||||
Features = require '../../infrastructure/Features'
|
||||
Errors = require '../Errors/Errors'
|
||||
logger = require 'logger-sharelatex'
|
||||
settings = require 'settings-sharelatex'
|
||||
|
@ -38,17 +37,10 @@ module.exports = TokenAccessController =
|
|||
if !projectExists and settings.overleaf
|
||||
logger.log {token, userId},
|
||||
"[TokenAccess] no project found for this token"
|
||||
TokenAccessHandler.getV1DocInfo token, userId, (err, doc_info) ->
|
||||
TokenAccessHandler.getV1DocInfo token, (err, doc_info) ->
|
||||
return next err if err?
|
||||
return next(new Errors.NotFoundError()) if doc_info.exported
|
||||
if Features.hasFeature('force-import-to-v2')
|
||||
return res.render('project/v2-import', {
|
||||
projectId: token,
|
||||
hasOwner: doc_info.has_owner,
|
||||
name: doc_info.name
|
||||
})
|
||||
else
|
||||
return res.redirect(302, "/sign_in_to_v1?return_to=/#{token}")
|
||||
return res.redirect(302, "/sign_in_to_v1?return_to=/#{token}")
|
||||
else if !project?
|
||||
logger.log {token, userId},
|
||||
"[TokenAccess] no token-based project found for readAndWrite token"
|
||||
|
|
|
@ -2,7 +2,6 @@ Project = require('../../models/Project').Project
|
|||
CollaboratorsHandler = require('../Collaborators/CollaboratorsHandler')
|
||||
PublicAccessLevels = require '../Authorization/PublicAccessLevels'
|
||||
PrivilegeLevels = require '../Authorization/PrivilegeLevels'
|
||||
UserGetter = require '../User/UserGetter'
|
||||
ObjectId = require("mongojs").ObjectId
|
||||
Settings = require('settings-sharelatex')
|
||||
V1Api = require "../V1/V1Api"
|
||||
|
@ -111,7 +110,7 @@ module.exports = TokenAccessHandler =
|
|||
if privilegeLevel != PrivilegeLevels.READ_ONLY
|
||||
project.tokens.readOnly = ''
|
||||
|
||||
getV1DocInfo: (token, v2UserId, callback=(err, info)->) ->
|
||||
getV1DocInfo: (token, callback=(err, info)->) ->
|
||||
# default to allowing access and not exported
|
||||
return callback(null, {
|
||||
allow: true
|
||||
|
@ -119,9 +118,6 @@ module.exports = TokenAccessHandler =
|
|||
exported: false
|
||||
}) unless Settings.apis?.v1?
|
||||
|
||||
UserGetter.getUser v2UserId, { overleaf: 1 }, (err, user) ->
|
||||
return callback(err) if err?
|
||||
v1UserId = user.overleaf?.id
|
||||
V1Api.request { url: "/api/v1/sharelatex/users/#{v1UserId}/docs/#{token}/info" }, (err, response, body) ->
|
||||
return callback err if err?
|
||||
callback null, body
|
||||
V1Api.request { url: "/api/v1/sharelatex/docs/#{token}/info" }, (err, response, body) ->
|
||||
return callback err if err?
|
||||
callback null, body
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
request = require 'request'
|
||||
settings = require 'settings-sharelatex'
|
||||
Errors = require '../Errors/Errors'
|
||||
|
||||
# TODO: check what happens when these settings aren't defined
|
||||
DEFAULT_V1_PARAMS = {
|
||||
|
@ -39,10 +38,6 @@ module.exports = V1Api =
|
|||
return callback(error, response, body) if error?
|
||||
if 200 <= response.statusCode < 300 or response.statusCode in (options.expectedStatusCodes or [])
|
||||
callback null, response, body
|
||||
else if response.statusCode == 403
|
||||
error = new Errors.ForbiddenError("overleaf v1 returned forbidden")
|
||||
error.statusCode = response.statusCode
|
||||
callback error
|
||||
else
|
||||
error = new Error("overleaf v1 returned non-success code: #{response.statusCode} #{options.method} #{options.uri}")
|
||||
error.statusCode = response.statusCode
|
||||
|
|
|
@ -29,7 +29,5 @@ module.exports = Features =
|
|||
Settings.overleaf? and isEnabled
|
||||
when 'redirect-sl'
|
||||
return Settings.redirectToV2?
|
||||
when 'force-import-to-v2'
|
||||
return Settings.forceImportToV2
|
||||
else
|
||||
throw new Error("unknown feature: #{feature}")
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
extends ../layout
|
||||
|
||||
block content
|
||||
main.content
|
||||
.container
|
||||
.row
|
||||
.col-sm-8.col-sm-offset-2
|
||||
h1.text-center Move project to Overleaf v2
|
||||
img.v2-import__img(
|
||||
src="/img/v1-import/v2-editor.png"
|
||||
alt="The new V2 editor."
|
||||
)
|
||||
|
||||
if hasOwner
|
||||
p.text-center.row-spaced-small
|
||||
| #[strong #{name}] has not yet been moved into the new version of
|
||||
| Overleaf. You will need to move it in order to continue working
|
||||
| on it. It should only take a few seconds.
|
||||
|
||||
form(
|
||||
async-form="v2Import"
|
||||
name="v2ImportForm"
|
||||
action="/overleaf/project/"+ projectId + "/import"
|
||||
method="POST"
|
||||
ng-cloak
|
||||
)
|
||||
input(name='_csrf', type='hidden', value=csrfToken)
|
||||
form-messages(for="v2ImportForm")
|
||||
input.row-spaced.btn.btn-primary.text-center.center-block(
|
||||
type="submit"
|
||||
value="Move Project and Continue"
|
||||
ng-disabled="v2ImportForm.inflight || v2ImportForm.response.success"
|
||||
)
|
||||
else
|
||||
p.text-center.row-spaced.small
|
||||
| #[strong #{name}] has not yet been moved into the new version of
|
||||
| Overleaf. This project was created anonymously and therefore
|
||||
| cannot be automatically imported. Please download a zip file of
|
||||
| the project and upload that to continue editing it.
|
||||
|
||||
button.row-spaced.btn.btn-primary.text-center.center-block
|
||||
| Download project zip file
|
||||
|
||||
|
||||
h3 What can I do once I've moved my project?
|
||||
ul
|
||||
li New & Improved Editor
|
||||
li Tracked Changed & Comments
|
||||
li Git access (still supported)
|
||||
|
||||
h3 Is there anything I can't do once I've moved my project to
|
||||
ul
|
||||
li Assignments
|
||||
li F1000 Research Workflow
|
||||
li
|
||||
| Files you have imported from CiteULike and Plotly will become
|
||||
| ordinary files, but you can still use these services by
|
||||
| downloading and uploading files
|
||||
li
|
||||
| Publishing to Figshare and PeerWith are not presently available,
|
||||
| but improved versions will be coming back
|
|
@ -7,5 +7,4 @@
|
|||
@import "app/institution-hub.less";
|
||||
@import "app/publisher-hub.less";
|
||||
@import "app/admin-hub.less";
|
||||
@import "app/import.less";
|
||||
@import "components/overbox.less";
|
|
@ -1,5 +0,0 @@
|
|||
.v2-import__img {
|
||||
.img-responsive;
|
||||
.center-block;
|
||||
width: 80%;
|
||||
}
|
|
@ -132,7 +132,7 @@ module.exports = MockV1Api =
|
|||
console.error "error starting MockV1Api:", error.message
|
||||
process.exit(1)
|
||||
|
||||
app.get '/api/v1/sharelatex/users/:user_id/docs/:token/info', (req, res, next) =>
|
||||
app.get '/api/v1/sharelatex/docs/:token/info', (req, res, next) =>
|
||||
res.json { allow: true, exported: false }
|
||||
|
||||
MockV1Api.run()
|
||||
|
|
|
@ -35,9 +35,6 @@ describe "TokenAccessController", ->
|
|||
exported: false
|
||||
})
|
||||
}
|
||||
'../../infrastructure/Features': @Features = {
|
||||
hasFeature: sinon.stub().returns(false)
|
||||
}
|
||||
'logger-sharelatex': {log: sinon.stub(), err: sinon.stub()}
|
||||
'settings-sharelatex': {
|
||||
overleaf:
|
||||
|
@ -253,7 +250,6 @@ describe "TokenAccessController", ->
|
|||
@req.url = '/123abc'
|
||||
@res = new MockResponse()
|
||||
@res.redirect = sinon.stub()
|
||||
@res.render = sinon.stub()
|
||||
@next = sinon.stub()
|
||||
@req.params['read_and_write_token'] = '123abc'
|
||||
@TokenAccessHandler.findProjectWithReadAndWriteToken = sinon.stub()
|
||||
|
@ -261,11 +257,8 @@ describe "TokenAccessController", ->
|
|||
|
||||
describe 'when project was not exported from v1', ->
|
||||
beforeEach ->
|
||||
@TokenAccessHandler.getV1DocInfo = sinon.stub().yields(null, {
|
||||
allow: true
|
||||
exists: true
|
||||
exported: false
|
||||
})
|
||||
@TokenAccessHandler.checkV1ProjectExported = sinon.stub()
|
||||
.callsArgWith(1, null, false)
|
||||
@TokenAccessController.readAndWriteToken @req, @res, @next
|
||||
|
||||
it 'should redirect to v1', (done) ->
|
||||
|
@ -276,87 +269,14 @@ describe "TokenAccessController", ->
|
|||
)).to.equal true
|
||||
done()
|
||||
|
||||
describe 'when project was not exported from v1 but forcing import to v2', ->
|
||||
beforeEach ->
|
||||
@Features.hasFeature.returns(true)
|
||||
|
||||
describe 'with project name', ->
|
||||
beforeEach ->
|
||||
@TokenAccessHandler.getV1DocInfo = sinon.stub().yields(null, {
|
||||
allow: true
|
||||
exists: true
|
||||
exported: false
|
||||
has_owner: true
|
||||
name: 'A title'
|
||||
})
|
||||
@TokenAccessController.readAndWriteToken @req, @res, @next
|
||||
|
||||
it 'should render v2-import page with name', (done) ->
|
||||
expect(@res.render.calledWith(
|
||||
'project/v2-import',
|
||||
{
|
||||
projectId: '123abc'
|
||||
name: 'A title'
|
||||
hasOwner: true
|
||||
}
|
||||
)).to.equal true
|
||||
done()
|
||||
|
||||
describe 'with project owner', ->
|
||||
beforeEach ->
|
||||
@TokenAccessHandler.getV1DocInfo = sinon.stub().yields(null, {
|
||||
allow: true
|
||||
exists: true
|
||||
exported: false
|
||||
has_owner: true
|
||||
name: 'A title'
|
||||
})
|
||||
@TokenAccessController.readAndWriteToken @req, @res, @next
|
||||
|
||||
it 'should render v2-import page', (done) ->
|
||||
expect(@res.render.calledWith(
|
||||
'project/v2-import',
|
||||
{
|
||||
projectId: '123abc',
|
||||
hasOwner: true
|
||||
name: 'A title'
|
||||
}
|
||||
)).to.equal true
|
||||
done()
|
||||
|
||||
describe 'without project owner', ->
|
||||
beforeEach ->
|
||||
@TokenAccessHandler.getV1DocInfo = sinon.stub().yields(null, {
|
||||
allow: true
|
||||
exists: true
|
||||
exported: false
|
||||
has_owner: false
|
||||
name: 'A title'
|
||||
})
|
||||
@TokenAccessController.readAndWriteToken @req, @res, @next
|
||||
|
||||
it 'should render v2-import page', (done) ->
|
||||
expect(@res.render.calledWith(
|
||||
'project/v2-import',
|
||||
{
|
||||
projectId: '123abc',
|
||||
hasOwner: false
|
||||
name: 'A title'
|
||||
}
|
||||
)).to.equal true
|
||||
done()
|
||||
|
||||
describe 'when project was exported from v1', ->
|
||||
beforeEach ->
|
||||
@TokenAccessHandler.getV1DocInfo = sinon.stub().yields(null, {
|
||||
allow: true
|
||||
exists: true
|
||||
exported: true
|
||||
})
|
||||
@TokenAccessHandler.checkV1ProjectExported = sinon.stub()
|
||||
.callsArgWith(1, null, false)
|
||||
@TokenAccessController.readAndWriteToken @req, @res, @next
|
||||
|
||||
it 'should call next with a not-found error', (done) ->
|
||||
expect(@next.callCount).to.equal 1
|
||||
expect(@next.callCount).to.equal 0
|
||||
done()
|
||||
|
||||
describe 'when token access is off, but user has higher access anyway', ->
|
||||
|
|
|
@ -21,7 +21,6 @@ describe "TokenAccessHandler", ->
|
|||
'../../models/Project': {Project: @Project = {}}
|
||||
'settings-sharelatex': @settings = {}
|
||||
'../Collaborators/CollaboratorsHandler': @CollaboratorsHandler = {}
|
||||
'../User/UserGetter': @UserGetter = {}
|
||||
'../V1/V1Api': @V1Api = {
|
||||
request: sinon.stub()
|
||||
}
|
||||
|
@ -494,12 +493,11 @@ describe "TokenAccessHandler", ->
|
|||
|
||||
describe 'getV1DocInfo', ->
|
||||
beforeEach ->
|
||||
@v2UserId = 123
|
||||
@callback = sinon.stub()
|
||||
|
||||
describe 'when v1 api not set', ->
|
||||
beforeEach ->
|
||||
@TokenAccessHandler.getV1DocInfo @token, @v2UserId, @callback
|
||||
@TokenAccessHandler.getV1DocInfo @token, @callback
|
||||
|
||||
it 'should not check access and return default info', ->
|
||||
expect(@V1Api.request.called).to.equal false
|
||||
|
@ -513,45 +511,19 @@ describe "TokenAccessHandler", ->
|
|||
beforeEach ->
|
||||
@settings.apis = { v1: 'v1' }
|
||||
|
||||
describe 'on UserGetter.getUser success', ->
|
||||
describe 'on success', ->
|
||||
beforeEach ->
|
||||
@UserGetter.getUser = sinon.stub().yields(null, {
|
||||
overleaf: { id: 1 }
|
||||
})
|
||||
@TokenAccessHandler.getV1DocInfo @token, @v2UserId, @callback
|
||||
|
||||
it 'should get user', ->
|
||||
expect(@UserGetter.getUser.calledWith(@v2UserId)).to.equal true
|
||||
|
||||
describe 'on UserGetter.getUser error', ->
|
||||
beforeEach ->
|
||||
@error = new Error('failed to get user')
|
||||
@UserGetter.getUser = sinon.stub().yields(@error)
|
||||
@TokenAccessHandler.getV1DocInfo @token, @v2UserId, @callback
|
||||
|
||||
it 'should callback with error', ->
|
||||
expect(@callback.calledWith @error).to.equal true
|
||||
|
||||
describe 'on V1Api.request success', ->
|
||||
beforeEach ->
|
||||
@v1UserId = 1
|
||||
@UserGetter.getUser = sinon.stub().yields(null, {
|
||||
overleaf: { id: @v1UserId }
|
||||
})
|
||||
@V1Api.request = sinon.stub().callsArgWith(1, null, null, 'mock-data')
|
||||
@TokenAccessHandler.getV1DocInfo @token, @v2UserId, @callback
|
||||
@TokenAccessHandler.getV1DocInfo @token, @callback
|
||||
|
||||
it 'should return response body', ->
|
||||
expect(@V1Api.request.calledWith { url: "/api/v1/sharelatex/users/#{@v1UserId}/docs/#{@token}/info" }).to.equal true
|
||||
expect(@V1Api.request.calledWith { url: "/api/v1/sharelatex/docs/#{@token}/info" }).to.equal true
|
||||
expect(@callback.calledWith null, 'mock-data').to.equal true
|
||||
|
||||
describe 'on V1Api.request error', ->
|
||||
describe 'on error', ->
|
||||
beforeEach ->
|
||||
@UserGetter.getUser = sinon.stub().yields(null, {
|
||||
overleaf: { id: 1 }
|
||||
})
|
||||
@V1Api.request = sinon.stub().callsArgWith(1, 'error')
|
||||
@TokenAccessHandler.getV1DocInfo @token, @v2UserId, @callback
|
||||
@TokenAccessHandler.getV1DocInfo @token, @callback
|
||||
|
||||
it 'should callback with error', ->
|
||||
expect(@callback.calledWith 'error').to.equal true
|
||||
|
|
Loading…
Reference in a new issue