From 3343f8a8135506f6d1e099b44aa2e0443e73721b Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 11 Feb 2019 10:17:43 +0200 Subject: [PATCH] Allowed canViewCharacter to take in a character instead of a charId to save a database read --- app/lib/functions/permissions.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/lib/functions/permissions.js b/app/lib/functions/permissions.js index 8f160297..37b4ff73 100644 --- a/app/lib/functions/permissions.js +++ b/app/lib/functions/permissions.js @@ -5,12 +5,14 @@ canEditCharacter = function(charId, userId){ return (userId === char.owner || _.contains(char.writers, userId)); }; -canViewCharacter = function(charId, userId){ +canViewCharacter = function(char, userId){ userId = userId || Meteor.userId(); - var char = Characters.findOne( - charId, - {fields: {owner: 1, writers: 1, readers: 1, "settings.viewPermission": 1}} - ); + if (typeof char !== 'object'){ + char = Characters.findOne( + charId, + {fields: {owner: 1, writers: 1, readers: 1, "settings.viewPermission": 1}} + ); + } if (!char) return true; return userId === char.owner || char.settings.viewPermission === "public" ||