Added undo delete and recycle bin to library

This commit is contained in:
Stefan Zermatten
2021-08-27 13:00:01 +02:00
parent 518880fa5c
commit 608ab4e588
5 changed files with 107 additions and 4 deletions

View File

@@ -10,17 +10,17 @@ Meteor.startup(() => {
];
/**
* Deletes all soft removed documents that were removed more than 30 minutes ago
* Deletes all soft removed documents that were removed more than 1 day ago
* and were not restored
* @return {Number} Number of documents removed
*/
const deleteOldSoftRemovedDocs = function(){
const now = new Date();
const thirtyMinutesAgo = new Date(now.getTime() - 30*60000);
const yesterday = new Date(now.getTime() - (24 * 60 * 60 * 1000));
collections.forEach(collection => {
collection.remove({
removed: true,
removedAt: {$lt: thirtyMinutesAgo} // dates *before* 30 minutes ago
removedAt: {$lt: yesterday} // dates *before* yesterday
}, function(error){
if (error){
console.error(JSON.stringify(error, null, 2));

View File

@@ -69,6 +69,28 @@ Meteor.publish('libraryNodes', function(libraryId){
});
});
Meteor.publish('softRemovedLibraryNodes', function(libraryId){
if (!libraryId) return [];
libraryIdSchema.validate({libraryId});
this.autorun(function (){
let userId = this.userId;
let library = Libraries.findOne(libraryId);
try { assertViewPermission(library, userId) }
catch(e){
return this.error(e);
}
return [
LibraryNodes.find({
'ancestors.0.id': libraryId,
removed: true,
removedWith: {$exists: false},
}, {
sort: {order: 1},
}),
];
});
});
Meteor.publish('descendantLibraryNodes', function(nodeId){
let node = LibraryNodes.findOne(nodeId);
let libraryId = node?.ancestors[0]?.id;