Factor out meshuser extraids

Noah Zalev committed Jul 24, 2021 at 21:57 UTC da8947d25e480c6022caa2d3e33a35af7bb0d722
1 file changed +18 -23
meshuser.js
+18 -23
@@ -657,17 +657,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
657 links = parent.GetAllMeshIdWithRights(user);
658
659 // Add any nodes with direct rights or any nodes with user group direct rights
660 - if (obj.user.links != null) {
661 - for (var i in obj.user.links) {
662 - if (i.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(i); }
663 - else if (i.startsWith('ugrp/')) {
664 - const g = parent.userGroups[i];
665 - if ((g != null) && (g.links != null)) {
666 - for (var j in g.links) { if (j.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(j); } }
667 - }
668 - }
669 - }
670 - }
660 + extraids = getUserExtraIds();
661 } else {
662 // Request list of all nodes for one specific meshid
663 meshid = command.meshid;
@@ -6181,6 +6171,22 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
6171 return true;
6172 }
6173
6174 + function getUserExtraIds() {
6175 + var extraids = null;
6176 + if (obj.user.links != null) {
6177 + for (var i in obj.user.links) {
6178 + if (i.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(i); }
6179 + else if (i.startsWith('ugrp/')) {
6180 + const g = parent.userGroups[i];
6181 + if ((g != null) && (g.links != null)) {
6182 + for (var j in g.links) { if (j.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(j); } }
6183 + }
6184 + }
6185 + }
6186 + }
6187 + return extraids;
6188 + }
6189 +
6190 function csvClean(s) { return '\"' + s.split('\"').join('').split(',').join('').split('\r').join('').split('\n').join('') + '\"'; }
6191
6192 // Return detailed information about an array of nodeid's
@@ -6229,18 +6235,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
6235 var links = parent.GetAllMeshIdWithRights(user);
6236
6237 // Add any nodes with direct rights or any nodes with user group direct rights
6232 - var extraids = null;
6233 - if (obj.user.links != null) {
6234 - for (var i in obj.user.links) {
6235 - if (i.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(i); }
6236 - else if (i.startsWith('ugrp/')) {
6237 - const g = parent.userGroups[i];
6238 - if ((g != null) && (g.links != null)) {
6239 - for (var j in g.links) { if (j.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(j); } }
6240 - }
6241 - }
6242 - }
6243 - }
6238 + var extraids = getUserExtraIds();
6239
6240 // Request a list of all nodes
6241 db.GetAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', null, function (err, docs) {