Started work on per-user rights removal.

Ylian Saint-Hilaire committed Aug 27, 2021 at 09:14 UTC 96f7c048f723d2403dfc9ef8557de4da64ecdb8a
2 files changed +43 -15
meshuser.js
+7 -1
@@ -1584,7 +1584,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1584 if (command.resetNextLogin === true) { chguser.passchange = -1; }
1585 if ((command.consent != null) && (typeof command.consent == 'number')) { if (command.consent == 0) { delete chguser.consent; } else { chguser.consent = command.consent; } change = 1; }
1586 if ((command.phone != null) && (typeof command.phone == 'string') && ((command.phone == '') || isPhoneNumber(command.phone))) { if (command.phone == '') { delete chguser.phone; } else { chguser.phone = command.phone; } change = 1; }
1587 - if ((command.flags != null) && (typeof command.flags == 'number')) { if (command.flags == 0) { delete chguser.flags; } else { chguser.flags = command.flags; } change = 1; } // Flags: 1 = Account Image, 2 = Session Recording
1587 + if ((command.flags != null) && (typeof command.flags == 'number')) {
1588 + // Flags: 1 = Account Image, 2 = Session Recording
1589 + if ((command.flags == 0) && (chguser.flags != null)) { delete chguser.flags; change = 1; } else { if (command.flags !== chguser.flags) { chguser.flags = command.flags; change = 1; } }
1590 + }
1591 + if ((command.removeRights != null) && (typeof command.removeRights == 'number')) {
1592 + if ((command.removeRights == 0) && (chguser.removeRights != null)) { delete chguser.removeRights; change = 1; } else { if (command.removeRights !== chguser.removeRights) { chguser.removeRights = command.removeRights; change = 1; } }
1593 + }
1594
1595 // Site admins can change any server rights, user managers can only change AccountLock, NoMeshCmd and NoNewGroups
1596 if (common.validateInt(command.siteadmin) && (chguser._id !== user._id) && (chguser.siteadmin != command.siteadmin)) { // We can't change our own siteadmin permissions.
views/default.handlebars
+36 -14
@@ -14052,15 +14052,18 @@
14052 }
14053
14054 // Display features
14055 - if (serverinfo.usersSessionRecording == 1) {
14056 - var userFeatures = [];
14057 - if (user.flags) {
14058 - if ((serverinfo.usersSessionRecording == 1) && (user.flags & 2)) { userFeatures.push("Record Sessions"); }
14059 - }
14060 - userFeatures = userFeatures.join(', ');
14061 - if (userFeatures == '') { userFeatures = '<i>' + "None" + '</i>'; }
14062 - x += addDeviceAttribute("Features", addLink(userFeatures, 'p20edituserfeatures()'));
14063 - }
14055 + var userFeatures = [];
14056 + if ((serverinfo.usersSessionRecording == 1) && (user.flags) && (user.flags & 2)) { userFeatures.push("Record Sessions"); }
14057 + if (user.removeRights) {
14058 + if ((user.removeRights & 0x00010000) != 0) { userFeatures.push("No Desktop"); }
14059 + else if ((user.removeRights & 0x00000100) != 0) { userFeatures.push("Desktop View Only"); }
14060 + if ((user.removeRights & 0x00000200) != 0) { userFeatures.push("No Terminal"); }
14061 + if ((user.removeRights & 0x00000400) != 0) { userFeatures.push("No Files"); }
14062 + if ((user.removeRights & 0x00000010) != 0) { userFeatures.push("No Console"); }
14063 + }
14064 + userFeatures = userFeatures.join(', ');
14065 + if (userFeatures == '') { userFeatures = '<i>' + "None" + '</i>'; }
14066 + x += addDeviceAttribute("Features", addLink(userFeatures, 'p20edituserfeatures()'));
14067
14068 x += addDeviceAttribute("Server Rights", premsg + msg.join(', ') + ' <img style=cursor:pointer class=hoverButton onclick=\'return showUserAdminDialog(event,"' + encodeURIComponentEx(user._id) + '")\' src="images/link5.png" />');
14069 if (user.quota) x += addDeviceAttribute("Server Quota", EscapeHtml(parseInt(user.quota) / 1024) + ' k');
@@ -14179,19 +14182,38 @@
14182 function p20edituserfeatures() {
14183 if (xxdialogMode) return;
14184 var flags = (currentUser.flags)?currentUser.flags:0, x = ''; // Flags: 1 = Account Image, 2 = Session Recording
14185 + var removeRights = (currentUser.removeRights)?currentUser.removeRights:0, x = ''; // Remove Device Group Rights
14186 if (serverinfo.usersSessionRecording == 1) {
14183 - x += '<div><label><input type=checkbox id=d20flag2 onchange=p20edituserfeaturesValidate() ' + ((flags & 2) ? 'checked' : '') + '>' + "Record sessions" + '</label><br></div>';
14187 + x += '<div><label><input type=checkbox id=d20flag1 onchange=p20edituserfeaturesValidate() ' + ((flags & 2) ? 'checked' : '') + '>' + "Record sessions" + '</label><br></div>';
14188 }
14189 + x += '<div><label><input type=checkbox id=d20flag2 onchange=p20edituserfeaturesValidate() ' + ((removeRights & 0x00010000) ? 'checked' : '') + '>' + "No Desktop Access" + '</label><br></div>';
14190 + x += '<div style=margin-left:8px><label><input type=checkbox id=d20flag3 onchange=p20edituserfeaturesValidate() ' + ((removeRights & 0x00000100) ? 'checked' : '') + '>' + "Remote View Only" + '</label><br></div>';
14191 + x += '<div><label><input type=checkbox id=d20flag4 onchange=p20edituserfeaturesValidate() ' + ((removeRights & 0x00000200) ? 'checked' : '') + '>' + "No Terminal Access" + '</label><br></div>';
14192 + x += '<div><label><input type=checkbox id=d20flag5 onchange=p20edituserfeaturesValidate() ' + ((removeRights & 0x00000400) ? 'checked' : '') + '>' + "No File Access" + '</label><br></div>';
14193 + x += '<div><label><input type=checkbox id=d20flag6 onchange=p20edituserfeaturesValidate() ' + ((removeRights & 0x00000010) ? 'checked' : '') + '>' + "No Agent Console" + '</label><br></div>';
14194 setDialogMode(2, "Edit User Features", 3, p20edituserfeaturesEx, x);
14195 + p20edituserfeaturesValidate();
14196 }
14197
14188 - function p20edituserfeaturesValidate() { }
14198 + function p20edituserfeaturesValidate() {
14199 + QE('d20flag3', !Q('d20flag2').checked);
14200 + }
14201
14202 // Send to the server the new user's real name
14203 function p20edituserfeaturesEx() {
14192 - var f = currentUser.flags & 1; // Flags: 1 = Account Image, 2 = Session Recording
14193 - if (Q('d20flag2').checked) { f += 2; }
14194 - meshserver.send({ action: 'edituser', id: currentUser._id, flags: f });
14204 + // Setup user flags
14205 + var flags = (currentUser.flags)?currentUser.flags:0; // Flags: 1 = Account Image, 2 = Session Recording
14206 + var f = flags & 1;
14207 + if ((serverinfo.usersSessionRecording == 1) && Q('d20flag1').checked) { f += 2; }
14208 +
14209 + // Setup user permission removal
14210 + var r = 0;
14211 + if (Q('d20flag2').checked) { r += 0x00010000; }
14212 + else if (Q('d20flag3').checked) { r += 0x00000100; }
14213 + if (Q('d20flag4').checked) { r += 0x00000200; }
14214 + if (Q('d20flag5').checked) { r += 0x00000400; }
14215 + if (Q('d20flag6').checked) { r += 0x00000010; }
14216 + meshserver.send({ action: 'edituser', id: currentUser._id, flags: f, removeRights: r });
14217 }
14218
14219 function p30editPhoneValidate(x) {