1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

More user groups improvements.

This commit is contained in:
Ylian Saint-Hilaire 2020-01-02 00:30:14 -08:00
parent 42f6e21031
commit 9da0b1938d
5 changed files with 645 additions and 466 deletions

View file

@ -7648,7 +7648,14 @@
if (meshrights & 1) { x += '<br><input type=button value=' + "Notes" + ' title=\"' + "View notes about this device group" + '\" onclick=showNotes(false,"' + encodeURIComponent(currentMesh._id) + '") />'; }
x += '<br style=clear:both><br>';
if (meshrights & 2) { x += '<a href=# onclick="return p20showAddMeshUserDialog()" style=cursor:pointer;margin-right:10px><img src=images/icon-addnew.png border=0 height=12 width=12> ' + "Add Users" + '</a>'; }
if (meshrights & 2) {
x += '<a href=# onclick="return p20showAddMeshUserDialog()" style=cursor:pointer;margin-right:10px><img src=images/icon-addnew.png border=0 height=12 width=12> ' + "Add Users" + '</a>';
if ((userinfo.siteadmin & 256) != 0) {
var userGroupCount = 0, newUserGroup = false;
for (var i in usergroups) { userGroupCount++; if ((currentMesh.links == null) || (currentMesh.links[i] == null)) { newUserGroup = true; } }
if ((userGroupCount > 0) && (newUserGroup)) { x += '<a href=# onclick="return p20showAddMeshUserDialog(2)" style=cursor:pointer;margin-right:10px><img src=images/icon-addnew.png border=0 height=12 width=12> ' + "Add User Group" + '</a>'; }
}
}
if (meshrights & 4) {
if (currentMesh.mtype == 1) {
@ -7680,10 +7687,11 @@
// Display all users for this mesh
for (var i in sortedusers) {
var trash = '', rights = "Partial Device Group Rights", r = sortedusers[i].rights;
var trash = '', rights = "Partial Device Group Rights", r = sortedusers[i].rights, icon = 2;
if (r == 0xFFFFFFFF) rights = "Full Device Group Administrator"; else if (r == 0) rights = "No Rights";
if ((sortedusers[i].id != userinfo._id) && (meshrights == 0xFFFFFFFF || (((meshrights & 2) != 0)))) { trash = '<a href=# onclick=\'return p20deleteUser(event,"' + encodeURIComponent(sortedusers[i].id) + '")\' title=\"' + "Remove user rights to this device group" + '\" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>'; }
x += '<tr tabindex=0 onclick=p20viewuser("' + encodeURIComponent(sortedusers[i].id) + '") onkeypress="if (event.key==\'Enter\') p20viewuser(\'' + encodeURIComponent(sortedusers[i].id) + '\')" style=cursor:pointer' + (((count % 2) == 0) ? ';background-color:#DDD' : '') + '><td><div title=\"' + "User" + '\" class=m2></div><div>&nbsp;' + EscapeHtml(decodeURIComponent(sortedusers[i].name)) + '<div></div></div></td><td><div style=float:right>' + trash + '</div><div>' + rights + '</div></td></tr>';
if (sortedusers[i].id.startsWith('ugrp/')) { icon = 4; }
x += '<tr tabindex=0 onclick=p20viewuser("' + encodeURIComponent(sortedusers[i].id) + '") onkeypress="if (event.key==\'Enter\') p20viewuser(\'' + encodeURIComponent(sortedusers[i].id) + '\')" style=cursor:pointer' + (((count % 2) == 0) ? ';background-color:#DDD' : '') + '><td><div title=\"' + "User" + '\" class=m' + icon + '></div><div>&nbsp;' + EscapeHtml(decodeURIComponent(sortedusers[i].name)) + '<div></div></div></td><td><div style=float:right>' + trash + '</div><div>' + rights + '</div></td></tr>';
++count;
}
@ -7878,12 +7886,26 @@
var y = '';
for (var i in meshes) { if ((currentUser.links == null) || (currentUser.links[i] == null)) { y += '<option value=' + encodeURIComponent(i) + '>' + EscapeHtml(meshes[i].name) + '</option>'; } }
x += addHtmlValue("Device Group", '<div style=width:230px;margin:0;padding:0><select onchange=p20validateAddMeshUserDialog() id=dp2groupid style=width:100%>' + y + '</select></div>');
} else if (userid === 2) {
if ((userinfo.siteadmin & 256) == 0) return;
var y = '';
for (var i in usergroups) { if ((currentMesh.links == null) || (currentMesh.links[i] == null)) { y += '<option value=' + encodeURIComponent(i) + '>' + EscapeHtml(usergroups[i].name) + '</option>'; } }
x += addHtmlValue("User Group", '<div style=width:230px;margin:0;padding:0><select onchange=p20validateAddMeshUserDialog() id=dp2groupid style=width:100%>' + y + '</select></div>');
} else if (userid === 3) {
var y = '';
for (var i in meshes) { if ((currentUserGroup.links == null) || (currentUserGroup.links[i] == null)) { y += '<option value=' + encodeURIComponent(i) + '>' + EscapeHtml(meshes[i].name) + '</option>'; } }
x += addHtmlValue("Device Group", '<div style=width:230px;margin:0;padding:0><select onchange=p20validateAddMeshUserDialog() id=dp2groupid style=width:100%>' + y + '</select></div>');
} else {
userid = decodeURIComponent(userid);
var uname = userid.split('/')[2];
if (users && users[userid]) { uname = users[userid].name; }
if (usergroups && usergroups[userid]) { uname = usergroups[userid].name; }
if (userinfo._id == userid) { uname = userinfo.name; }
x += format("Group permissions for user {0}.", uname) + '<br /><br />';
if (userid.startsWith('ugrp/')) {
x += format("Group permissions for {0}.", uname) + '<br /><br />';
} else {
x += format("Group permissions for user {0}.", uname) + '<br /><br />';
}
}
x += '<div style="height:120px;overflow-y:scroll;border:1px solid gray">';
x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20fulladmin>' + "Full Administrator" + '</label><br>';
@ -7909,8 +7931,16 @@
Q('dp20username').focus();
} else if (userid === 1) {
setDialogMode(2, "Add Device Group", 3, p20showAddMeshUserDialogEx, x, userid);
} else if (userid === 2) {
setDialogMode(2, "Add User Group", 3, p20showAddMeshUserDialogEx, x, userid);
} else if (userid === 3) {
setDialogMode(2, "Add Device Group", 3, p20showAddMeshUserDialogEx, x, userid);
} else {
setDialogMode(2, "Edit User Device Group Permissions", 7, p20showAddMeshUserDialogEx, x, userid);
if (userid.startsWith('ugrp/')) {
setDialogMode(2, "Edit Device Group Permissions", 7, p20showAddMeshUserDialogEx, x, userid);
} else {
setDialogMode(2, "Edit User Device Group Permissions", 7, p20showAddMeshUserDialogEx, x, userid);
}
var cmeshrights = GetMeshRights(currentMesh), meshrights = GetMeshRights(currentMesh, userid);
if (meshrights == 0xFFFFFFFF) {
Q('p20fulladmin').checked = true;
@ -8031,14 +8061,20 @@
if (t === 1) {
var meshid = decodeURIComponent(Q('dp2groupid').value), mesh = meshes[meshid];
if (mesh != null) { meshserver.send({ action: 'addmeshuser', meshid: meshid, meshname: mesh.name, usernames: [ currentUser._id.split('/')[2] ], meshadmin: meshadmin }); }
if (mesh != null) { meshserver.send({ action: 'addmeshuser', meshid: meshid, meshname: mesh.name, userids: [ currentUser._id ], meshadmin: meshadmin }); }
} else if (t === 2) {
var ugrpid = decodeURIComponent(Q('dp2groupid').value), mesh = meshes[currentMesh._id];
if (mesh != null) { meshserver.send({ action: 'addmeshuser', meshid: currentMesh._id, meshname: currentMesh.name, userid: ugrpid, meshadmin: meshadmin }); }
} else if (t === 3) {
var meshid = decodeURIComponent(Q('dp2groupid').value), mesh = meshes[meshid];
if (mesh != null) { meshserver.send({ action: 'addmeshuser', meshid: meshid, meshname: mesh.name, userids: [ currentUserGroup._id ], meshadmin: meshadmin }); }
} else {
if (t == null) {
var users = Q('dp20username').value.split(','), users2 = [];
for (var i in users) { users2.push(users[i].trim()); }
meshserver.send({ action: 'addmeshuser', meshid: currentMesh._id, meshname: currentMesh.name, usernames: users2, meshadmin: meshadmin });
} else {
meshserver.send({ action: 'addmeshuser', meshid: currentMesh._id, meshname: currentMesh.name, usernames: [ t.split('/')[2] ], meshadmin: meshadmin });
meshserver.send({ action: 'addmeshuser', meshid: currentMesh._id, meshname: currentMesh.name, userids: [ t ], meshadmin: meshadmin });
}
}
}
@ -8087,6 +8123,7 @@
if (button != 2) return;
var uname = userid.split('/')[2];
if (users && users[userid]) { uname = users[userid].name; }
if (usergroups && usergroups[userid]) { uname = usergroups[userid].name; }
if (userinfo._id == userid) { uname = userinfo.name; }
setDialogMode(2, "Remote Mesh User", 3, p20viewuserEx2, format("Confirm removal of user {0}?", EscapeHtml(decodeURIComponent(uname))), userid);
}
@ -9056,7 +9093,7 @@
// Display the groups using the sorted list
var x = '<table class=p3usersTable cellpadding=0 cellspacing=0>', addHeader = true;
x += '<th>' + "Name" + '<th style=width:80px>' + "Users";
x += '<th>' + "Name" + '<th style=width:80px>' + "Device Groups" + '<th style=width:80px>' + "Users";
for (var i in sortedGroups) { x += addUserGroupHtml(sortedGroups[i]); }
x += '</table>';
@ -9068,13 +9105,13 @@
}
function addUserGroupHtml(group) {
var usercount = 0;
if (group.links) { for (var i in group.links) { usercount++; } }
var usercount = 0, meshcount = 0;
if (group.links) { for (var i in group.links) { if (i.startsWith('user/')) { usercount++; } if (i.startsWith('mesh/')) { meshcount++; } } }
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) + '\")>';
x += '<div class=bar style=width:100%>';
x += '<div class=baricon><div class="m4"></div></div>';
x += '<div class=g1></div><div class=g2></div>';
x += '<div><span style=font-size:16px>' + group.name + '</span></div></div><td style=text-align:center>' + usercount;
x += '<div><span style=font-size:16px>' + group.name + '</span></div></div><td style=text-align:center>' + meshcount + '<td style=text-align:center>' + usercount;
return x;
}
@ -9106,7 +9143,8 @@
var group = currentUserGroup = usergroups[decodeURIComponent(groupid)];
if (group == null) { if (xxcurrentView == 51) { setDialogMode(0); go(50); } return; }
QH('p51groupName', group.name);
var usercount = 0, meshcount = 0;
if (group.links) { for (var i in group.links) { if (i.startsWith('user/')) { usercount++; } if (i.startsWith('mesh/')) { meshcount++; } } }
var desc = group.desc;
if ((desc == null) || (desc == '')) { desc = '<i>' + "None" + '<i>'; } else { desc = EscapeHtml(desc); }
@ -9118,6 +9156,9 @@
x += addDeviceAttribute("Name", EscapeHtml(group.name));
x += addDeviceAttribute("Description", desc);
}
x += addDeviceAttribute("Users", usercount);
x += addDeviceAttribute("Device Groups", meshcount);
x += '</table></div><br />';
if ((userinfo.siteadmin & 256) != 0) {
@ -9127,14 +9168,16 @@
// Setup the panel
QH('p51group', x);
x = '<br />';
if ((userinfo.siteadmin & 256) != 0) {
x = '<a href=# onclick="return p51showAddUserDialog()" style=cursor:pointer;margin-right:10px><img src=images/icon-addnew.png border=0 height=12 width=12> ' + "Add Users" + '</a>';
x += '<a href=# onclick="return p51showAddUserDialog()" style=cursor:pointer;margin-right:10px><img src=images/icon-addnew.png border=0 height=12 width=12> ' + "Add Users" + '</a>';
}
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>' + "Group Members" + '</th><th scope=col style=text-align:left></th></tr>';
// Sort the users for this mesh
var count = 1, sortedusers = [];
for (var i in currentUserGroup.links) {
if (i.startsWith('user/') == false) continue;
var uname = i.split('/')[2];
if (currentUserGroup.links[i].name) { uname = currentUserGroup.links[i].name; }
if (i == userinfo._id) { uname = userinfo.name; }
@ -9151,7 +9194,29 @@
if (count == 1) { x += '<tr><td><div style=padding:6px>&nbsp;<i>' + "No Members" + '</i><div></div></div></td><td></td></tr>'; }
x += '</tbody></table><br />';
count = 1;
var deviceGroupCount = 0, newDeviceGroup = false;
for (var i in meshes) { deviceGroupCount++; if ((currentUserGroup.links == null) || (currentUserGroup.links[i] == null)) { newDeviceGroup = true; } }
if ((deviceGroupCount > 0) && (newDeviceGroup)) { x += '<a href=# onclick="return p20showAddMeshUserDialog(3)" style=cursor:pointer;margin-right:10px><img src=images/icon-addnew.png border=0 height=12 width=12> ' + "Add Device Group" + '</a>'; }
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>' + "Common Device Groups" + '</th><th scope=col style=text-align:left></th></tr>';
if (currentUserGroup.links) {
for (var i in currentUserGroup.links) {
if (i.startsWith('mesh/')) {
var cr = 0, r = currentUserGroup.links[i].rights, mesh = meshes[i], trash = '', rights = "Partial Device Group Rights";
if (mesh == null) { continue; }
if ((userinfo.links) && (userinfo.links[i] != null) && (userinfo.links[i].rights != null)) { cr = userinfo.links[i].rights; }
var meshname = mesh?EscapeHtml(mesh.name):('<i>' + "Unknown Device Group" + '</i>');
if (r == 0xFFFFFFFF) rights = "Full Device Group Administrator"; else if (r == 0) rights = "No Rights";
if ((cr & 2) != 0) { trash = '<a href=# onclick=\'return p51removeMeshFromUserGroup(event,"' + encodeURIComponent(mesh._id) + '")\' title=\"' + "Remove user group rights to this device group" + '\" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>'; }
x += '<tr ' + (((++count % 2) == 0) ? 'style=background-color:#DDD' : '') + '><td><div title=\"' + "Device Group" + '\" class=m99></div><div>&nbsp;' + meshname + '<div></div></div></td><td><div style=float:right>' + trash + '</div><div>' + rights + '</div></td></tr>';
}
}
}
if (count == 1) { x += '<tr><td><div style=padding:6px>&nbsp;<i>' + "No device groups in common" + '</i><div></div></div></td><td></td></tr>'; }
x += '</tbody></table>';
if ((userinfo.siteadmin & 256) != 0) {
x += '<div style=font-size:x-small;text-align:right><span><a href=# onclick=p51showDeleteUserGroupDialog() style=cursor:pointer>' + "Delete User Group" + '</a></span></div>';
}
@ -9160,6 +9225,17 @@
go(51);
}
function p51removeMeshFromUserGroup(e, meshid) {
if (xxdialogMode) return;
var mesh = meshes[decodeURIComponent(meshid)];
if (mesh == null) return;
setDialogMode(2, "Remove Device Group", 3, p51removeMeshFromUserGroupEx, format("Confirm removal of device group {0}?", mesh.name), mesh._id);
}
function p51removeMeshFromUserGroupEx(b, meshid) {
meshserver.send({ action: 'removemeshuser', meshid: meshid, userid: currentUserGroup._id });
}
function p51editgroup(focus) {
if (xxdialogMode) return;
var x = addHtmlValue("Name", '<input id=dp51name style=width:230px maxlength=32 onchange=p51editgroupValidate() onkeyup=p51editgroupValidate(event) />');