Merge pull request #5575 from overleaf/bg-improve-undelete-doc-admin-page

add deletedAt timestamp to undelete doc admin page

GitOrigin-RevId: 46893aae35290e42886320731a5f68811fb3ed46
This commit is contained in:
Brian Gough 2021-10-26 14:32:01 +01:00 committed by Copybot
parent e681c6322f
commit 4688cb7b54
2 changed files with 49 additions and 11 deletions

View file

@ -117,14 +117,18 @@ module.exports = HttpController = {
logger.log({ project_id }, 'getting all deleted docs') logger.log({ project_id }, 'getting all deleted docs')
DocManager.getAllDeletedDocs( DocManager.getAllDeletedDocs(
project_id, project_id,
{ name: true }, { name: true, deletedAt: true },
function (error, docs) { function (error, docs) {
if (error) { if (error) {
return next(error) return next(error)
} }
res.json( res.json(
docs.map(doc => { docs.map(doc => {
return { _id: doc._id.toString(), name: doc.name } return {
_id: doc._id.toString(),
name: doc.name,
deletedAt: doc.deletedAt,
}
}) })
) )
} }

View file

@ -302,7 +302,13 @@ describe('Delete via PATCH', function () {
describe('when the doc gets a name on delete', function () { describe('when the doc gets a name on delete', function () {
beforeEach(function (done) { beforeEach(function (done) {
DocstoreClient.deleteDoc(this.project_id, this.doc_id, done) this.deletedAt = new Date()
DocstoreClient.deleteDocWithDate(
this.project_id,
this.doc_id,
this.deletedAt,
done
)
}) })
it('should show the doc in deleted docs response', function (done) { it('should show the doc in deleted docs response', function (done) {
@ -311,7 +317,11 @@ describe('Delete via PATCH', function () {
(error, deletedDocs) => { (error, deletedDocs) => {
if (error) return done(error) if (error) return done(error)
expect(deletedDocs).to.deep.equal([ expect(deletedDocs).to.deep.equal([
{ _id: this.doc_id.toString(), name: 'main.tex' }, {
_id: this.doc_id.toString(),
name: 'main.tex',
deletedAt: this.deletedAt.toISOString(),
},
]) ])
done() done()
} }
@ -331,9 +341,11 @@ describe('Delete via PATCH', function () {
) )
}) })
beforeEach('delete doc2', function (done) { beforeEach('delete doc2', function (done) {
DocstoreClient.deleteDocWithName( this.deletedAt2 = new Date()
DocstoreClient.deleteDocWithDateAndName(
this.project_id, this.project_id,
this.doc_id2, this.doc_id2,
this.deletedAt2,
'two.tex', 'two.tex',
done done
) )
@ -350,9 +362,11 @@ describe('Delete via PATCH', function () {
) )
}) })
beforeEach('delete doc3', function (done) { beforeEach('delete doc3', function (done) {
DocstoreClient.deleteDocWithName( this.deletedAt3 = new Date()
DocstoreClient.deleteDocWithDateAndName(
this.project_id, this.project_id,
this.doc_id3, this.doc_id3,
this.deletedAt3,
'three.tex', 'three.tex',
done done
) )
@ -364,9 +378,21 @@ describe('Delete via PATCH', function () {
if (error) return done(error) if (error) return done(error)
expect(deletedDocs).to.deep.equal([ expect(deletedDocs).to.deep.equal([
{ _id: this.doc_id3.toString(), name: 'three.tex' }, {
{ _id: this.doc_id2.toString(), name: 'two.tex' }, _id: this.doc_id3.toString(),
{ _id: this.doc_id.toString(), name: 'main.tex' }, name: 'three.tex',
deletedAt: this.deletedAt3.toISOString(),
},
{
_id: this.doc_id2.toString(),
name: 'two.tex',
deletedAt: this.deletedAt2.toISOString(),
},
{
_id: this.doc_id.toString(),
name: 'main.tex',
deletedAt: this.deletedAt.toISOString(),
},
]) ])
done() done()
} }
@ -390,8 +416,16 @@ describe('Delete via PATCH', function () {
if (error) return done(error) if (error) return done(error)
expect(deletedDocs).to.deep.equal([ expect(deletedDocs).to.deep.equal([
{ _id: this.doc_id3.toString(), name: 'three.tex' }, {
{ _id: this.doc_id2.toString(), name: 'two.tex' }, _id: this.doc_id3.toString(),
name: 'three.tex',
deletedAt: this.deletedAt3.toISOString(),
},
{
_id: this.doc_id2.toString(),
name: 'two.tex',
deletedAt: this.deletedAt2.toISOString(),
},
// dropped main.tex // dropped main.tex
]) ])
done() done()