More work on device permissions.

Ylian Saint-Hilaire committed Mar 27, 2020 at 17:57 UTC 1df511d1d495c49100fb9145ebb7d811744a6fc4
2 files changed +52 -8
translate/translate.json
+1 -1
@@ -27645,4 +27645,4 @@
27645 ]
27646 }
27647 ]
27648 -}
27648 +}
\ No newline at end of file
views/default.handlebars
+51 -7
@@ -474,6 +474,7 @@
474 </table><br />
475 <div id=p10html2></div>
476 <div id=p10html3></div>
477 + <div id=p10html4></div>
478 </div>
479 <div id=p11 class="noselect" style="display:none">
480 <div id="p11title">
@@ -5052,6 +5053,39 @@
5053 if (lastTab != null && Q('p19ph-' + lastTab) != null) pluginHandler.callPluginPage(lastTab, Q('p19ph-' + lastTab));
5054 }
5055
5056 + // Show special user permissions
5057 + x = '';
5058 + if (urlargs.dp == 1) { // For testing only
5059 + x += '<a href=# onclick="return p20showAddMeshUserDialog(5)" style=cursor:pointer;margin-right:10px><img src=images/icon-addnew.png border=0 height=12 width=12> ' + "Add User" + '</a>';
5060 + x += '<table style="color:black;background-color:#EEE;border-color:#AAA;border-width:1px;border-style:solid;border-collapse:collapse" border=0 cellpadding=2 cellspacing=0 width=100%><tbody><tr style=background-color:#AAAAAA;font-weight:bold><th scope=col style=text-align:left;width:430px>' + "Special Permissions" + '</th><th scope=col style=text-align:left></th></tr>';
5061 + var count = 1;
5062 + if (currentNode.links != null) {
5063 + // Sort the list of users to display
5064 + var useridlist = [];
5065 + for (var i in currentNode.links) { if (i.startsWith('user/')) { useridlist.push(i); } }
5066 + useridlist.sort();
5067 + for (var i in useridlist) {
5068 + var trash = '', rights = '', userid = useridlist[i], srights = currentNode.links[userid].rights, rights = "Some Added Rights", username = userid.split('/')[2];
5069 + if ((users != null) && (users[userid] != null)) { username = users[userid].name; }
5070 +
5071 + /*
5072 + var node = nodelist[i], r = currentUser.links[node._id].rights, trash = '', rights = "Partial Device Rights", cr = GetNodeRights(node);
5073 + if ((userinfo.links) && (userinfo.links[i] != null) && (userinfo.links[i].rights != null)) { cr = userinfo.links[i].rights; }
5074 + var nodename = node?EscapeHtml(node.name):('<i>' + "Unknown Device" + '</i>');
5075 + */
5076 + if (srights == 0xFFFFFFFF) rights = "Full Device Rights"; else if (srights == 0) rights = "No Added Rights";
5077 + if ((meshrights & 2) != 0) {
5078 + rights = '<div style=cursor:pointer onclick=p20showAddMeshUserDialog(4,\"' + encodeURIComponent(userid) + '\")>' + rights + ' <img class=hoverButton style=cursor:pointer src=images/link5.png></div>';
5079 + trash = '<a href=# onclick=\'return p30removeUserFromNode(event,"' + encodeURIComponent(userid) + '")\' title=\"' + "Remove user rights to this device group" + '\" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>';
5080 + }
5081 + x += '<tr ' + (((++count % 2) == 0) ? 'style=background-color:#DDD' : '') + '><td><div title=\"' + "Device" + '\" class=m2></div><div>&nbsp;' + username + '<div></div></div></td><td><div style=float:right>' + trash + '</div><div>' + rights + '</div></td></tr>';
5082 + }
5083 + }
5084 + if (count == 1) { x += '<tr><td><div style=padding:6px>&nbsp;<i>' + "No users with special device permissions" + '</i><div></div></div></td><td></td></tr>'; }
5085 + x += '</tbody></table>';
5086 + }
5087 + QH('p10html4', x);
5088 +
5089 // Change the URL
5090 var urlviewmode = '';
5091 if ((xxcurrentView >= 10) && (xxcurrentView <= 19) && (currentNode != null)) {
@@ -5220,6 +5254,7 @@
5254 ++count;
5255 date = new Date(date.getTime() - (1000 * 60 * 60 * 24)); // Substract one day
5256 }
5257 +
5258 QH('p10html2', '<table cellpadding=2 cellspacing=0><thead><tr style=><th scope=col style=text-align:center;width:150px>' + "Day" + '</th><th scope=col style=text-align:center><a download href="devicepowerevents.ashx?id=' + currentNode._id + '" onclick="setDialogMode(0)"><img title=\"' + "Download power events" + '\" src="images/link4.png" /></a>' + "7 Day Power State" + '</th></tr></thead><tbody>' + x + '</tbody></table>');
5259 }
5260
@@ -8411,8 +8446,8 @@
8446 function p20showAddMeshUserDialog(userid, selected) {
8447 if (xxdialogMode) return false;
8448 var x = '';
8414 - if (userid == null) {
8415 - x += "Allow users to manage this device group and devices in this group.";
8449 + if ((userid == null) || (userid == 5)) {
8450 + if (userid == null) { x += "Allow users to manage this device group and devices in this group."; } else { x += "Allow users to manage this device."; }
8451 if (features & 0x00080000) { x += " Users need to login to this server once before they can be added to a device group." }
8452 x += '<br /><br /><div style=\'position:relative\'>';
8453 x += addHtmlValue("User Names", '<input id=dp20username style=width:230px maxlength=32 onchange=p20validateAddMeshUserDialog() onkeyup=p20validateAddMeshUserDialog() placeholder="user1, user2, user3" />');
@@ -8452,7 +8487,7 @@
8487 }
8488 }
8489 x += '<div style="height:120px;overflow-y:scroll;border:1px solid gray">';
8455 - if (userid != 4) {
8490 + if ((userid != 4) && (userid != 5)) {
8491 x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20fulladmin>' + "Full Administrator" + '</label><br>';
8492 x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20editmesh>' + "Edit Device Group" + '</label><br>';
8493 x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20manageusers>' + "Manage Device Group Users" + '</label><br>';
@@ -8486,6 +8521,9 @@
8521 setDialogMode(2, (selected == null)?"Add Device Permissions":"Edit Device Permissions", 3, p20showAddMeshUserDialogEx, x, userid);
8522 QE('dp2meshid', selected == null);
8523 QE('dp2nodeid', selected == null);
8524 + } else if (userid === 5) {
8525 + setDialogMode(2, "Add Users to Device", 3, p20showAddMeshUserDialogEx, x, userid);
8526 + Q('dp20username').focus();
8527 } else {
8528 if (userid.startsWith('ugrp/')) {
8529 setDialogMode(2, "Edit Device Group Permissions", 7, p20showAddMeshUserDialogEx, x, userid);
@@ -8661,6 +8699,10 @@
8699 } else if (t === 4) {
8700 var nodeid = decodeURIComponent(Q('dp2nodeid').value), node = getNodeFromId(nodeid);
8701 if (node != null) { meshserver.send({ action: 'adddeviceuser', nodeid: nodeid, nodename: node.name, userids: [ currentUser._id ], rights: meshadmin }); }
8702 + } else if (t === 5) {
8703 + var users = Q('dp20username').value.split(','), users2 = [];
8704 + for (var i in users) { users2.push(users[i].trim()); }
8705 + meshserver.send({ action: 'adddeviceuser', nodeid: currentNode._id, nodename: currentNode.name, usernames: users2, rights: meshadmin });
8706 } else {
8707 if (t == null) {
8708 var users = Q('dp20username').value.split(','), users2 = [];
@@ -10302,12 +10344,14 @@
10344
10345 function p30removeNodeFromUser(event, nodeid) {
10346 if (xxdialogMode) return;
10305 - var node = getNodeFromId(decodeURIComponent(nodeid))
10306 - setDialogMode(2, "Remove User", 3, p30removeNodeFromUserEx, format("Confirm removal of device {0}?", node.name), node);
10347 + var node = getNodeFromId(decodeURIComponent(nodeid));
10348 + setDialogMode(2, "Remove Device", 3, function(b, node) { meshserver.send({ action: 'adddeviceuser', nodeid: node._id, nodename: node.name, userids: [ currentUser._id ], rights: 0 }); }, format("Confirm removal of device {0}?", node.name), node);
10349 }
10350
10309 - function p30removeNodeFromUserEx(b, node) {
10310 - meshserver.send({ action: 'adddeviceuser', nodeid: node._id, nodename: node.name, userids: [ currentUser._id ], rights: 0 });
10351 + function p30removeUserFromNode(event, userid) {
10352 + if (xxdialogMode) return;
10353 + var user = users[decodeURIComponent(userid)];
10354 + setDialogMode(2, "Remove User", 3, function(b, user) { meshserver.send({ action: 'adddeviceuser', nodeid: currentNode._id, nodename: currentNode.name, userids: [ user._id ], rights: 0 }); }, format("Confirm removal of user {0}?", user.name), user);
10355 }
10356
10357 function p30RemoveUserGroup(button, ugrpid) {