From d947b62ba4c0fd1d17ffe03a05ebc7157300c88c Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Tue, 22 Nov 2022 21:29:08 +0200 Subject: [PATCH] Fixed events not being selectable for reset in libraries --- app/imports/server/publications/library.js | 52 +++++++++++----------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/app/imports/server/publications/library.js b/app/imports/server/publications/library.js index 67dcf74a..68c378b5 100644 --- a/app/imports/server/publications/library.js +++ b/app/imports/server/publications/library.js @@ -18,6 +18,8 @@ const LIBRARY_NODE_TREE_FIELDS = { slotFillerCondition: 1, removed: 1, removedAt: 1, + // Actions + actionType: 1, // SlotFillers slotQuantityFilled: 1, slotFillerType: 1, @@ -47,7 +49,7 @@ const LIBRARY_NODE_TREE_FIELDS = { } export { LIBRARY_NODE_TREE_FIELDS }; - + Meteor.publish('libraryCollection', function (libraryCollectionId) { this.autorun(function () { let userId = this.userId; @@ -63,10 +65,10 @@ Meteor.publish('libraryCollection', function (libraryCollectionId) { ] }); const libraryCollection = libraryCollectionCursor.fetch()[0]; - if (!libraryCollection) return [ libraryCollectionCursor ]; + if (!libraryCollection) return [libraryCollectionCursor]; this.autorun(function () { const libraryCursor = Libraries.find({ - _id: {$in: libraryCollection.libraries}, + _id: { $in: libraryCollection.libraries }, $or: [ { owner: userId }, { writers: userId }, @@ -76,7 +78,7 @@ Meteor.publish('libraryCollection', function (libraryCollectionId) { }, { sort: { name: 1 } }); - return [ libraryCollectionCursor, libraryCursor ]; + return [libraryCollectionCursor, libraryCursor]; }); }); }) @@ -135,14 +137,14 @@ Meteor.publish('libraries', function () { }); }); -Meteor.publish('library', function(libraryId){ +Meteor.publish('library', function (libraryId) { if (!libraryId) return []; - libraryIdSchema.validate({libraryId}); - this.autorun(function (){ + libraryIdSchema.validate({ libraryId }); + this.autorun(function () { let userId = this.userId; let library = Libraries.findOne(libraryId); try { assertViewPermission(library, userId) } - catch(e){ + catch (e) { return this.error(e); } return Libraries.find({ @@ -152,20 +154,20 @@ Meteor.publish('library', function(libraryId){ }); let libraryIdSchema = new SimpleSchema({ - libraryId:{ + libraryId: { type: String, regEx: SimpleSchema.RegEx.Id, }, }); -Meteor.publish('libraryNodes', function(libraryId){ +Meteor.publish('libraryNodes', function (libraryId) { if (!libraryId) return []; - libraryIdSchema.validate({libraryId}); - this.autorun(function (){ + libraryIdSchema.validate({ libraryId }); + this.autorun(function () { let userId = this.userId; let library = Libraries.findOne(libraryId); try { assertViewPermission(library, userId) } - catch(e){ + catch (e) { return this.error(e); } return [ @@ -191,54 +193,54 @@ Meteor.publish('libraryNode', function (libraryNodeId) { nodeIdSchema.validate({ libraryNodeId }); this.autorun(function () { const userId = this.userId; - const nodeCursor = LibraryNodes.find({_id: libraryNodeId}); + const nodeCursor = LibraryNodes.find({ _id: libraryNodeId }); let node = nodeCursor.fetch()[0]; try { assertDocViewPermission(node, userId) } catch (e) { return this.error(e); } - return [ nodeCursor ]; + return [nodeCursor]; }); }); -Meteor.publish('softRemovedLibraryNodes', function(libraryId){ +Meteor.publish('softRemovedLibraryNodes', function (libraryId) { if (!libraryId) return []; - libraryIdSchema.validate({libraryId}); - this.autorun(function (){ + libraryIdSchema.validate({ libraryId }); + this.autorun(function () { let userId = this.userId; let library = Libraries.findOne(libraryId); try { assertViewPermission(library, userId) } - catch(e){ + catch (e) { return this.error(e); } return [ LibraryNodes.find({ 'ancestors.0.id': libraryId, removed: true, - removedWith: {$exists: false}, + removedWith: { $exists: false }, }, { - sort: {order: 1}, + sort: { order: 1 }, }), ]; }); }); -Meteor.publish('descendantLibraryNodes', function(nodeId){ +Meteor.publish('descendantLibraryNodes', function (nodeId) { let node = LibraryNodes.findOne(nodeId); let libraryId = node?.ancestors[0]?.id; if (!libraryId) return []; - this.autorun(function (){ + this.autorun(function () { let userId = this.userId; let library = Libraries.findOne(libraryId); try { assertViewPermission(library, userId) } - catch(e){ + catch (e) { return this.error(e); } return [ LibraryNodes.find({ 'ancestors.id': nodeId, }, { - sort: {order: 1}, + sort: { order: 1 }, }), ]; });