Просмотр исходного кода

[DocstoreManager] patchDoc: allow updates after deletion

Jakob Ackermann 5 лет назад
Родитель
Сommit
26bc074098

+ 0 - 2
services/docstore/app.js

@@ -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')
   }

+ 0 - 6
services/docstore/app/js/DocManager.js

@@ -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) => {

+ 0 - 3
services/docstore/app/js/Errors.js

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

+ 0 - 37
services/docstore/test/acceptance/js/DeletingDocsTests.js

@@ -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(

+ 0 - 27
services/docstore/test/unit/js/DocManagerTests.js

@@ -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)