More work on individual device thru user groups.

Ylian Saint-Hilaire committed Apr 13, 2020 at 10:50 UTC 21d6d43593d02324f4a43945ddc23e8769aebb43
4 files changed +55 -8
meshuser.js
+12 -2
@@ -487,8 +487,18 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
487 // Request a list of all meshes this user as rights to
488 links = parent.GetAllMeshIdWithRights(user);
489
490 - // Add any nodes with direct rights
491 - if (obj.user.links != null) { for (var i in obj.user.links) { if (i.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(i); } } }
490 + // Add any nodes with direct rights or any nodes with user group direct rights
491 + if (obj.user.links != null) {
492 + for (var i in obj.user.links) {
493 + if (i.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(i); }
494 + else if (i.startsWith('ugrp/')) {
495 + const g = parent.userGroups[i];
496 + if ((g != null) && (g.links != null)) {
497 + for (var j in g.links) { if (j.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(j); } }
498 + }
499 + }
500 + }
501 + }
502 } else {
503 // Request list of all nodes for one specific meshid
504 meshid = command.meshid;
views/default-mobile.handlebars
+7
@@ -3539,6 +3539,13 @@
3539 // Check direct device rights using device data
3540 if ((node.links != null) && (node.links[userid] != null)) { r |= node.links[userid].rights; } // TODO: Deal with reverse permissions
3541
3542 + // Check direct device rights thru user groups
3543 + if ((node.links != null) && (userinfo.links != null)) {
3544 + for (var i in node.links) {
3545 + if (i.startsWith('ugrp/') && (userinfo.links[i] != null) && (node.links[i].rights != null)) { r |= node.links[i].rights; }
3546 + }
3547 + }
3548 +
3549 // Check direct device rights using user data
3550 /*
3551 if (userid == userinfo._id) { user = userinfo; } else { if (users != null) { user = users[userid]; } }
views/default.handlebars
+20 -6
@@ -8635,7 +8635,6 @@
8635 QE('dp2meshid', selected == null);
8636 QE('dp2nodeid', selected == null);
8637 } else if (userid === 7) {
8638 - console.log('a1');
8638 setDialogMode(2, (selected == null)?"Add Device Permissions":"Edit Device Permissions", 3, p20showAddMeshUserDialogEx, x, userid);
8639 QE('dp2meshid', selected == null);
8640 QE('dp2nodeid', selected == null);
@@ -8739,7 +8738,6 @@
8738 }
8739
8740 function p20validateAddMeshUserDialog(updateId) {
8742 - console.log('p20validateAddMeshUserDialog', updateId);
8741 var ok = true;
8742
8743 if (updateId === 4) {
@@ -8871,7 +8869,7 @@
8869 if (currentNode != null) { meshserver.send({ action: 'adddeviceuser', nodeid: currentNode._id, nodename: currentNode.name, userids: [ ugrpid ], rights: meshadmin }); }
8870 } else if (t === 7) {
8871 var nodeid = decodeURIComponent(Q('dp2nodeid').value), node = getNodeFromId(nodeid);
8874 - if (node != null) { meshserver.send({ action: 'adddeviceuser', nodeid: nodeid, nodename: node.name, userids: [ currentGroup._id ], rights: meshadmin }); }
8872 + if (node != null) { meshserver.send({ action: 'adddeviceuser', nodeid: nodeid, nodename: node.name, userids: [ currentUserGroup._id ], rights: meshadmin }); }
8873 } else {
8874 if (t == null) {
8875 var users = Q('dp20username').value.split(','), users2 = [];
@@ -9762,6 +9760,15 @@
9760 element.children[0].children[0].style['background-color'] = ((over == 0) ? '#c9c9c9' : '#b9b9b9');
9761 }
9762
9763 + // Highlights the user being hovered
9764 + function userMouseHover2(element, over) {
9765 + var e = element.children[0].children[0];
9766 + e.children[1].classList.remove('g1s');
9767 + e.children[2].classList.remove('g2s');
9768 + if (over == 1) { e.children[1].classList.add('g1s'); e.children[2].classList.add('g2s'); }
9769 + element.children[0].children[0].style['background-color'] = ((over == 0) ? '#c9c9c9' : '#b9b9b9');
9770 + }
9771 +
9772 function userChat(e, userid, name) {
9773 haltEvent(e);
9774 var url = '/messenger?id=meshmessenger/' + userid + '/' + encodeURIComponent(userinfo._id) + '&title=' + name;
@@ -10057,7 +10064,7 @@
10064 function addUserGroupHtml(group) {
10065 var usercount = 0, meshcount = 0;
10066 if (group.links) { for (var i in group.links) { if (i.startsWith('user/')) { usercount++; } if (i.startsWith('mesh/')) { meshcount++; } } }
10060 - var x = '<tr tabindex=0 onmouseover=userMouseHover(this,1) onmouseout=userMouseHover(this,0) onkeypress="if (event.key==\'Enter\') gotoUserGroup(\'' + encodeURIComponent(group._id) + '\')"><td style=cursor:pointer onclick=gotoUserGroup(\"' + encodeURIComponent(group._id) + '\")>';
10067 + var x = '<tr tabindex=0 onmouseover=userMouseHover2(this,1) onmouseout=userMouseHover2(this,0) onkeypress="if (event.key==\'Enter\') gotoUserGroup(\'' + encodeURIComponent(group._id) + '\')"><td style=cursor:pointer onclick=gotoUserGroup(\"' + encodeURIComponent(group._id) + '\")>';
10068 x += '<div class=bar style=width:100%>';
10069 x += '<div class=baricon><div class=m4></div></div>';
10070 x += '<div class=g1></div><div class=g2></div>';
@@ -11360,7 +11367,7 @@
11367 } else if ((xxcurrentView >= 30) && (xxcurrentView <= 39)) { // User Link
11368 if (currentUser != null) { urlviewmode = '?viewmode=' + xxcurrentView + '&gotouser=' + currentUser._id.split('/')[2]; }
11369 } else if ((xxcurrentView >= 51) && (xxcurrentView <= 59)) { // User Group Link
11363 - if (currentUserGroup != null) { urlviewmode = '?viewmode=' + xxcurrentView + '&gotougrp=' + currentUserGroup._id.split('/')[2]; }
11370 + if ((currentUserGroup != null) && (currentUserGroup._id != null)) { urlviewmode = '?viewmode=' + xxcurrentView + '&gotougrp=' + currentUserGroup._id.split('/')[2]; }
11371 } else if (xxcurrentView > 1) { urlviewmode = '?viewmode=' + xxcurrentView; }
11372 for (var i in urlargs) { urlviewmode += (((urlviewmode == '')?'?':'&') + i + '=' + urlargs[i]); }
11373 try { window.history.replaceState({}, document.title, window.location.pathname + urlviewmode); } catch (ex) { }
@@ -11687,13 +11694,20 @@
11694 if (typeof node == 'string') { node = getNodeFromId(node); if (node == null) { return 0; } }
11695 var r = GetMeshRights(node.meshid, userid);
11696 if (r == 0xFFFFFFFF) return r;
11690 - var user = null;
11697
11698 // Check direct device rights using device data
11699 if ((node.links != null) && (node.links[userid] != null)) { r |= node.links[userid].rights; } // TODO: Deal with reverse permissions
11700
11701 + // Check direct device rights thru user groups
11702 + if ((node.links != null) && (userinfo.links != null)) {
11703 + for (var i in node.links) {
11704 + if (i.startsWith('ugrp/') && (userinfo.links[i] != null) && (node.links[i].rights != null)) { r |= node.links[i].rights; }
11705 + }
11706 + }
11707 +
11708 // Check direct device rights using user data
11709 /*
11710 + var user = null;
11711 if (userid == userinfo._id) { user = userinfo; } else { if (users != null) { user = users[userid]; } }
11712 if ((user != null) && (user.links != null)) {
11713 var r2 = user.links[node._id];
webserver.js
+16
@@ -4274,6 +4274,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4274 rights |= r.rights; // TODO: Deal with reverse rights
4275 visible = true;
4276 }
4277 + r = g.links[nodeid];
4278 + if (r != null) {
4279 + if (r.rights == 0xFFFFFFFF) { func(nodes[0], 0xFFFFFFFF, true); return; } // User has full rights thru a user group direct link, stop here.
4280 + rights |= r.rights; // TODO: Deal with reverse rights
4281 + visible = true;
4282 + }
4283 }
4284 }
4285 }
@@ -4438,6 +4444,16 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4444
4445 // Check direct device rights using device data
4446 if ((user.links != null) && (user.links[nodeid] != null)) { r |= user.links[nodeid].rights; } // TODO: Deal with reverse permissions
4447 + if (r == 0xFFFFFFFF) return r;
4448 +
4449 + // Check direct device rights thru a user group
4450 + for (var i in user.links) {
4451 + if (i.startsWith('ugrp')) {
4452 + const g = obj.userGroups[i];
4453 + if (g && (g.links[nodeid] != null)) { r |= g.links[nodeid].rights; }
4454 + }
4455 + }
4456 +
4457 return r;
4458 }
4459