From da8947d25e480c6022caa2d3e33a35af7bb0d722 Mon Sep 17 00:00:00 2001 From: Noah Zalev Date: Sat, 24 Jul 2021 21:57:38 -0400 Subject: [PATCH] Factor out meshuser extraids --- meshuser.js | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/meshuser.js b/meshuser.js index 2d655efa..80efe729 100644 --- a/meshuser.js +++ b/meshuser.js @@ -657,17 +657,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use links = parent.GetAllMeshIdWithRights(user); // Add any nodes with direct rights or any nodes with user group direct rights - if (obj.user.links != null) { - for (var i in obj.user.links) { - if (i.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(i); } - else if (i.startsWith('ugrp/')) { - const g = parent.userGroups[i]; - if ((g != null) && (g.links != null)) { - for (var j in g.links) { if (j.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(j); } } - } - } - } - } + extraids = getUserExtraIds(); } else { // Request list of all nodes for one specific meshid meshid = command.meshid; @@ -6181,6 +6171,22 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use return true; } + function getUserExtraIds() { + var extraids = null; + if (obj.user.links != null) { + for (var i in obj.user.links) { + if (i.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(i); } + else if (i.startsWith('ugrp/')) { + const g = parent.userGroups[i]; + if ((g != null) && (g.links != null)) { + for (var j in g.links) { if (j.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(j); } } + } + } + } + } + return extraids; + } + function csvClean(s) { return '\"' + s.split('\"').join('').split(',').join('').split('\r').join('').split('\n').join('') + '\"'; } // Return detailed information about an array of nodeid's @@ -6229,18 +6235,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use var links = parent.GetAllMeshIdWithRights(user); // Add any nodes with direct rights or any nodes with user group direct rights - var extraids = null; - if (obj.user.links != null) { - for (var i in obj.user.links) { - if (i.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(i); } - else if (i.startsWith('ugrp/')) { - const g = parent.userGroups[i]; - if ((g != null) && (g.links != null)) { - for (var j in g.links) { if (j.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(j); } } - } - } - } - } + var extraids = getUserExtraIds(); // Request a list of all nodes db.GetAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', null, function (err, docs) {