mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #87 from overleaf/jpa-restore-non-deleted-only
[DocArchiveManager] optionally do not un-archive soft deleted docs
This commit is contained in:
commit
50cc1c1119
4 changed files with 65 additions and 4 deletions
|
@ -100,7 +100,12 @@ async function archiveDoc(projectId, doc) {
|
|||
}
|
||||
|
||||
async function unArchiveAllDocs(projectId) {
|
||||
const docs = await MongoManager.getArchivedProjectDocs(projectId)
|
||||
let docs
|
||||
if (settings.docstore.keepSoftDeletedDocsArchived) {
|
||||
docs = await MongoManager.getNonDeletedArchivedProjectDocs(projectId)
|
||||
} else {
|
||||
docs = await MongoManager.getArchivedProjectDocs(projectId)
|
||||
}
|
||||
if (!docs) {
|
||||
throw new Errors.NotFoundError(`No docs for project ${projectId}`)
|
||||
}
|
||||
|
|
|
@ -53,6 +53,15 @@ module.exports = MongoManager = {
|
|||
db.docs.find(query).toArray(callback)
|
||||
},
|
||||
|
||||
getNonDeletedArchivedProjectDocs(project_id, callback) {
|
||||
const query = {
|
||||
project_id: ObjectId(project_id.toString()),
|
||||
deleted: { $ne: true },
|
||||
inS3: true
|
||||
}
|
||||
db.docs.find(query).toArray(callback)
|
||||
},
|
||||
|
||||
upsertIntoDocCollection(project_id, doc_id, updates, callback) {
|
||||
const update = {
|
||||
$set: updates,
|
||||
|
|
|
@ -23,6 +23,8 @@ const Settings = {
|
|||
|
||||
docstore: {
|
||||
archiveOnSoftDelete: process.env.ARCHIVE_ON_SOFT_DELETE === 'true',
|
||||
keepSoftDeletedDocsArchived:
|
||||
process.env.KEEP_SOFT_DELETED_DOCS_ARCHIVED === 'true',
|
||||
|
||||
backend: process.env.BACKEND || 's3',
|
||||
healthCheck: {
|
||||
|
|
|
@ -167,7 +167,7 @@ describe('Archiving', function () {
|
|||
})
|
||||
|
||||
describe('a deleted doc', function () {
|
||||
before(function (done) {
|
||||
beforeEach(function (done) {
|
||||
this.project_id = ObjectId()
|
||||
this.doc = {
|
||||
_id: ObjectId(),
|
||||
|
@ -241,8 +241,8 @@ describe('Archiving', function () {
|
|||
)
|
||||
})
|
||||
|
||||
return describe('after unarchiving from a request for the project', function () {
|
||||
before(function (done) {
|
||||
describe('after unarchiving from a request for the project', function () {
|
||||
beforeEach(function (done) {
|
||||
return DocstoreClient.getAllDocs(
|
||||
this.project_id,
|
||||
(error, res, fetched_docs) => {
|
||||
|
@ -273,6 +273,51 @@ describe('Archiving', function () {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when keepSoftDeletedDocsArchived is enabled', function () {
|
||||
let keepSoftDeletedDocsArchived
|
||||
beforeEach(function overwriteSetting() {
|
||||
keepSoftDeletedDocsArchived =
|
||||
Settings.docstore.keepSoftDeletedDocsArchived
|
||||
Settings.docstore.keepSoftDeletedDocsArchived = true
|
||||
})
|
||||
afterEach(function restoreSetting() {
|
||||
Settings.docstore.keepSoftDeletedDocsArchived = keepSoftDeletedDocsArchived
|
||||
})
|
||||
|
||||
describe('after unarchiving from a request for the project', function () {
|
||||
beforeEach(function (done) {
|
||||
DocstoreClient.getAllDocs(
|
||||
this.project_id,
|
||||
(error, res, fetched_docs) => {
|
||||
this.fetched_docs = fetched_docs
|
||||
if (error) {
|
||||
return done(error)
|
||||
}
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('should not included the deleted', function (done) {
|
||||
this.fetched_docs.length.should.equal(0)
|
||||
done()
|
||||
})
|
||||
|
||||
it('should not have restored the deleted doc to mongo', function (done) {
|
||||
db.docs.findOne({ _id: this.doc._id }, (error, doc) => {
|
||||
if (error) {
|
||||
return done(error)
|
||||
}
|
||||
expect(doc.lines).to.not.exist
|
||||
expect(doc.ranges).to.not.exist
|
||||
expect(doc.inS3).to.equal(true)
|
||||
expect(doc.deleted).to.equal(true)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('archiving a single doc', function () {
|
||||
|
|
Loading…
Reference in a new issue