[DocstoreManager] patchDoc: allow updates after deletion

This commit is contained in:
Jakob Ackermann 2021-02-17 11:31:01 +00:00
parent dd4f4057f4
commit 26bc074098
5 changed files with 0 additions and 75 deletions

View file

@ -87,8 +87,6 @@ app.use(function (error, req, res, next) {
logger.error({ err: error, req }, 'request errored')
if (error instanceof Errors.NotFoundError) {
return res.sendStatus(404)
} else if (error instanceof Errors.InvalidOperation) {
return res.status(400).send(error.message)
} else {
return res.status(500).send('Oops, something went wrong')
}

View file

@ -336,12 +336,6 @@ module.exports = DocManager = {
)
}
// deletion is a one-way operation
if (doc.deleted)
return callback(
new Errors.InvalidOperation('Cannot PATCH after doc deletion')
)
if (meta.deleted && Settings.docstore.archiveOnSoftDelete) {
// The user will not read this doc anytime soon. Flush it out of mongo.
DocArchive.archiveDocById(project_id, doc_id, (err) => {

View file

@ -4,10 +4,7 @@ const { Errors } = require('@overleaf/object-persistor')
class Md5MismatchError extends OError {}
class InvalidOperation extends OError {}
module.exports = {
Md5MismatchError,
InvalidOperation,
...Errors
}

View file

@ -212,43 +212,6 @@ describe('Delete via DELETE', function () {
describe('Delete via PATCH', function () {
deleteTestSuite(DocstoreClient.deleteDoc)
describe('deleting a doc twice', function () {
beforeEach('perform 1st DELETE request', function (done) {
DocstoreClient.deleteDoc(this.project_id, this.doc_id, done)
})
beforeEach('get doc before 2nd DELETE request', function (done) {
db.docs.find({ _id: this.doc_id }).toArray((error, docs) => {
if (error) return done(error)
this.docBefore = docs[0]
if (!this.docBefore) return done(new Error('doc not found'))
done()
})
})
beforeEach('perform 2nd DELETE request', function (done) {
DocstoreClient.deleteDoc(this.project_id, this.doc_id, (error, res) => {
this.res1 = res
done(error)
})
})
it('should reject the 2nd request', function () {
expect(this.res1.statusCode).to.equal(400)
})
it('should not alter the previous doc state', function (done) {
db.docs.find({ _id: this.doc_id }).toArray((error, docs) => {
if (error) return done(error)
const docAfter = docs[0]
if (!docAfter) return done(new Error('doc not found'))
expect(docAfter).to.deep.equal(this.docBefore)
done()
})
})
})
describe('when providing a custom doc name in the delete request', function () {
beforeEach(function (done) {
DocstoreClient.deleteDocWithName(

View file

@ -689,33 +689,6 @@ describe('DocManager', function () {
})
})
describe('when the doc is already deleted', function () {
beforeEach(function (done) {
this.MongoManager.findDoc = sinon
.stub()
.yields(null, { _id: ObjectId(this.doc_id), deleted: true })
this.MongoManager.patchDoc = sinon.stub()
this.callback = sinon.stub().callsFake(() => done())
this.DocManager.patchDoc(
this.project_id,
this.doc_id,
'tomato.tex',
this.callback
)
})
it('should reject the operation', function () {
expect(this.callback).to.have.been.calledWith(
sinon.match.has('message', 'Cannot PATCH after doc deletion')
)
})
it('should not persist the change to mongo', function () {
expect(this.MongoManager.patchDoc).to.not.have.been.called
})
})
describe('when the doc does not exist', function () {
beforeEach(function () {
this.MongoManager.findDoc = sinon.stub().yields(null)