Started work on user group permission removal, #3129

Ylian Saint-Hilaire committed Sep 14, 2021 at 17:27 UTC 68dfafa739714b0a1a82f43290f2df6b8a752892
3 files changed +80 -9
meshuser.js
+7 -2
@@ -1948,12 +1948,17 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1948 if ((command.flags != null) && (typeof command.flags == 'number')) {
1949 // Flags: 2 = Session Recording
1950 if ((command.flags == 0) && (group.flags != null)) { delete group.flags; } else { if (command.flags !== group.flags) { group.flags = command.flags; } }
1951 - if (change == '') { change = 'User group flags changed.'; }
1951 + if (change == '') { change = 'User group features changed.'; }
1952 + }
1953 +
1954 + if ((command.removeRights != null) && (typeof command.removeRights == 'number')) {
1955 + if ((command.removeRights == 0) && (group.removeRights != null)) { delete group.removeRights; } else { if (command.removeRights !== group.removeRights) { group.removeRights = command.removeRights; } }
1956 + if (change == '') { change = 'User group features changed.'; }
1957 }
1958
1959 if (change != '') {
1960 db.Set(group);
1956 - var event = { etype: 'ugrp', userid: user._id, username: user.name, ugrpid: group._id, name: group.name, desc: group.desc, consent: ((group.consent == null) ? 0 : group.consent), action: 'usergroupchange', links: group.links, flags: group.flags, msg: change, domain: domain.id };
1961 + var event = { etype: 'ugrp', userid: user._id, username: user.name, ugrpid: group._id, name: group.name, desc: group.desc, consent: ((group.consent == null) ? 0 : group.consent), action: 'usergroupchange', links: group.links, flags: group.flags, removeRights: group.removeRights, msg: change, domain: domain.id };
1962 if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the mesh. Another event will come.
1963 parent.parent.DispatchEvent(['*', group._id, user._id], obj, event);
1964 }
views/default-mobile.handlebars
+1
@@ -1744,6 +1744,7 @@
1744 ugroup.desc = message.event.desc;
1745 ugroup.links = message.event.links;
1746 ugroup.flags = message.event.flags;
1747 + ugroup.removeRights = message.event.removeRights;
1748 }
1749 //mainUpdate(8192 + 16384);
1750
views/default.handlebars
+72 -7
@@ -2936,6 +2936,7 @@
2936 if (message.event.desc) { ugroup.desc = message.event.desc; } else { delete ugroup.desc; }
2937 if (message.event.links) { ugroup.links = message.event.links; } else { delete ugroup.links; }
2938 if (message.event.flags) { ugroup.flags = message.event.flags; } else { delete ugroup.flags; }
2939 + if (message.event.removeRights) { ugroup.removeRights = message.event.removeRights; } else { delete ugroup.removeRights; }
2940 if (typeof message.event.consent == 'number') { ugroup.consent = message.event.consent; }
2941 }
2942 mainUpdate(4096 + 8192 + 16384);
@@ -13830,13 +13831,24 @@
13831 }
13832
13833 // Display features
13833 - if (serverinfo.userGroupsSessionRecording == 1) {
13834 - var userGroupFeatures = [];
13835 - if ((group.flags) && (group.flags & 2)) { userGroupFeatures.push("Record Sessions"); }
13836 - userGroupFeatures = userGroupFeatures.join(', ');
13837 - if (userGroupFeatures == '') { userGroupFeatures = '<i>' + "None" + '</i>'; }
13838 - x += addDeviceAttribute("Features", addLink(userGroupFeatures, 'p51edituserGroupFeatures()'));
13839 - }
13834 + var userGroupFeatures = [];
13835 + if ((serverinfo.userGroupsSessionRecording == 1) && (group.flags) && (group.flags & 2)) { userGroupFeatures.push("Record Sessions"); }
13836 + if (group.removeRights) {
13837 + if ((group.removeRights & 0x00000008) != 0) { userGroupFeatures.push("No Remote Control"); } else {
13838 + if ((group.removeRights & 0x00010000) != 0) { userGroupFeatures.push("No Desktop"); }
13839 + else if ((group.removeRights & 0x00000100) != 0) { userGroupFeatures.push("Desktop View Only"); }
13840 + if ((group.removeRights & 0x00000200) != 0) { userGroupFeatures.push("No Terminal"); }
13841 + if ((group.removeRights & 0x00000400) != 0) { userGroupFeatures.push("No Files"); }
13842 + }
13843 + if ((group.removeRights & 0x00000010) != 0) { userGroupFeatures.push("No Console"); }
13844 + if ((group.removeRights & 0x00008000) != 0) { userGroupFeatures.push("No Uninstall"); }
13845 + if ((group.removeRights & 0x00020000) != 0) { userGroupFeatures.push("No Remote Command"); }
13846 + if ((group.removeRights & 0x00000040) != 0) { userGroupFeatures.push("No Wake"); }
13847 + if ((group.removeRights & 0x00040000) != 0) { userGroupFeatures.push("No Reset/Off"); }
13848 + }
13849 + userGroupFeatures = userGroupFeatures.join(', ');
13850 + if (userGroupFeatures == '') { userGroupFeatures = '<i>' + "None" + '</i>'; }
13851 + x += addDeviceAttribute("Features", addLink(userGroupFeatures, 'p51edituserGroupFeatures()'));
13852
13853 // Display user consent flags for this user group
13854 {
@@ -13961,6 +13973,58 @@
13973 }
13974 }
13975
13976 + function p51edituserGroupFeatures() {
13977 + if (xxdialogMode) return;
13978 + var flags = (currentUserGroup.flags)?currentUserGroup.flags:0, x = ''; // Flags: 1 = Account Image, 2 = Session Recording
13979 + var removeRights = (currentUserGroup.removeRights)?currentUserGroup.removeRights:0, x = ''; // Remove Device Group Rights
13980 + if (serverinfo.userGroupsSessionRecording == 1) {
13981 + x += '<div><label><input type=checkbox id=d51flag1 onchange=p51edituserGroupFeaturesValidate() ' + ((flags & 2) ? 'checked' : '') + '>' + "Record sessions" + '</label><br></div>';
13982 + }
13983 + x += '<div><label><input type=checkbox id=d51flag7 onchange=p51edituserGroupFeaturesValidate() ' + ((removeRights & 0x00000008) ? 'checked' : '') + '>' + "No Remote Control" + '</label><br></div>';
13984 + x += '<div style=margin-left:8px><label><input type=checkbox id=d51flag2 onchange=p51edituserGroupFeaturesValidate() ' + ((removeRights & 0x00010000) ? 'checked' : '') + '>' + "No Desktop Access" + '</label><br></div>';
13985 + x += '<div style=margin-left:16px><label><input type=checkbox id=d51flag3 onchange=p51edituserGroupFeaturesValidate() ' + ((removeRights & 0x00000100) ? 'checked' : '') + '>' + "Remote View Only" + '</label><br></div>';
13986 + x += '<div style=margin-left:8px><label><input type=checkbox id=d51flag4 onchange=p51edituserGroupFeaturesValidate() ' + ((removeRights & 0x00000200) ? 'checked' : '') + '>' + "No Terminal Access" + '</label><br></div>';
13987 + x += '<div style=margin-left:8px><label><input type=checkbox id=d51flag5 onchange=p51edituserGroupFeaturesValidate() ' + ((removeRights & 0x00000400) ? 'checked' : '') + '>' + "No File Access" + '</label><br></div>';
13988 + x += '<div><label><input type=checkbox id=d51flag6 onchange=p51edituserGroupFeaturesValidate() ' + ((removeRights & 0x00000010) ? 'checked' : '') + '>' + "No Agent Console" + '</label><br></div>';
13989 + x += '<div><label><input type=checkbox id=d51flag8 onchange=p51edituserGroupFeaturesValidate() ' + ((removeRights & 0x00008000) ? 'checked' : '') + '>' + "No Uninstall" + '</label><br></div>';
13990 + x += '<div><label><input type=checkbox id=d51flag9 onchange=p51edituserGroupFeaturesValidate() ' + ((removeRights & 0x00020000) ? 'checked' : '') + '>' + "No Remote Command" + '</label><br></div>';
13991 + x += '<div><label><input type=checkbox id=d51flag10 onchange=p51edituserGroupFeaturesValidate() ' + ((removeRights & 0x00000040) ? 'checked' : '') + '>' + "No Wake" + '</label><br></div>';
13992 + x += '<div><label><input type=checkbox id=d51flag11 onchange=p51edituserGroupFeaturesValidate() ' + ((removeRights & 0x00040000) ? 'checked' : '') + '>' + "No Reset/Off" + '</label><br></div>';
13993 + setDialogMode(2, "Edit User Features", 3, p51edituserGroupFeaturesEx, x);
13994 + p51edituserGroupFeaturesValidate();
13995 + }
13996 +
13997 + function p51edituserGroupFeaturesValidate() {
13998 + QE('d51flag2', !Q('d51flag7').checked);
13999 + QE('d51flag3', !Q('d51flag7').checked && !Q('d51flag2').checked);
14000 + QE('d51flag4', !Q('d51flag7').checked);
14001 + QE('d51flag5', !Q('d51flag7').checked);
14002 + }
14003 +
14004 + // Send to the server the new user's real name
14005 + function p51edituserGroupFeaturesEx() {
14006 + // Setup user flags
14007 + var flags = (currentUserGroup.flags)?currentUserGroup.flags:0; // Flags: 1 = Account Image, 2 = Session Recording
14008 + var f = flags & 1;
14009 + if ((serverinfo.userGroupsSessionRecording == 1) && Q('d51flag1').checked) { f += 2; }
14010 +
14011 + // Setup user permission removal
14012 + var r = 0;
14013 + if (Q('d51flag7').checked) { r += 0x00000008; } else {
14014 + if (Q('d51flag2').checked) { r += 0x00010000; }
14015 + else if (Q('d51flag3').checked) { r += 0x00000100; }
14016 + if (Q('d51flag4').checked) { r += 0x00000200; }
14017 + if (Q('d51flag5').checked) { r += 0x00000400; }
14018 + }
14019 + if (Q('d51flag6').checked) { r += 0x00000010; }
14020 + if (Q('d51flag8').checked) { r += 0x00008000; }
14021 + if (Q('d51flag9').checked) { r += 0x00020000; }
14022 + if (Q('d51flag10').checked) { r += 0x00000040; }
14023 + if (Q('d51flag11').checked) { r += 0x00040000; }
14024 + meshserver.send({ action: 'editusergroup', ugrpid: currentUserGroup._id, flags: f, removeRights: r });
14025 + }
14026 +
14027 + /*
14028 function p51edituserGroupFeatures() {
14029 if (xxdialogMode) return;
14030 var flags = (currentUserGroup.flags)?currentUserGroup.flags:0, x = ''; // Flags: 2 = Session Recording
@@ -13977,6 +14041,7 @@
14041 if ((serverinfo.userGroupsSessionRecording == 1) && Q('d51flag1').checked) { f += 2; }
14042 meshserver.send({ action: 'editusergroup', ugrpid: currentUserGroup._id, flags: f });
14043 }
14044 + */
14045
14046 function p51removeDeviceFromUserGroup(e, nodeid) {
14047 if (xxdialogMode) return;